Skip to content

Get an OAuth2 access token ​

Exchange CloudPrint API credentials for a short-lived OAuth2 Bearer token using the Client Credentials grant.

POST/oauth/tokenAPI version: v1operationId: issueOAuthTokenView as Markdown

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 ​

NameLocationTypeRequiredDescriptionConstraints
X-Request-IdheaderstringnoOptional request identifier for tracing; CloudPrint returns a safe value in the response header.maxLength: 128; example: "order-100045-attempt-1"

Request body ​

Content type: application/x-www-form-urlencoded

NameTypeRequiredDescriptionConstraints
grant_typestringyesOAuth2 grant type used to request the token.enum: client_credentials; example: "client_credentials"
client_idstringyesPublic identifier from the account API Credentials pair.—
client_secretstringyesSecret from API Credentials; keep it only in a backend secret store.—
scopestringnoSpace-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 ​

NameTypeRequiredDescriptionConstraints
token_typestringyesOAuth2 token type; Public API tokens use Bearer.example: "Bearer"
expires_inintegeryesAccess-token lifetime in seconds from the time of issuance.example: 900
access_tokenstringyesShort-lived OAuth2 Bearer token used in Public API requests.example: "eyJ..."
scopestringyesSpace-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 statusDescription
400Invalid OAuth2 request
401Invalid OAuth2 client credentials
429Rate limit exceeded
500OAuth2 server error

Integration guidance ​

  • Keep client_secret only in a backend secret store; never send it to browser or distributed desktop code.
  • Cache the token until shortly before expires_in instead of requesting a token for every print job.
  • Request the smallest scope set needed by the current integration.

Guides for integrating CloudPrint, connecting the local agent and operating print workflows.