
Salesforce Agent API can be used to invoke Salesforce Agentforce Agents using APIs.
Configuration:
1. Create a Connected App in Salesforce Setup under App Manager.
a. “Enable OAuth Settings” should be selected.
b. For the Callback URL, use https://login.salesforce.com.
c. For the Selected OAuth Scopes, select “Access chatbot services (chatbot_api)”, “Access the Salesforce API Platform (sfap_api)”, “Manage user data via APIs (api)” and “Perform requests at any time (refresh_token, offline_access)”.
d. Deselect Require Proof Key for Code Exchange (PKCE) Extension for Support Authorization Flows, Require Secret for Web Server Flow and Require Secret for Refresh Token Flow.
e. Make sure “Enable Client Credentials Flow” and “Issue JSON Web Token (JWT)-based access tokens for named users” are enabled on the Connected App.
f. In the “Run As”, please select a user that has “API Only” permission. If you use or select an user without this permission, it will not work.
2. Go to Agents in Salesforce Setup. Select the Agent. Go to Connections Tab. Click the “Add” button in Connections sections. Select the Connected App created in Step 1.

API Steps:
1. Generate Access Token.


2. Create the Session. Use the Access Token and API Instance URL from the Step 1.


Sample Body JSON Payload:
Kindly use your Salesforce My Domain URL in the endpoint.
{
"externalSessionKey": "488abeaf-bb0b-42be-8ec1-41bddf154f97",
"instanceConfig": {
"endpoint": "https://dsb00000fiy6z2af.test1.my.pc-rnd.salesforce.com"
},
"streamingCapabilities": {
"chunkTypes": ["Text"]
}
}
For externalSessionKey, you cane use andomUUID() from UUID class in Apex.
Sample Apex Code:
UUID randomUUID = UUID.randomUUID();
System.debug(
'randomUUID is ' +
randomUUID
);
System.debug(
'randomUUID String value is ' +
randomUUID.toString()
);
3. We can send a message to the Agentforce Agent. It will process and send the response. We are going to make use of Synchronous Message endpoint.


Sample Body JSON Payload:
{
"message": {
"sequenceId": 2,
"type": "Text",
"text": "Opportunity Booking"
},
"variables": []
}
4. Once the conversation is completed, you have to end the Session. To end the Agentforce API session, do a Delete request.

Salesforce Article:
https://developer.salesforce.com/docs/einstein/genai/guide/agent-api.html