Get an OAuth2 access token
Exchange CloudPrint API credentials for a short-lived OAuth2 Bearer token using the Client Credentials grant.
What this endpoint does
Exchange CloudPrint API credentials for a short-lived OAuth2 Bearer token using the Client Credentials grant.
Authentication
This endpoint does not require a Bearer token.
Request
Production base URL: https://public-api.cloudprint.me/oauth/token
Parameters
This endpoint has no path, query or custom header parameters.
Request body
Content type: application/x-www-form-urlencoded
| Name | Type | Required | Description | Constraints |
|---|---|---|---|---|
grant_type | string | yes | OAuth2 grant used for the token request. | enum: client_credentials; example: "client_credentials" |
client_id | string | yes | Public identifier from the account API Credentials pair. | — |
client_secret | string | yes | Secret from API Credentials; keep it only in a backend secret store. | — |
scope | string | no | Space-separated scopes requested for the access token. | example: "agents:read printers:read documents:write print_jobs:write print_jobs:read" |
Example requests
cURL
bash
curl -sS https://public-api.cloudprint.me/oauth/token \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=33333333-3333-4333-8333-333333333333' \
--data-urlencode 'client_secret=cpsec_...' \
--data-urlencode 'scope=agents:read printers:read documents:write print_jobs:write print_jobs:read'PHP
php
<?php
$response = file_get_contents('https://public-api.cloudprint.me/oauth/token', false, stream_context_create([
'http' => [
'method' => 'POST',
'header' => "Content-Type: application/x-www-form-urlencoded\r\n",
'content' => http_build_query([
'grant_type' => 'client_credentials',
'client_id' => getenv('CLOUDPRINT_CLIENT_ID'),
'client_secret' => getenv('CLOUDPRINT_CLIENT_SECRET'),
'scope' => 'agents:read printers:read documents:write print_jobs:write print_jobs:read',
]),
],
]));
$token = json_decode((string) $response, true, flags: JSON_THROW_ON_ERROR)['access_token'];Response
HTTP status: 200 — Access token issued
Response fields
| Name | Type | Required | Description | Constraints |
|---|---|---|---|---|
token_type | string | yes | OAuth2 token type; Public API tokens use Bearer. | example: "Bearer" |
expires_in | integer | yes | Access-token lifetime in seconds from the time of issuance. | example: 900 |
access_token | string | yes | Short-lived OAuth2 Bearer token used in Public API requests. | example: "eyJ..." |
scope | string | yes | Space-separated scopes requested for the access token. | example: "printers:read print_jobs:write" |
Example response
json
{
"token_type": "Bearer",
"expires_in": 900,
"access_token": "eyJ...",
"scope": "printers:read print_jobs:write"
}Errors
| HTTP status | Description |
|---|---|
400 | Invalid OAuth2 request |
401 | Invalid OAuth2 client credentials |
429 | Rate limit exceeded |
500 | OAuth2 server error |
Integration guidance
- Keep
client_secretonly in a backend secret store; never send it to browser or distributed desktop code. - Cache the token until shortly before
expires_ininstead of requesting a token for every print job. - Request the smallest scope set needed by the current integration.
Related documentation
Get the current API client contextConfirm which CloudPrint account, client application and scopes are represented by the current access token.Authenticate with OAuth2 Client CredentialsCreate a CloudPrint client app, request a short-lived access token and protect credentials with the correct API scopes.CloudPrint API errors and retriesHandle CloudPrint API status codes, machine-readable errors, rate limits, request tracing and safe retry decisions.