Skip to content

Call the REST API

Source: docs/api/how-to.md

Every command on this page runs in CI against a demo stack (release 3.15.0), so it works as written. You need curl, jq and openssl.

The full list of endpoints, with every field, is the API reference. Each instance also serves its own Swagger UI at /api/docs and the document at /api/v1/openapi.json.

The API has three kinds of credential. Each one opens a different part of it.

Credential Looks like Opens You get it from
OIDC access token a JWT (eyJ…) /api/v1/* (management: CAs, certificates, SSH) your identity provider
Integration token pkimg_… /api/v1/external/* (sign, revoke, status) for one CA Operations → Integrations in the UI
SSH fleet token pkimg_… /api/v1/external/ssh/* (sign SSH certificates, KRL) POST /api/v1/ssh/tokens or the SSH UI

Send each one as Authorization: Bearer <token>. Without OIDC (a test install), the management API needs no token; the integration and fleet tokens are always required.

Terminal window
API=https://pki.example.com # your instance, without /api/v1
TOKEN=eyJ... # OIDC access token (admin role for the write calls below)
INTEGRATION_TOKEN=pkimg_... # from Operations -> Integrations, bound to one CA

Use the client credentials flow with a confidential client in your identity provider (see OIDC: machine-to-machine). With Keycloak:

Terminal window
TOKEN=$(curl -s https://keycloak.example.com/realms/pki/protocol/openid-connect/token \
-d grant_type=client_credentials -d client_id=pki-service -d client_secret="$CLIENT_SECRET" \
| jq -r .access_token)

The token needs the admin role to create CAs and revoke; the user role can list, issue and download.

Terminal window
curl -s "$API/api/v1/cas/?limit=5" -H "Authorization: Bearer $TOKEN" \
| jq '{total: .pagination.total, cas: [.items[] | {id, subject, status}]}'

Lists are paged with limit (at most 100) and offset; pagination.hasMore says if there is more.

Terminal window
CA_ID=$(curl -s -X POST "$API/api/v1/cas/" \
-H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
-d '{
"subject": {"commonName": "Example API Root CA", "organization": "Example Corp", "country": "ES"},
"keyAlgorithm": "RSA-4096",
"validityYears": 10
}' | jq -r .id)
echo "CA: $CA_ID"

The CA key pair is made in the KMS. keyAlgorithm is RSA-2048 or RSA-4096.

Terminal window
CERT_ID=$(curl -s -X POST "$API/api/v1/certificates/" \
-H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
-d '{
"caId": "'"$CA_ID"'",
"subject": {"commonName": "api.example.internal", "organization": "Example Corp", "country": "ES"},
"certificateType": "server",
"keyAlgorithm": "ECDSA-P256",
"validityDays": 90,
"sanDns": ["api.example.internal"],
"sanIp": ["192.0.2.10"]
}' | jq -r .id)
echo "certificate: $CERT_ID"

certificateType is server, client, dual, code_signing or email. The key pair is made in the KMS too. Put the common name in sanDns as well: clients check the SAN, not the CN.

Downloads return JSON; the file is base64 in data.

Terminal window
curl -s "$API/api/v1/certificates/$CERT_ID/download?format=pem" -H "Authorization: Bearer $TOKEN" \
| jq -r .data | base64 -d > api.pem
curl -s "$API/api/v1/cas/$CA_ID/download?format=pem" -H "Authorization: Bearer $TOKEN" \
| jq -r .data | base64 -d > ca.pem
openssl x509 -in api.pem -noout -subject -ext subjectAltName,extendedKeyUsage
openssl verify -CAfile ca.pem api.pem

Other formats: der, p12 / pfx and jks-keystore (need password=), key-pem, full-pem, chain-pem, and more; see the reference for GET /certificates/{id}/download.

Terminal window
curl -s -X POST "$API/api/v1/certificates/$CERT_ID/revoke" \
-H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
-d '{"reason": "superseded", "generateCrl": true}' | jq '{status, revocationDate, revocationReason}'
SERIAL=$(openssl x509 -in api.pem -noout -serial | cut -d= -f2)
CRL_URL=$(openssl x509 -in api.pem -noout -ext crlDistributionPoints | grep -o 'URI:.*' | cut -c5-)
curl -s "$CRL_URL" -o api.crl
openssl crl -in api.crl -noout -text | grep -i -A1 "$SERIAL" | head -2
openssl verify -crl_check -CAfile ca.pem -CRLfile api.crl api.pem || echo "rejected, as expected"

The CRL URL is written into each certificate. reason is one of the RFC 5280 reasons (unspecified, keyCompromise, superseded, cessationOfOperation, …).

Machines that make their own key send a CSR to the external API. The integration token is bound to one CA; the request does not name the CA. The CSR key must be RSA (2048–8192 bits): an ECDSA CSR is rejected today with 400 INVALID_CSR (“Cannot read public key. OID is not RSA.”).

Terminal window
openssl req -new -newkey rsa:2048 -nodes -keyout device.key -out device.csr \
-subj "/CN=device-17.example.internal/O=Example Corp/C=ES" \
-addext "subjectAltName=DNS:device-17.example.internal" \
-addext "extendedKeyUsage=clientAuth" -addext "keyUsage=digitalSignature,keyEncipherment"
jq -n --rawfile csr device.csr '{csrPem: $csr, requestUid: "device-17-2026-11", durationDays: 30}' > sign.json
curl -s -X POST "$API/api/v1/external/sign" \
-H "Authorization: Bearer $INTEGRATION_TOKEN" -H 'Content-Type: application/json' -d @sign.json > signed.json
jq '{idempotent, serialNumber, notAfter}' signed.json
jq -r .certificatePem signed.json | openssl x509 -noout -subject -issuer

requestUid makes the call safe to repeat: the same value returns the same certificate ("idempotent": true). More in Automate issuance.

Errors have one shape: error.code, error.message and, for validation, error.details.

Terminal window
curl -s "$API/api/v1/cas/?limit=500" -H "Authorization: Bearer $TOKEN" | jq .
Status Means
400 the request does not match the schema (see details)
401 no token, or the token is not valid
403 valid token, but the role or the token scope does not allow the call
404 the id does not exist
409 conflict with the current state (for example, already revoked)