Step-by-Step Guide to Creating Custom Action for Agent Using API (External Service)
When Your Agent Needs Data from Outside Salesforce — No Code Required
Agentforce supports a range of action types out of the box — standard actions, Flow actions, and custom Apex actions. For most tasks within Salesforce, these cover a lot of ground.
But some use cases require data that lives outside Salesforce entirely. When a support agent needs to know the weather at a customer's location during a live call, that data doesn't exist in any Salesforce record. The agent needs to reach out to an external service to get it.
In a previous guide, we covered how to do this using Apex REST. This guide covers a different path — API External Services — which requires no Apex code at all. If the external API you want to connect to has an OpenAPI specification, you can wire it directly into Agentforce as a Custom Action through Salesforce's External Services framework.
This guide uses WeatherAPI as the example — but the pattern applies to any external API that provides an OpenAPI specification.
By the end of this guide, your Agentforce Agent will be able to retrieve the current weather at any Contact's location — directly within Salesforce, without writing a single line of Apex.
How This Implementation Works
There are four layers to this implementation, each with a distinct job.
1. External Credential and Named Credential — Secure Authentication
The WeatherAPI key never appears in code. It is stored as an Authentication Parameter under a Named Principal in an External Credential. A Custom Header defined on the External Credential injects the key into every callout using formula syntax, with "Allow Formulas in HTTP Header" enabled on the Named Credential. The Named Credential stores the WeatherAPI base URL and references the External Credential for authentication.
This is the same credential pattern used in the Apex REST guide — and it works identically here. Credentials stay in Setup, out of any code or configuration, and can be rotated without a deployment.
2. External Service — The Bridge to WeatherAPI
This is where this guide's approach differs fundamentally from the Apex REST path.
Rather than writing an Apex class to make the callout, you register WeatherAPI directly in Salesforce as an External Service using its OpenAPI specification. WeatherAPI publishes an official OpenAPI specification on SwaggerHub. You download the YAML file from:
https://api.swaggerhub.com/apis/WeatherAPI.com/WeatherAPI/1.0.2/swagger.yamlYou then upload this file in Salesforce's External Services setup, select the operations you want to expose, and Salesforce generates the integration layer automatically. No Apex, no callout code, no REST class.
The operation used in this guide is Realtime Weather — which maps to WeatherAPI's /current.json endpoint and returns the current weather conditions for a given location.
3. Custom Agent Action — Wiring It to the Agent
The Custom Agent Action is created from the registered External Service in Agentforce Assets using the API action type and External Services as the category. This makes it reusable across multiple agents. Once created, the action is added to the Agent's topic and the agent is activated.
4. Two Paths — Apex REST vs External Services
This guide and the Apex REST guide solve the same business problem using two different approaches. Here's how they compare:
Apex REST + OpenAPI: Custom Apex REST class → OpenAPI document → API Catalog → Agent Action. Code required: Yes — Apex.
API External Services: Download OpenAPI spec → External Service → Agent Action. Code required: No.
Both are valid. The External Services path is the faster route when the external API already has a published OpenAPI specification. The Apex REST path gives you more control — you can transform, filter, and enrich the data before returning it to the agent. Choose based on what your integration requires.
Step-by-Step Guide
The step-by-step guide with screenshots covers:
Sign up and set up an Agentforce Developer Edition org
Create a new Employee Agent in Agentforce Builder
Register for a free WeatherAPI account and note the API key
Create an External Credential with the API key stored as an Authentication Parameter
Create a Named Credential with the WeatherAPI base URL
Configure a Permission Set for External Credential access
Download the WeatherAPI OpenAPI specification from SwaggerHub
Register WeatherAPI as an External Service in Salesforce
Create a Custom Agent Action from the External Service using Agentforce Assets
Add the Custom Action to the Agent
Test the agent
Things to Watch Out For
The API key goes in a Custom Header, not just an Authentication Parameter. Storing the key as an Authentication Parameter under the Principal is only half the job. The Custom Header is what actually injects the key into the callout. Without a Custom Header referencing $Credential.Weather_API_External_Credential.key, the callout will return a 401.
Select only the operations you need. When setting up the External Service, Salesforce presents all available WeatherAPI operations. For this guide, select only Realtime Weather. Selecting all operations adds unnecessary noise to your org and can slow down action selection in Agentforce Builder.
Schema validation must pass before you can proceed. After uploading the YAML file, Salesforce validates the schema. If validation fails, check that the YAML file downloaded correctly and is not corrupted before troubleshooting further.
Summary
API External Services is one of the most underutilised paths to extending Agentforce — partly because most guides focus on Apex and Flows, and partly because the External Services setup involves a few steps that aren't immediately obvious the first time through.
The pattern itself is clean once you understand it. Download the OpenAPI spec, register it as an External Service, select the operations you want, create a Custom Agent Action, and wire it to your agent. No code. No deployment pipeline. No OpenAPI document generation from scratch.
The example in this guide uses WeatherAPI, but the architecture is identical for any external API that publishes an OpenAPI specification — which is increasingly the standard for modern APIs.
Agentforce Advisory, Training & Implementation Services
If you’d like help going deeper with Agentforce beyond this guide, I offer the following:
Self-Paced Training – #Mastering Agentforce
A structured, hands-on course covering Agentforce concepts, Prompt Templates, Agents, Actions, and real-world implementation patterns.
Live Online & Onsite Agentforce Training
Instructor-led training for Salesforce teams, partners, and customer organizations, tailored to real use cases and practical scenarios.
Agentforce Advisory & Implementation Services
Strategic advisory and hands-on implementation support to help you design, build, and scale Agentforce solutions with confidence.
For training, advisory, or implementation discussions, please reach out via the Contact page, where you can submit a form or schedule a conversation.
References & Useful URLs
Documentation — External Services
Blog Post — #Step-by-Step Guide to Creating a Custom Action for Agent Using Apex REST
Got a takeaway from this guide, or have you implemented it in your org? I'd love to hear what you built or what you learned — drop a comment below.