Agentforce Testing API Authentication

Calls to the Testing API Connect API resources need an access token. To get one, create an external client app in your org, copy its consumer key and secret, and request a token.

Do this setup once per org. The same app and token work for Agentforce Testing API (turn-level and conversational tests) and for the legacy Testing API.

Prerequisites 

To call Testing API endpoints in Connect API, you need an org with Agentforce enabled and at least one active agent. You also need to create an external client app and a token.

User Permissions 

The user that runs the tests needs these permissions. For the client credentials flow, that’s the user you specify in the Run As field when you create the app.

  • AI Testing User (AITestingUser)
  • AI Workbench User (AIWorkbenchUser), which AI Testing User requires

To grant them, create a permission set that includes both user permissions and assign it to the user. To create and assign a permission set, see Create a Permission Set and Assign Permission Sets to a Single User in Salesforce Help.

Create a Salesforce App 

To securely use Connect API endpoints for Testing API, you must create an External Client App (ECA) or a Connected App.

Create an external client app with OAuth and JWT enabled. Use these instructions to get set up: Create a Local External Client App

When creating the app, include these settings.

  1. Use these OAuth Scopes:

    • Access Connect REST API Resources (chatter_api)
    • Manage user data via APIs (api)
    • Manage user data via Web browsers (web)
    • Perform requests at any time (refresh_token, offline_access)

    OAuth scopes settings

  2. In OAuth Settings, select these additional settings:

    • Enable Client Credentials Flow
    • Issue JSON Web Token (JWT)-based access tokens for named users

    OAuth flow and security settings

  3. After creating the app, ensure that the API caller has the correct client credentials and that the client can issue JWT-based access tokens.

    • Click the Policies tab for the app, and then click Edit.
    • Select the Enable Client Credentials Flow checkbox.
    • Specify the client user in the Run As field.
    • Select the Issue JSON Web Token (JWT)-based access tokens checkbox. By default, this token expires in 30 minutes. You can change this value to less than 30 minutes.

Enable Client Credentials Flow appears in two places: in the app’s OAuth Settings (step 2) and on its Policies tab (step 3). Select it in both. If you select it in only one, the token request fails with client credentials flow not enabled.

Important

Obtain Credentials 

To create a token, you need the consumer key and the consumer secret from your ECA.

  1. From Setup, find and select External Client Apps.

  2. Select your app and click the Settings tab.

  3. Expand the OAuth Settings section.

  4. Click the Consumer Key and Consumer Secret button, and copy your secrets. You need these values to mint this token.

    Store your consumer secret in a secure location.

    Important

  5. From Setup, in the Quick Find box, enter My Domain, and then select My Domain.

  6. Copy the value shown in the Current My Domain URL field.

  7. Request a JWT from Salesforce using a POST request, specifying the values for your consumer key, consumer secret, and domain name.

Create a Token 

All calls to Testing API require a token. Create a token by using the consumer key, the consumer secret, and your domain name.

1curl -X POST https://{MY_DOMAIN_URL}/services/oauth2/token
2-d 'grant_type=client_credentials'
3-d 'client_id={CONSUMER_KEY}'
4-d 'client_secret={CONSUMER_SECRET}'
  • MY_DOMAIN_URL: Get the domain from Setup by searching for My Domain. Copy the value shown in the Current My Domain URL field.
  • CONSUMER_KEY, CONSUMER_SECRET: Get the consumer key and secret by following the instructions in Obtain Credentials.

The previous cURL request returns a JSON payload similar to this response.

1{
2  "access_token": "eyJ0bmsiOiJ...(shortened)",
3  "signature": "Zzf2V4jNqOtyYIeotqXNRfKRMmLsFvRwQda+fdgpmH8=",
4  "token_format": "jwt",
5  "scope": "chatter_api api",
6  "instance_url": "https://instance_name.my.salesforce.com",
7  "id": "https://login.test1.pc-rnd.salesforce.com/id/00DSG00000KcODt2AN/005SG00000GiUcHYAV",
8  "token_type": "Bearer",
9  "issued_at": "1737590384852"
10}

Copy the access token specified in the access_token property. This token is required when you make requests to the API. Send it as a bearer token in the Authorization header.

Next Steps 

See Also