Complete the one-time setup
1
Create a sandbox credential
Open API integrations in the Bahn customer portal. Select Create credential, then give the credential a name that identifies one system.Copy the client ID and client secret before you close the window. The portal shows the client secret one time.
2
Store the credential
Store the client ID and client secret in your server-side secret manager. Do not send the secret to a browser or mobile application.
3
Add the environment URLs
Store the API base URL and token URL with the credential. Do not combine sandbox and production configuration.
4
Verify the sandbox connection
Get an access token. Then call
GET /v2/orders with that token.Complete your order and webhook tests in the sandbox before you create a production credential.Run the token flow
Your system repeats this flow automatically:- Read the client ID and client secret from secure storage.
- Request an access token with HTTP Basic authentication.
- Cache the token for its credential and scope set.
- Send the token in the
Authorizationheader for API requests. - Request a new token before the current token expires.
Get an access token
Use the client ID as the HTTP Basic username. Use the client secret as the password. Send the request body as form data.Use the access token
Send the access token as a Bearer token.Select scopes
Omit thescope form field to request every scope assigned to the credential. Send it when your process needs a smaller set.
A request for a scope that is not assigned to the credential fails. Most integrations can omit the
scope field.
Handle token failures
If an API request returns401, get a new token and retry the request once. Stop if the new token also fails.
If the token endpoint returns invalid_client, check that the credential belongs to the environment in the token URL. Do not retry the same values in a loop.
If the token endpoint returns invalid_request, check the content type, grant_type, and optional scope field.
Replace a credential
Create the replacement credential before you revoke the old credential. Update your system, verify a new token, and then revoke the old credential. Contactsupport@bahnexpress.com if a credential is exposed or you need integration support.
An ordering-channel credential uses the same token flow. It can act for represented businesses through ordered_for. Read Platform ordering for its access rules.