Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
MRR_CSP
Employee
Employee
In my previous two blogs of this series, I explained how to call simple OData APIs of types GET and POST from SAP Cloud Workflow service.

In this blog, we’ll address how to call an OData API of type POST, and how to pass a JSON payload to the api. Have a look at the previous blogs to learn more - blog 1 and blog 2.

 

Pre-requisites

  • You have the URI to invoke the OData API

  • You have the credentials to authenticate the call


 

I will be using an OData API provided by SuccessFactors to add a new employee record into an SFSF system. You can refer to the following document for further information (in this case, section 14.1 in the below guide):

SAP SuccessFactors Employee Central OData API: Reference Guide

 

Disclaimer: Adding a new user into SFSF system is a procedure of multiple steps. For this blog, I will not be following them. We just will address how to call an OData API from the workflow, and how to pass a payload to it.

 



















OData URI https://apisalesdemo4.successfactors.com/odata/v2/upsert
Method Type POST
Authentication BasicAuthentication
Payload

{

  "__metadata": {

    "uri": "User(‘hgrant’)"

  },

  "username": "henrygrant",

  "status": "Active",

  "userId": "hgrant"

}

 

 

If you have reached this blog after reading the previous two blogs on this topic, you will know that the first step is to setup the destination.

Keeping true to my tradition in the past blogs, I shall be using a rudimentary workflow again to demonstrate this process.



Let’s now have a look at the Service Task ‘POST SFSF Content’ and see how we call the OData API.

The steps involved are simple and straightforward.

  • Use the appropriate destination in the Workflow’s service task

  • Provide the path to the OData API

  • Append the response from the OData API into the context of the Workflow

  • AND most importantly, pass a payload to the OData API through a request variable.


 

The destination is configured as https://apisalesdemo4.successfactors.com/

That leaves us with the path to the OData API as /odata/v2/upsert?$format=json

The parameter ‘format=json’ ensures that the response is received in JSON format, which can be consumed by the workflow.

 



























Destination SFOData
Path /odata/v2/upsert?$format=json
HTTP Method POST
Path to XSRF Token Leave this blank
Request Variable ${context.sfsf.request.payload}
Response Variable ${context.sfsf.response}

 



We now must make sure that the workflow does indeed have the necessary payload in the context, in the exact path defined for the request variable.

Since this is a very simple workflow for the sole purpose of a demonstration, I can pass it as part of the JSON context to start the workflow instance.

However, if this payload were to come from a previous service task invocation (depending on how you design your workflow), you must make sure that the response variable for that service task is the same as the request variable for this service task, i.e. context > sfsf > request > payload

 

In this case, the payload to start the process will look like this:



 

And as expected, the response will be of type JSON owing to the parameter sent in the path - format=json

 

When this workflow is executed, a new user entity will be created in the SFSF system. A success acknowledgement will be returned, which will be added into the process context in the following path – context > sfsf > response

 

For reference, the response will look like this:



There you have it. We have now addressed how to invoke an OData API through Workflow, and pass a JSON payload to it. I hope this set of articles makes it easier than it already was to do so. If anything was unclear, or missed out, feel free to direct your questions here. Until then, hope you have fun working with Workflow Services on the SAP Cloud Platform. See you around… Cheers.