How to call API from flow in Salesforce

| By Sonali Sharma

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.
    1. If you prefer using the Apex action, you will need to create an Apex class that makes the API callout.
    2. 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:

    1. Select the Apex class you created for making the API callout.
    2. Provide any input variables required by the Apex class.
    3. Map any output variables from the Apex class to flow variables if needed.

    For the HTTP request action:

    1. Specify the API endpoint URL in the “Endpoint URL” field.
    2. Choose the appropriate HTTP method (GET, POST, PUT, DELETE) for your API call.
    3. Add any required headers or parameters.
    4. 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.
    1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *