Loading
Salesforce now sends email only from verified domains. Read More
Automate Your Business Processes
Table of Contents
Select Filters

          No results
          No results
          Here are some search tips

          Check the spelling of your keywords.
          Use more general search terms.
          Select fewer filters to broaden your search.

          Search all of Salesforce Help
          Manage External Inventory with HTTP Callout Action Example

          Manage External Inventory with HTTP Callout Action Example

          This example reviews your store's inventory levels and make an HTTP callout to your supplier's API to place orders when inventory is low.

          Required Editions

          Available in: Lightning Experience
          View supported editions.
          User Permissions Needed
          To open, edit, create, activate or deactivate a flow using all flow types, elements, and features available in Flow Builder, including Einstein and Agentforce for Flow: Manage Flow
          To create an external credential, a named credential, and an HTTP callout action: Customize Application

          Let's say that you want to make managing your pet store's inventory easier by integrating with your supplier's ordering system so that you can place orders in real time. You want to create a flow that reviews your inventory levels and triggers a call to your supplier's API when they're low. When you click Submit Order, it prompts a real-time API call that automatically places your order.

          Before you configure an HTTP callout action:

          • Create an external credential and a named credential so that the external service can connect to the API. See Guidelines for Authenticating HTTP Callout Actions. In this example, the external credential is PetStore and the named credential is Acme Pet Supplies.
          • Prepare a sample API response in JSON format. If a sample doesn't exist in the API's documentation, you can use a third-party API platform to retrieve a response. In this example, the sample API response used is:
            {
              "id": 0,
              "petId": 0,
              "quantity": 0,
              "shipDate": "2024-10-09T08:49:33.605Z",
              "status": "placed",
              "complete": true
            }
          • Start with an API that's well documented. If details such as field requirements or definitions are inaccurate or outdated, it can take time to debug.
          1. Open the Flows list view.
            • From Setup, in the Quick Find box, enter Flows, and then select Flows.
            • From the Automation app, select the Flows tab.
            • From the Flows tab in any Lightning app, click the actions menu and select Open Flow.
          2. Create a screen flow.
            • From the Automation app, click New | Screen | Screen Flow.
            • From Setup, click New Flow | Screen | Screen Flow.
          3. Add the Get Records element and configure it.
            1. For Label, enter Get Pet Inventory.
            2. For Object, select Inventory.
            3. For Condition Requirements, select None—Get All Inventory Records.
            4. For How Many Records to Store, select All Records.
            Get Records element configuration
          4. After the Get Pet Inventory element, add a Screen element and configure it.
            1. For Label, enter Reorder Pet Inventory.
            2. For API Name, enter Reorder_Pet_Inventory.
            3. Under Configure Header, enable Show Header.
            4. Under Configure Footer, enable Show Footer.
          5. Add a Section component to the Reorder Pet Inventory screen and configure it.
            1. Enable Include Header.
            2. For Label, enter Pet Inventory.
            3. For API Name, enter Available_Pets.
            4. Under Configure columns, add the required columns, and set the width.
          6. Add a Data Table component as a child of the Pet Inventory section and configure it.
            1. For API Name, enter petTable.
            2. For Label, enter Available Pets.
            3. Enable Use Label as the table title.
            4. For Source Collection under Configure Data Source, enter {!Get_Pet_Inventory}.
            5. Enable Show search bar.
            6. Under Configure Columns, add required columns.
          7. Add another Section component as a child of the Reorder Pet Inventory screen and configure it.
            1. Enable Include Header.
            2. For Label, enter Restock Selected Pet.
            3. For API Name, enter Reorder_Information.
            4. Under Configure Columns, add the required columns, and set their width.
          8. Add a Text component as a child of the Restock Selected Pet section and enter these values.
            1. For Label, enter Selected Pet.
            2. For API Name, enter Selected_Pet.
            3. For Default Value, enter {!petTable.firstSelectedRow.Name}.
          9. Add a Currency component as a child of the Restock Selected Pet section and enter these values.
            1. For Label, enter Cost Per Unit.
            2. For API Name, enter Cost_Per_Unit.
            3. For Default Value, enter {!petTable.firstSelectedRow.Current_MSRP__c}.
          10. Add a Number component as a child of the Restock Selected Pet section and enter these values.
            1. For Label, enter Order Quantity.
            2. For API Name, enter Order_Quantity.
            3. For Decimal Places, enter 0.
          11. Add another Number component as a child of the Restock Selected Pet section and enter these values.
            1. For Label, enter Total Cost.
            2. For API Name, enter Total_Cost.
            3. For Default Value, enter {!formulaTotalCost}.
            4. For Decimal Places, enter 2.
            Screen element configuration
          12. After the Screen element, add an Action element and configure it.
            1. Click Create HTTP Callout.
              A list of action categories in Action element.
            2. In Create External Service, for Name, enter OrderPetTest.
            3. For Named Credential, select Acme Pet Supplies.
              The URL associated with the credential is autopopulated.
            4. Click Next.
            5. In Configure Invocable Action, for Label, enter Order Pet.
            6. For Method, select POST.
            7. For URL Path, enter /store/order.
            8. Click Next.
              HTTP Callout configuration
            9. For Sample JSON Request, enter the JSON snippet required for this example.
            10. To confirm data structure parameters, click Review.
              Sample JSON Request configuration
            11. In Select Sample Response Method, select Connect for Schema, and then click Next.
            12. Click Save.
            13. For Label, enter Callout to Order Pets.
            14. For API Name, enter Callout_to_Order_Pets.
            15. In Set Body Request, for Value, enter {!Order_Pet_Input_Test}.
          13. Before the Callout to Order Pets action, add an Assignment element and configure it.
            1. For Label, enter Assign Callout Request Fields.
            2. For API Name, enter Assign_Callout_Request_Fields.
            3. For Set Variable Values, enter {!Order_Pet_Input_Test.id} Equals. {!petTable.firstSelectedRow.Recommended_Reorder_Quantity__c}.
            4. Click Add Assignment, and enter {!Order_Pet_Input_Test.quantity} Equals {!Order_Quantity}.
            5. Click Add Assignment, and enter {!Order_Pet_Input_Test.shipDate} Equals {!$Flow.CurrentDate}.
            6. Click Add Assignment, and enter {!Order_Pet_Input_Test.status} Equals Placed.
            Assignment element configuration
          14. After the Callout to Order Pets action, add a Decision element and configure it.
            1. For Label, enter Was Callout Successful?.
            2. For API Name, enter Was_Callout_Successful.
            3. For Select Decision Logic, select Define Manually (Default).
            4. For the New Outcome label, enter Callout Successful.
            5. For Condition Requirements to Execute Outcome, select All Conditions Are Met (AND).
            6. For Resources, enter {!Callout_to_Order_Pets.responseCode}Greater Than or Equal 200.
            7. Click Add Resources, enter {!Callout_to_Order_Pets.responseCode} Lesser Than or Equal 200.
            8. Click Default Outcome.
            9. For Label, delete the text, and then enter Callout Not Successful.
            Decision element configuration
          15. On the Callout Not Successful outcome path, add a Screen element and configure it.
            1. For Label, enter Error Screen.
            2. For API Name, enter Error_Screen.
            3. Under Configure Header, enable Show Header.
            4. Under Configure Footer, enable Show Footer.
          16. On the Callout Successful outcome path, add an Update Records element and configure it.
            1. For Label, enter Update Inventory Quantity on Hand.
            2. For API Name, enter Update_Inventory_Quantity_on_Hand.
            3. For ​​How to Find Records to Update and Set Their Values, select Specify conditions to identify records, and set fields individually.
            4. For Object, select Inventory.
            5. For Condition Requirements to Update Records in Filter Inventory Records, select All Conditions Are Met (AND).
            6. For Field, Operator, and Value, select Record ID Equals {!petTable.firstSelectedRow.Id}.
            7. In Set Field Values for the Inventory Records, for Field, select Quantity on Order.
            8. In Set Field Values for the Inventory Records, for Value, enter ​​{!UpdateQuantityOnHand}.
            Update Records element configuration
          17. On the Callout Successful outcome path, next to the Update Inventory Quantity on Hand element, add a Screen element and configure it.
            1. For Label, enter Order Placed.
            2. For API Name, enter Order_Placed.
            3. Under Configure Footer, enable Show Footer.
            4. For Navigation, select Use a custom label.
            5. For Next or Finish Button Label, enter OK.
            6. Hide the Previous and Pause buttons.
            7. Add a Display component to the Screen element.
            8. For the API Name of the Display component, enter SuccessDisplayHeader.
            9. For Description of the Display component, enter Your order was successful!.
            10. Add a Section component to the Screen element.
            11. For Label of the Section component, enter ​​Order Summary.
            12. For the API Name of the Section component, enter OrderSummary.
            13. Set the Column width based on the requirement.
            14. Add required Display components as children of the Section, and configure them based on the requirement.
            Screen element configuration
          18. Save the flow, and then click Debug to troubleshoot the flow for any errors.
          19. Click Run.
          20. Select an inventory item that you want to order.
            Debug screen of HTTP Callout example.
          21. Enter an order quantity, and then click Submit Order.
            The order is placed successfully. If the flow fails, troubleshoot the flow errors.
          22. (Optional) To restart the flow by using the same or different values for the input variables, click Change Inputs or Run Again.
            You can't convert the debug run to a test in the screen flow.
            HTTP Callout Example
           
          Loading
          Salesforce Help | Article