Hear from Salesforce leaders on how to create and deploy Agentforce agents.
Contact Us 1-800-596-4880

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:

  1. In the Access Management navigation menu, click Connected Apps.

  2. In Owned Apps, click Create App.

  3. In Create App, enter a unique name for the app, select App acts on its own behalf (client credentials), and then click Save.

  4. Click Add Scopes.

  5. 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.

  6. Select the Business Groups the app has permission to access the assigned scopes in and click Next.

  7. Select the Environments for the business groups and scopes you selected, and click Next.

  8. Review the scopes you added and click Add Scopes.

    Add scopes review with Runtime Manager scopes selected
  9. In Update App, click Save Changes.

Get the bearer token

To get the bearer token for the app:

  1. In the Access Management navigation menu, click Connected Apps.

  2. In Owned Apps, click Copy Id and save the app’s client ID in a secure location.

  3. Repeat the previous step to copy the app’s client secret.

  4. Run the following cURL command and replace CLIENT_ID and CLIENT_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'
    command

    You 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 ExamplesLeaving the Site.