In this blog post, we are going to integrate the Indian Postal API with Salesforce’s Agentforce step by step with a simple and easy-to-follow explanation. Agentforce is one of the latest buzzworthy features in Salesforce, it is also a offering a powerful way to integrate external systems and fetch data in real time. With this integration, sales reps can check post office details across India by entering the name of a place or a PIN code.
This capability is highly useful for industries like retail, logistics, and carrier management, where quick access to postal data can enhance operational efficiency and customer service. Let’s dive into the implementation!
What is Agentforce ?
Agentforce engages with customers autonomously across multiple channels, 24/7, using natural language. It resolves issues quickly and accurately by leveraging trusted data, ensuring a seamless customer experience. With a set of pre-built skills, Agentforce can be deployed to support customers in minutes, or you can easily customize it with low-code options for specific needs. This flexibility enables businesses to tailor the solution for a wide range of customer interactions, from simple queries to complex support cases. Whether you need rapid deployment or deep customization, Agentforce makes it possible to enhance customer engagement and operational efficiency, all with minimal technical expertise.
How does Agentforce work?
Agentforce is a powerful AI-driven assistant in Salesforce that can handle complex queries, retrieve precise business insights, automate actions, and seamlessly scale across teams and departments.
At its core, it utilizes the Atlas Reasoning Engine, which deconstructs a given request into manageable tasks. It systematically evaluates each step, formulates a strategy, and executes the necessary actions to deliver a complete and accurate response.
This advanced capability makes Agentforce a valuable tool for enhancing business automation, decision-making, and seamless system integrations.
Now What is the Indian Post API?
The Indian Postal API, commonly referred to as PostalPincode.in API, is a public API that provides postal-related data across India. It allows users to retrieve detailed information about post offices, PIN codes, and locations directly from the India Post database.
Example 1 (Search by Postal PIN Code):
GET https://api.postalpincode.in/pincode/{PINCODE}
Ex: https://api.postalpincode.in/pincode/110001
Response For Valid PIN Codes:
[{"Message":"Number of pincode(s) found:21","Status":"Success","PostOffice":[{"Name":"Baroda House","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"Bengali Market","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"Bhagat Singh Market","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"Connaught Place","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"Constitution House","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"Election Commission","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"Janpath","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"Krishi Bhawan","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"Lady Harding Medical College","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"New Delhi ","Description":null,"BranchType":"Head Post Office","DeliveryStatus":"Delivery","Circle":"Delhi","District":"New Delhi","Division":"New Delhi GPO","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"North Avenue","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"Parliament House","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"Patiala House","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"Pragati Maidan","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"Pragati Maidan Camp","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"Rail Bhawan","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"Sansad Marg","Description":null,"BranchType":"Head Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"Sansadiya Soudh","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"Secretariat North","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"Shastri Bhawan","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"Supreme Court","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"Central Delhi","Division":"New Delhi Central","Region":"Delhi","Block":"New Delhi","State":"Delhi","Country":"India","Pincode":"110001"}]}]
Example 2 (Search by Post Office Branch Name):
To get details of a Post Office Branch details (New Delhi)
GET https://api.postalpincode.in/postoffice/{POSTOFFICEBRANCHNAME}
Ex: https://api.postalpincode.in/postoffice/New Delhi
Response For Valid Post Office Branch Name:
[{"Message":"Number of Post office(s) found:2","Status":"Success","PostOffice":[{"Name":"New Delhi ","Description":null,"BranchType":"Head Post Office","DeliveryStatus":"Delivery","Circle":"Delhi","District":"New Delhi","Division":"New Delhi GPO","Region":"Delhi","State":"Delhi","Country":"India","Pincode":"110001"},{"Name":"New Delhi South Ext-II","Description":null,"BranchType":"Sub Post Office","DeliveryStatus":"Non-Delivery","Circle":"Delhi","District":"South Delhi","Division":"New Delhi South","Region":"Delhi","State":"Delhi","Country":"India","Pincode":"110049"}]}]
Implementing Indian Postal Agent
Now that we have a understanding of Agentforce and Indian Postal API, let’s dive into the actual implementation. You’ll definitely enjoy this process, and it will be well worth your time!
Step1: Setting Up a Dev Org for Agentforce
Since Agentforce is currently in beta, it is not available in regular Salesforce Developer Orgs. However, Salesforce provides a special org for practice through one of its Trailhead modules. Keep in mind that this org is temporary and will expire after a certain period. Click on this for Agentforce playground.

Step 2: Enable Agent Setup
- Click the Setup icon and select Setup. This will open the Setup page in a new tab.
- In the Quick Find search bar, type and select Einstein Setup.
- Click the Turn On Einstein toggle and ensure that Einstein is enabled.
- Refresh your browser to reload the Setup page.

- In the Setup Quick Find, search for and select Agents.
- Click the Agentforce toggle, and ensure it is set to On.

Step 3: Create Indian Postal Agent
The first step in setting up an agent is the guided setup, which walks you through the process of creating an agent, assigning topics, and configuring essential settings.
Topics define the types of tasks the agent can handle, while actions represent the tools or steps the agent uses to complete those tasks. For example, when a client inquires about a specific topic, the agent determines the appropriate action(s) to take in response.
- In the Setup Quick Find, search for and select Agents.

2. Click + New Agent. Note: If the New Agent button is not present, refresh the page until the button appears.
3. Select Agentforce Service Agent as the type. Click on Next.
4. Remove the added Topics in Review Topics, click on next.
,5. Change the Name to Indian Postal Agent and ensure the API Name updates to Indian_Postal_Agent.
6. Enter this info for Company: Deliver personalized customer interactions with an autonomous AI agent. Indian Postal Agent intelligently supports your customers with common inquiries and escalates complex issues.
7. Enter the info for Role: The Postal Agent’s role is to intelligently provide post office details by taking user input, such as the PIN code and place. It offers accurate and timely information to assist users with their postal needs.
8. Enter the info for the company: The Indian Postal Agent is to intelligently provide post office details by taking user input, such as the PIN code and place. It offers accurate and timely information to assist users with their postal needs.
7. Select EinsteinServiceAgent User as the Agent User.

8. For now, Data Cloud won’t be used. Click Create.
Step4: Add Custom Topics and Actions
Topics and actions can be created and customized using Agent Builder. Note: It’s not recommended to use the standard query and summarization actions with a public facing agent, so instead use custom actions to interact with the data.
1. From the Agent Builder, click New and select New Topic. Note: If the New button does not appear, return to the agent setup page and toggle the Agentforce toggle to off, then back to on again.

2. In the modal, configure the Start element as follows:
Field | Value |
---|---|
Topic Label | Indian Postal Management |
Classification Description | The Postal Agent is an intelligent system designed to provide accurate post office details based on user input, such as the PIN code and Place or city. Its primary function is to assist users by delivering timely and precise information about post office services, locations, and related postal needs. |
Scope | The Postal Agent’s objective is to provide users with accurate and timely post office details based on their input, such as PIN code and location. |
3. At the bottom, click Add Instructions 4 times. There will now be six blank instruction text boxes.
4. Add these Instructions:
Field | Value |
---|---|
1st Instruction | When a user asks for the list of post offices by providing the PIN code, perform the action ‘Check Post Office Details’ and display the list of places. |
2nd Instruction | If a user provides a non-numeric input for the PIN code, respond with an appropriate message informing them that the PIN code should be a number, not a string. |
3rd Instruction | When a user asks for the list of post office by providing the name. perform the action ‘Check Post Office Details by Name’ and display the list of places. |
4th Instruction | If a user provides a non-string input for the name of the place, respond with an appropriate message informing them that the post office name should be a string or text. |
5. Leave everything else as is and click Next.
6. Custom actions will be added to this topic so skip adding any of the standard actions and click Finish.
Step5: Add Custom Actions to the Agent
Agent actions can be created using Apex, Flow, and Prompt templates. In this example, we will use an Apex action and create an Apex method to call out to the Postal APIs. Here
Here, we have two Apex actions for our agent: one is ‘Check Post Office Details by Pincode,’ and the other is ‘Check Post Office Details by Name.’ We will create two Apex classes for these actions, each containing an @InvocableMethod. The Apex methods must be annotated with @InvocableMethod to make them available for creating agent actions.
public class CheckPostOfficeDetailsByPinCode {
@InvocableMethod(
label='Check Post Office Details By Pincode'
description='Returns the Post office details if the users ask please give the post office details of for the pin code 534275'
)
public static List<String> getPostOfficeData(List<String> pinCodeList){
String pincode = pinCodeList[0];
String apiResponse = PostOfficeAPIService.getPostOfficeDataByPin(pinCode);
return new List<String> {apiResponse};
}
}
The @InvocableMethod annotation includes a label, which will serve as the action name, and an optional description that provides instructions for the agent. This method parameter should be a List.
We also have one more Apex class, PostOfficeAPIService, where we have written the actual logic to call out the API.
public class PostOfficeAPIService {
public static String getPostOfficeDataByPin(String pinCode) {
String endPoint = 'https://api.postalpincode.in/pincode/'+pinCode;
String postOffices = '';
try{
HttpRequest request = new HttpRequest();
request.setEndpoint(endPoint);
request.setMethod('GET');
Http http = new Http();
HttpResponse response = http.send(request);
if(response.getStatusCode() == 200){
String jsonData = response.getBody();
List<PostOfficeApiResponse> responseData = (List<PostOfficeApiResponse>)Json.deserialize(jsonData, List<PostOfficeApiResponse>.class);
for(PostOffice item: responseData[0].postOffice){
postOffices = postOffices + item.Name + ',';
}
return postOffices;
}else{
System.debug('error occured' + response.getStatus());
return response.getStatus();
}
}catch(Exception e){
throw new AuraHandledException(e.getMessage());
}
}
}
Creating Agent Action-1 Utilizing the Above Apex Method:
In the setup, navigate to Agent Actions and click on the ‘+New Action’ button. A new popup will open. Select ‘Apex’ as the reference action type, choose the Apex method (label value), and and select ‘Check Post office Details’ from the list and click ‘Next.

After clicking ‘Next,’ you need to provide the action instructions (the @InvocableMethod description will be reflected here), define the input and output values, and then click the ‘Finish’ button. The agent action will be created successfully.

The same process applies to the second action, which will be invoked to retrieve post office details by the name of the place.
public class CheckPostOfficeDetailsByPlace {
@InvocableMethod(
label='Check Post Office Details by Place'
description='Returns the Post office details if the users ask please give the post office details of for the name Hyderabad'
)
public static List<String> getPostOfficeData(List<String> nameList){
String name = nameList[0];
String apiResponse = PostOfficeAPIService.getPostOfficeDataByPlace(name);
return new List<String> {apiResponse};
}
}
Same as above we are going to use PostOfficeAPIServiceclass, where we have written the actual logic to call out the API.
public class PostOfficeAPIService {
public static String getPostOfficeDataByPlace(String place) {
String endPoint = 'https://api.postalpincode.in/postoffice/'+ place;
String postOffices = '';
try{
HttpRequest request = new HttpRequest();
request.setEndpoint(endPoint);
request.setHeader('Content-Length', '0');
request.setMethod('GET');
Http http = new Http();
HttpResponse response = http.send(request);
if(response.getStatusCode() == 200){
String jsonData = response.getBody();
List<PostOfficeApiResponse> responseData = (List<PostOfficeApiResponse>)Json.deserialize(jsonData, List<PostOfficeApiResponse>.class);
for(PostOffice item: responseData[0].postOffice){
postOffices = postOffices + item.name + ' - ' + item.PINCode + ',';
}
return postOffices;
}else{
System.debug('error code' + response.getStatusCode());
return response.getStatus();
}
}catch(Exception e){
throw new AuraHandledException(e.getMessage());
}
}
}
Complete PostOfficeAPIService class code:
public class PostOfficeAPIService {
public static String getPostOfficeDataByPin(String pinCode) {
String endPoint = 'https://api.postalpincode.in/pincode/'+pinCode;
String postOffices = '';
try{
HttpRequest request = new HttpRequest();
request.setEndpoint(endPoint);
request.setMethod('GET');
Http http = new Http();
HttpResponse response = http.send(request);
if(response.getStatusCode() == 200){
String jsonData = response.getBody();
List<PostOfficeApiResponse> responseData = (List<PostOfficeApiResponse>)Json.deserialize(jsonData, List<PostOfficeApiResponse>.class);
for(PostOffice item: responseData[0].postOffice){
postOffices = postOffices + item.Name + ',';
}
return postOffices;
}else{
System.debug('error occured' + response.getStatus());
return response.getStatus();
}
}catch(Exception e){
throw new AuraHandledException(e.getMessage());
}
}
public static String getPostOfficeDataByPlace(String place) {
String endPoint = 'https://api.postalpincode.in/postoffice/'+ place;
String postOffices = '';
try{
HttpRequest request = new HttpRequest();
request.setEndpoint(endPoint);
request.setHeader('Content-Length', '0');
request.setMethod('GET');
Http http = new Http();
HttpResponse response = http.send(request);
if(response.getStatusCode() == 200){
String jsonData = response.getBody();
List<PostOfficeApiResponse> responseData = (List<PostOfficeApiResponse>)Json.deserialize(jsonData, List<PostOfficeApiResponse>.class);
for(PostOffice item: responseData[0].postOffice){
postOffices = postOffices + item.name + ' - ' + item.PINCode + ',';
}
return postOffices;
}else{
System.debug('error code' + response.getStatusCode());
return response.getStatus();
}
}catch(Exception e){
throw new AuraHandledException(e.getMessage());
}
}
class PostOfficeApiResponse{
List<PostOffice> postOffice;
}
class PostOffice{
String Name;
String PINCode;
}
}
Creating Agent Action-2 Utilizing the Above Apex Method:
As of now, we have created an action for ‘Check Post Office Details’. Next, we need to create the ‘Check Post Office Details by Name’ agent action and use the above Apex method to get the details.
Again, In the setup, navigate to Agent Actions and click on the ‘+New Action’ button. A new popup will open. Select ‘Apex’ as the reference action type, choose the Apex method (label value), select ‘Check Post Office Details by Name‘ from the list and click ‘Next.

After clicking ‘Next,’ you need to provide the action instructions (the @InvocableMethod description will be reflected here), define the input and output values, and then click the ‘Finish’ button. The agent action will be created successfully.

Adding Agent Actions to a Topic:
We are almost done. The created actions need to be added to the Topic. For that, go to the Agent Builder and click on the Topic that was created, ‘Indian Postal Management.’ Go to the ‘This Topic’s Actions’ tab and click on the New button. You will be able to select two options: one is ‘Create New Action’ and the other is ‘Add from Asset Library.’ Since we already have actions, just go with the second option.


Once you have added the action to the topic, click Finish and save the topic.
Before testing, we need to ensure a few things:
- Our agent user should have access to the Apex classes we created. Add the Custom Einstein Agent User profile to all those classes, as shown in the screenshot below.

2. Since we are communicating with an external system, the Postal API should be added to the Remote Site Settings, as shown below. If you are still encountering any callout errors, you can add the URL to the trusted URLs.

Testing the Indian Postal Agent:
We are now ready to test our agent. Simply refresh the Conversation Preview by clicking on the refresh icon and enter the prompts. Once everything is working correctly, you can activate the agent.
