To call an API from a flow in Salesforce, you can use the Apex action or the HTTP request action. Here is a step-by-step explanation of how to do it:
- Create a new flow or open an existing flow in Salesforce Setup.
- Drag and drop an Apex action or an HTTP request action onto the canvas.
- If you prefer using the Apex action, you will need to create an Apex class that makes the API callout.
- If you prefer using the HTTP request action, you can directly specify the API endpoint and parameters in the action itself.
Note: The Apex action provides more flexibility and customization options, but the HTTP request action is simpler for basic API calls.
- Configure the Apex action or the HTTP request action:
For the Apex action:- Select the Apex class you created for making the API callout.
- Provide any input variables required by the Apex class.
- Map any output variables from the Apex class to flow variables if needed.
For the HTTP request action:
- Specify the API endpoint URL in the “Endpoint URL” field.
- Choose the appropriate HTTP method (GET, POST, PUT, DELETE) for your API call.
- Add any required headers or parameters.
- Specify the response format (JSON, XML, etc.) and map the response to flow variables if needed.
- Connect the Apex action or the HTTP request action to other elements in the flow as necessary.
- For example, you might want to use decision elements to evaluate the API response and take different paths based on the result.
- Save and activate the flow.
When the flow is executed, it will trigger the API call either through the Apex action or the HTTP request action. You can handle the API response within the flow by mapping it to flow variables or using decision elements to process the data further.
Note: Make sure you have the necessary permissions and authentication setup to access the external API. This may involve configuring authentication credentials, such as API keys or OAuth tokens, depending on the API you’re calling.