Asynchronous Interaction Pattern

To specify an asynchronous request, you must add the callback URI to the integration definition for Standard Fulfillment Provider or Apex Type Provider as an optional attribute.

Standard Fulfillment Provider 

  • Provide the callback URI in the integration definition to accept the callback.

  • Use these steps to set up the async callout.

      • Use the ResponseUri key to retrieve the Callback URI value from the payload.

      • Use the StepId key to retrieve the Fulfillment Step value from the payload. If order item ID is returned instead of Fulfillment Step ID, use CorrelationId key to extract the value of the step ID. For example, callout:13Wxx0000004CAf:.

      • Pass the StepId value to the callback URI endpoint. Return 202 response code to ensure the Fulfillment Step is in Running state. Otherwise, the 200 response code completes the step.

        Here’s a sample payload.

        1{
        2    "ResponseUri": "/services/apexrest/async/callout",
        3    "StepId": "802xx000001nb1MAAQ",
        4    "CorrelationId": "callout:13Wxx0000004CAf:",
        5    ...//Other values
        6}
  • Extract the step ID from the request. Find the Fulfillment Step ID in the org by using the extracted step ID and update the Fulfillment Step state to Completed.

Apex Type Provider 

  • Provide the callback URI in the integration definition to accept the callback.

  • Set up the async callout by using Apex Type Provider.

      • Create an Apex class that implements the ProcessIntegrationProvider interface.

        Here’s a sample that shows the addition of a callback URI to the provider attribute for Apex Type Provider.

        1global with sharing class DFOAsyncApexSample implements industriesintegrationfwk.ProcessIntegrationProvider {
        2
        3    private static final industriesintegrationfwk.ApexProviderAttr NAMED_CRED_ATTR = 
        4        new industriesintegrationfwk.ApexProviderAttr('Named Credential', 
        5        'Named_Credential', 'DFOCalloutMockCreds', true, 'String');
        6 
        7    private static final industriesintegrationfwk.ApexProviderAttr CALLBACK_URL_ATTR = 
        8        new industriesintegrationfwk.ApexProviderAttr('Callback URL', 
        9        'Callback_URL', 'DFOCallbackUrl', true, 'String');
        10
        11    global static List<industriesintegrationfwk.ApexProviderAttr> getProviderAttributes() {
        12        List<industriesintegrationfwk.ApexProviderAttr> defaults = new List<industriesintegrationfwk.ApexProviderAttr>();
        13        defaults.add(NAMED_CRED_ATTR);
        14        defaults.add(CALLBACK_URL_ATTR);
        15     
        16        return defaults;
        17    }
      • Specify the Fulfillment Step ID as the value of the requestGuid parameter of the executeCallout method. You can also extract the Step ID from the CorrelationId key value. For example, "callout:13Wxx0000004CAf:".

        Here’s a sample payload that assigns the provider attribute values.

        1public interface ProcessIntegrationProvider {
        2    IntegrationCalloutResponse executeCallout(String requestGuid, 
        3    String inputRecordId, String payload, Map<String, Object> attributes);
        4
        5    List<ProviderAttr> getProviderAttributes();
        6}
    • Set response code to 202 to indicate that the callout is asynchronously executed and in Processing state.

      Here’s a sample payload that sets the response code.

      1global with sharing class DFOAsyncApexSample implements industriesintegrationfwk.ProcessIntegrationProvider {
      2...
      3IntegrationCalloutResponse executeCallout(String requestGuid, 
      4    String inputRecordId, String payload, Map<String, Object> attributes){
      5    // execute http request
      6    ...
      7    // set accepted if no failures
      8    IntegrationCalloutResponse acceptedResponse = 
      9        new IntegrationCalloutResponse(true);
      10    acceptedResponse.setResponseCode(202);
      11    
      12    return new IntegrationCalloutResponse();
      13    }
      14}
    • The callback URI is visible in the integration definition.

      Integration Definition for Apex Type Provider

  • Extract the step ID from the request. Find the Fulfillment Step ID in the org by using the extracted step ID and update the Fulfillment Step state to Completed.

    1FulfillmentStep step = new FulfillmentStep(id = 'stepId', State = 'Completed'); 
    2upsert step;