10 - Call 3rd-Party System and Wait for Callback
- How to pause process instance with “Wait for an API Call”
- How to call trigger to resume process instance
Prerequisites
- You have completed the previous tutorial for the event-based processes CodeJam, Add 2nd Approval With Custom Variables, Conditions and Form Events.
- Step 1
Remember, our action will just describe the type of service we want to access, but we need to create a destination to indicate the actual backend service to call.
-
Download the destination template.
Click Destination template, and then click the download button.

-
Go to the SAP BTP cockpit for your subaccount.
You can always return to your trial account cockpit by going to https://account.hanatrial.ondemand.com/ and then opening your subaccount.
Click Connectivity > Destinations.

Click Import Destination, and select the file you downloaded.

-
Click Save.
-
Click Check Connection, and you should get a 200 status code.

-
- Step 2
You created a destination, but you must let SAP Build Process Automation know that you want to allow it to be used in deployed processes.
-
In the main SAP Build page, click Control Tower.
-
Click Destinations.

-
Click Add.

Select the AccessProService destination.

Click Next.
Keep All Environments, and click Add Destination.

The destination should now appear in the list of destinations that can be used with your processes.

-
- Step 3
-
In the SAP Build menu, click Actions.

-
Click Create.

Select OData Destinations.

Select AccessProService.

-
You will now see a list of all the entities and all the API calls you can make, only for your information.

Click Next.
-
Name the action as follows:
Field Value Name Access Pro Service Description A 3rd-party service for managing the creation of employee/visitor badges. 
Click Create.
You will now see the operations available for this service, and you will need to decide which ones to expose (to “your” developers).
-
Select the POST /Badges call, since you will want to create a new badge request during your process.

Click Add.
You now get the action where you can modify the inputs and outputs, or add additional API calls to this action. We will keep the inputs and outputs as is.
-
Under Inputs, select ID and click Remove.
The CAP service will generate an ID automatically, so we do not want to be forced to supply that field.

Click Save.

-
Click Release, then click Release to confirm..

Click Publish, and then click Publish to confirm.

-
- Step 4
We will want the 3rd-party system to call our process back, and we need to supply to it the process instance ID. So first we must store the value.
-
Go back into your process, and make sure you have the Editable version open.
With nothing selected (just click in an open space), open the side panel.
Under Variables, and then under Custom Variables, click Configure.

-
Click Add Variable.
Set the name to instanceID.
The identifier is automatically generated and the type is automatically String.
Click Apply.

-
Above the notification step, add a script task.

-
Set the name to Get instance ID.

-
Open the editor.
Add the following line to the editor.
JavaScriptCopy$.context.custom.instanceid = $.info.workflowInstanceId
Click Apply.
-
Click Save (upper right).
-
- Step 5
-
Under the script task, click the plus sign, +, and add an action.

-
Click Browse All Actions.

Select the Add new entity to Badges (as part of Access Pro Service project), and click Add.

-
In the side panel, create a destination variable.
Click inside the Destination Variable field, and click Create Destination Variable.

Name the variable AccessProDest, and click Create.

-
Under inputs, bind the input fields:
Field Value businesspartnerId Process Inputs > data > BusinessPartner communityId Process Inputs > data > YY1_SAPCommunityDisplayName firstname Process Inputs > data > FirstName lastname Process Inputs > data > LastName processInstanceId Custom Variables > instanceID status Approved -
Click Save.
-
- Step 6
-
Under the action, click the plus sign, +.

-
Click Controls and Events.

Scoll down and select Wait for an API Call.

Click Create an API Call.

-
Call the API trigger AccessProCallback, and click Create.

-
With the new step selected, open the side panel.
Select the Outputs tab, and click Configure.

-
Click Add Ouput.
Set the name to badgeId, and click Apply.

-
Click Save.
-
- Step 7
Our 3rd-party system will call back to our process instance, and send a badge number. Let’s add that to the notification form.
-
Click the 3 dots next to your notification form, and select Open Editor.

-
Add a Paragraph and set its text to:
TextCopyYour badge number is:Add a Text field. Call it Badge Number and set to read only.

Click Save.
-
Back in the process, with your form selected, open the side panel.
Under Inputs, bind the badgeId from the Wait for Badge System step to the new form field.

-
Click Save.
-
- Step 8
In order to call an SAP Build Process Automation trigger – either a standard trigger or a wait trigger – you must send an API key with adequate permissions.
-
Go to the Control Tower, and click Environments.

Select the Public environment.

-
In the API Keys tab, click Add API Key.

-
Call the key AccessProCallbackAPIKey, and click Next.

Enable the following scopes:
- trigger_read
- trigger_execute
Click Next.

On the Review page, click Add.

-
A key will be generated.
IMPORTANT: Make sure to copy and save it in a safe place.

-
- Step 9
-
Click Release.

Confirm by clicking Release.
-
Click Show project version (upper left).
This will take you to the released version of your project, so you can deploy it.

-
Click Deploy.

Select the Public environment.
Select Upgrade.
Note that it will show you that a new trigger will be created for the Wait for an API Call step.

-
Click Deploy.
You will now have a new destination to select, since you created a destination variable for the action to create a new badge request.
This is in addition to the one you selected in previous deployments for the S/4HANA backend.

Select the AccessProService destination, and make sure the S4HANA_Badges destination is selected.
-
Click Deploy.
-
After deploying, go to the Control Tower > Environments, and go to the Public environment.

Click Triggers, and you will see the trigger created for the Wait for an API Call. The trigger is called AccessProCallback.

Click View

You will see the connection details for the 3rd party system to call our process instances to resume them.
Copy the URL and put it in a safe place, where you put your API key. You will need these when we use the 3rd-party system.
IMPORTANT: Your URL will be different than the screenshot.

-
- Step 10
Things to Ponder
How did you get the process instance ID to pass to the 3rd-party system?
What other details about your process can you get this way?
What other integrations could you imagine with the “Wait for an API Call”?
What other scopes can you specify for an API key?