Expired Access Token Refresh Requests

Your access token expires after a number of seconds specified in the response element. The default lifespan for an access token is 1440 seconds, a total of 24 minutes.

If you get a 401 response code for a REST API call, you must acquire a new access token. To request a new access token, make a request to the OAuth server using the refresh token you received with the original access token.

You can refresh an access token either after it has expired, or no earlier than two minutes before it expires.

Using a Refresh Token Without mTLS

If you do not have Mutual TLS (mTLS) authentication enabled, use the following CURL example as a model to request a new access token using a refresh token received with a previous access token.

curl -X POST
	{{oauth_server_url_prefix}}/v2/oauth/token \ 
	-H 'Authorization: BasicBase64_Encoded_Client_And_Secret' \ 
	-H 'Content-type:application/x-www-form-urlencoded' \ 
	-d 'grant_type=refresh_token&refresh_token=refresh_token'

Where:

oauth_server_url_prefix is the URL prefix for the OAuth server for your region, as shown on the SAP Ariba Developer Portal on the discovery page for any API, in the Environment details table.

Base64_Encoded_Client_And_Secret is the Base64-encoded OAuth Client ID and OAuth Secret generated as described in Generating the OAuth Secret and Base64 Encoded Client ID and Secret.

refresh-token is the refresh token you received with the access token you wish to refresh

Using a Refresh Token with mTLS

If you have mTLS authentication enabled, use the following CURL example as a model to request a new access token using a refresh token received with a previous access token.

curl --request POST 'oauth_server_url_prefix/v2/oauth/token?grant_type=openapi_2lo'\ 
--header 'client-id: clientId' \
--cert "myCertFile" --key "myPrivateKeyFile" 
--form 'grant_type="openapi_2lo"' \
--form 'refresh_token="refreshToken"'  
         

Where:

oauth_server_url_prefix is the URL prefix for the OAuth server for your region, as shown on the SAP Ariba Developer Portal on the discovery page for any API, in the Environment details table.

clientId is the OAuth Client ID for the application. You can obtain the ID as described in Finding Your Application's Application Key and OAuth Client ID.

myCertFile is the name of the X.509 certificate file configured to authenticate your client as described in Managing Security Certificates for Mutual Authentication.

myKeyFile is the name of the private key file that corresponds to the X.509 certificate.

refresh-token is the refresh token you received with the access token you wish to refresh

Sample Response

{
	"timeUpdated":1462818063261,
	"access_token":"f3e21aaf-218d-48b8-9195-b77bd88c8b82",
	"refresh_token":"da420531-ca3e-4eb0-9c2f-4f6584d1b91f",
	"token_type":"bearer",
	"expires_in":1440
}
Include the new access token in subsequent requests for protected resources. When this new access token expires, you can use the new refresh token to refresh it.

Future token refresh requests should use the newest refresh token. The old refresh token will be invalid.

Response Parameters

timeUpdated
the time when the access token was created
access_token
the token to be included in each request for access to protected resources
refresh_token
the token to be included in a request for a new access token when your current access token has expired
token_type
always bearer
expires_in
the duration in seconds before the token expires. The default is 1440 secondes, or 24 minutes