
Getting the Bearer Token for a Connected App Example
This example demonstrates how to create a connected app that acts on its own behalf using client credentials to get the bearer token so you can invoke Anypoint Platform APIs.
Create a Connected App
To create a connected app, add Runtime Manager scopes, and deploy the app to CloudHub:
-
In the Access Management navigation menu, click Connected Apps.
-
In Owned Apps, click Create App.
-
In Create App, enter a unique name for the app, select App acts on its own behalf (client credentials), and then click Save.
-
Click Add Scopes.
-
Select the scopes for the app from the Runtime Manager section, and then click Next.
For information about scopes and permissions for connected apps, see the Endpoint Scopes.
-
Select the Business Groups the app has permission to access the assigned scopes in and click Next.
-
Select the Environments for the business groups and scopes you selected, and click Next.
-
Review the scopes you added and click Add Scopes.
-
In Update App, click Save Changes.
Get the bearer token
To get the bearer token for the app:
-
In the Access Management navigation menu, click Connected Apps.
-
In Owned Apps, click Copy Id and save the app’s client ID in a secure location.
-
Repeat the previous step to copy the app’s client secret.
-
Run the following cURL command and replace
CLIENT_ID
andCLIENT_SECRET
with your client ID and secret:curl --location --request POST https://anypoint.mulesoft.com/accounts/api/v2/oauth2/token \ --header 'Content-Type: application/x-www-form-urlencoded' \ --data-urlencode 'client_id=<CLIENT_ID>' \ --data-urlencode 'client_secret=<CLIENT_SECRET>' \ --data-urlencode 'grant_type=client_credentials'
commandYou receive the following response:
{ "access_token": "<bearer token>", "token_type": "bearer" }
Now that you have the bearer token, you can use the connected app to invoke Anypoint Platform APIs. For more examples, see Connected App Examples
.