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: 
TJe
Product and Topic Expert
Product and Topic Expert

In this tutorial we will create a very basic Action Project for a simple REST API which will return the list of ToDos.
The goal is to cover all the steps necessary to consume Actions in a Process, not to proivde a real Process use case.

This is part of a blog series for Actions:
SAP Process Automation – Consume APIs with <no-code> using Actions.

Overview of the Steps:

    • Consumption in Process
      - Create Business Process and use an Action
      - Release and Deploy the Process
      - Test the Process which is using the Action


Create BTP Destination

In the SAP BTP Cockpit, create a destination that will be used in the Action Editor to test the Action and in the Process execution.

ParameterValue
URLhttps://jsonplaceholder.typicode.com/
Additional Propertiessap.applicationdevelopment.actions.enabled = true
 sap.processautomation.enabled = true

 


Configure Destination for SAP Process Automation

To allow the usage of the BTP destination, you have to add the Destination in SAP Process Automation.

    • In the Settings or SAP Process Automation, select Destinations
    • Click New Destination
      select the Destination from the list and press Add
    • The destination is now added to the lst and can be used in SAP Process Automation


Create Action Project

In this sample we will create a simple Action Project for a REST API.
We will not change input/output parameters or customize the action.

Important: You need an Open API specification for your API to create Actions

    • For this example, just copy the definition from here to a local text file called ToDoAPI.json and save the file. We will use the file to create the Action Project with one Action.
      { "openapi": "3.0.0",
          "info": {
              "description": "This is a fake API of todo list",
              "title": "fake.todo",
              "version": "1.0.0"
          },
          "servers": [ { "url": "https://jsonplaceholder.typicode.com/" } ],
          "paths": {
              "/todos": {
                  "get": {
                      "summary": "get list of todos",
                      "description": "get list of todos",
                      "operationId": "get.todos",
                      "responses": {
                          "200": {
                              "description": "Successful response",
                              "content": { 
                                  "application/json": {
                                      "schema": {
         				        "type": "object",
      					"title": "Collection of Tasks",
      					"properties": {
      					        "responseArray": {
      							"type": "array",
      							"required": true,
      							"items": {
      								"properties": {
      									"userId": { "type": "number" },
      									"id": { "type": "number" },
      									"title": { "type": "string" },
      									"completed": { "type": "boolean" }
      } } } } } } } } } } } } }
    • In the Lobby of SAP Process Automation, create an Action Project.
    • Specify the name ToDo Actions and upload the API spec ToDoAPI.json, click Create
    • Select the actions from the list, click Add
    • Your Action Project will contain one action


Test an Action

You can test the execution of your action in the Action Editor. Lets test the Action 'get list of todos'.

    • Select 'get list of todos' from the list, the action has no input parameters
    • Select Tab Output, shows the fields returned when the action is executed

    • Select Tab Test, you can see the different options available to test an action.
      Connectivity Host allows you to test with an destination or Manual, you can enter the system details here.
    • Select the destination Demo, click Test
      The Response Preview will show the results


Release and Publish to Library

To be able to use the Action in a Process, we have to release and publish the Action Project.

    • Click Release

 

    • Provide release information, click Release
    • Click Publish to Library
    • On Publish Project, click Publish


Consumption in Process

Create Business Process and use an Action

 

    • From the Lobby select Create Process
    • Enter the Project Name, e.g. Demo Process and select Create
    • On the Create Process Dialog, enter the Process Name myActionProcess and select Create
      your canvas should look like here
    • Select the + to add a step to your process
    • Select Browse library, you will see all actions
      here I have used a filter to show only Actions from ToDo Actions project
    • Lets use 'get list of todos' action, click Add
    • As a last step we have to define a Destination variable
      This variable will be later used in the Execution to assign a destination created in BTP and configured in SAP Process Automation
    • Select Create Destination Variable, set system as Identifier and select Create
    • An Environment variable was created and your process should not display an error anymore
    • Now Save your process


Release and Deploy the Process

To test the action in the process, we will release and deploy the project.

    • clik Release
    • Enter a Version comment, click Release
    • click Deploy
    • On the Deploy a project dialog, select the Destination Demo, click Confirm
    • The Deploy button gets activated, click Deploy
    • Your project is deployed and the deployed version is shown

 

Test the Process which is using the Action

 

    • In the Monitor or SAP Process Automation, select Manage --> Process and Workflow Definitions
      you can use filter myActionProcess
    • select the myActionProcess from the list, click Start New Instance
    • On the Start New Instance you can specify input parameters, we have no input so we can use {}, click Start New Instance and Close
    • The instance will be started
    • Select Monitor -> Process and Workflow Instances
    • Reset the Filters to show all instances
    • in the Search, enter myActionProcess
    • Select myActionProcess from the list to show the instance results


Consumption in Automation

coming soon
...


Conclusion

Following this tutorial, you have seen all the steps to consume an Action in a process.

48 Comments
sven_diedrich
Employee
Employee
0 Kudos
Does this require an running Agent or is the caller SPA itself?
piyushgupta
Explorer
0 Kudos

Really informative article thomas.jentsch

Is it safe to say that Action Project is used to call APIs only?

If that is the case then isn't there an option to call APIs from activities in Automation?

 

TJe
Product and Topic Expert
Product and Topic Expert
0 Kudos
Testing Actions in the Action Editor or execution within a process does not require an running Agent.
Execution within in automation requires an running Agent.
TJe
Product and Topic Expert
Product and Topic Expert
Yes, Action Project is used currently for REST APIs.
And yes, you can use this also in automations.

  • there are Web Service activitities for automations (independent from Action Project)

  • Actions can be used in automations as well
    you need to add the Action Project as a dependency to your SPA project and after that step you can use the actions in your automations.
    (using an action in processes, the dependency is added automatically for automations this is a manual step)


Will add the consumption in automations to this blog asap.
Bram
Explorer
0 Kudos
Hi Thomas,

I followed your guide but I do not get automatically output fields.

What am I doing wrong?


Thanks.
TJe
Product and Topic Expert
Product and Topic Expert
0 Kudos
Just tested on my trial and works fine. Seems to be an issue in the ToDoAPI.jsoncan you please check the file and may be create just a new one.
Bram
Explorer
0 Kudos
Hi Thomas,

I've checked the file, and try it again, with the same result: no output fields.

Also when I am trying the blog of Archana Shukla (business partner api - json) (https://blogs.sap.com/2022/10/21/connect-to-external-systems-using-actions-in-sap-process-automation/) I get also no input and output fields.

Has this something to do with our BTP account. I am not using a trial account but a full BTP account.

Thanks.

Kr,

Bram
vbalko-claimate
Active Participant
Hello thomas.jentsch ,

 

thank you for very nice morning blogpost. It is always very pleasant to start a day with such small and interesting article which will push your knowledge a little bit further.

But... Everything went fine until I tried to test call the api. I am receiving the error - see below.



I also tried to add dummy parameter to query and path, tried to do test with manual url instead of destination, but with same result.

Maybe it is some temporary problem on SAP side?

 


Error on test


 

Also, the lobby and UI of BUILD (SPA) has changed due to recent TechED, but most of screenshots are up to date.

 

Good work - thanks

 

Vlado
TJe
Product and Topic Expert
Product and Topic Expert
Could reproduce the issue, should be fixed very soon.
janschober
Participant
Thanks thomas.jentsch  for this excellent blog. Awesome and comprehensive summary!
0 Kudos
HI Thomas,

I am also facing the same issue when try this blog,

when can I expect the fix for the issue?

 

Thanks,

Venkata Sai
TJe
Product and Topic Expert
Product and Topic Expert
0 Kudos
Tested and it is fixed.
TJe
Product and Topic Expert
Product and Topic Expert
0 Kudos
Updated the openAPI spec, so the action can be used in another tutorial I'm currently working on.
(the output parameter must be defined as required)
Girish_Kumar_Gu
Participant
0 Kudos
Hi thomas.jentsch

Thanks for the blog.

I've a question regarding an error I am getting. I've created an Action Project to expose an API from my service. The API works fine from the Action Editor. I've then published it and used in a Process Automation project.

I want this action to be called after task is approved. I can see that after approval, the API is called but it returns the below error:


I've checked the destination and it seems fine. Testing from Action Editor using the same destination works fine.

Any idea what could be the issue? Am I missing any configuration?

Thanks
TJe
Product and Topic Expert
Product and Topic Expert
0 Kudos
This is a limitation for this destination type we have in process execution today, as there is no user context (which is available in Action Editor and Forms). This will change when user principal propagation for Processes will be released (current plan is to have this in Februrary).
Girish_Kumar_Gu
Participant
0 Kudos
Thanks for the reply thomas.jentsch

Any link or channel where I can track the releases?
Girish_Kumar_Gu
Participant
0 Kudos
Hi thomas.jentsch

I have a question related to Action Project.

After creating an action project, few of the APIs have changed. Therefore I want to update the API Specification but I can't find any option to do so. There is no way to reupload the Open API spec

Is that a limitation or am I missing anything?

Thanks

Girish
TJe
Product and Topic Expert
Product and Topic Expert
You have to import the modified OpenAPI spec (JSON) again to your project.
Please be aware, that this will overwrite your manual modifications in the Action project with the definition from the spec.
Girish_Kumar_Gu
Participant
0 Kudos
I got the option. I wonder why I couldn't locate it earlier 😄

Thanks for your help!
VijayCR
Active Contributor
0 Kudos
Hi thomas.jentsch ,

Very helpful blog , just FYI i have used the https://convert.odata-openapi.net/ for the converter from ODATA to Open API and was able to consume on-premise API .

Thanks,

Vijaya
TJe
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi Vijay,

great, thank you for the information and the feedback.

regards
Thomas
Girish_Kumar_Gu
Participant
0 Kudos
Also for CAP based applications, following command works well for generating the Open API spec:

 
cds compile srv --service all -o docs --to openapi
Rajasekhar215
Explorer
0 Kudos
Hi thomas.jentsch

Thanks for the blog.

I've a question regarding an error I am getting. I've created an Action Project to expose an API from my service. The API works fine from the Action Editor. I've then published it and used in a Process Automation project.

result:

{
"data": [
{
"upsideQuantity": "100.000",
"commitUOM": "EA",
"commitEndDate": "2023-01-28",
"type": "orderForecast",
"forecastQuantity": "1000.000"

}]}

 

The action executed successfully but it's not giving me the any output data.

result:

{
"action_get_getLastUpdatedTime_2": {
"result": {}
}
}

 

Can you please help me here??

 

Thanks,
Rajasekhar
TJe
Product and Topic Expert
Product and Topic Expert
0 Kudos
Can you please check if your action has an output schema for the successful response code.
In the attached screenshot you can see the response body from the requested.
Sometimes this is missing in openAPI specs and must be manually updated to get results not only when testing the action, but also when the action is used in a process/automation.

Rajasekhar215
Explorer
0 Kudos
 

Hi thomas.jentsch ,

In action project we are getting the output PFB,



But while consuming in the process it is not giving any data in the context.



Can you please help with the issue.


Thanks,
Rajasekhar

TJe
Product and Topic Expert
Product and Topic Expert
0 Kudos

How does the definition in the Output Tab of the action look like ?
If the Body is empty, that's the issue.

destoje
Explorer
0 Kudos
Hi Thomas Jentsh,

I used the action functionality in a workflow for the creation of a product on S4. Is there a possibilty to extract the error message from S4 if the action fails for a wrong value?

 

Thanks,

Jelle
TJe
Product and Topic Expert
Product and Topic Expert
0 Kudos
The highest level of details you can get from error messages is, when you test the Action in the Action Editor. In the monitoring of your process, you can get the details in the log of the process.
destoje
Explorer
0 Kudos
So there is no possibility to use the details of an error message or the error in general within the workflow? Or some error handling within the workflow?
TJe
Product and Topic Expert
Product and Topic Expert
0 Kudos
Correct, currently there is no error / exception handling, this is planned but not ready yet.
destoje
Explorer
0 Kudos
When is this planned?
TJe
Product and Topic Expert
Product and Topic Expert
0 Kudos
No concrete date yet.
Jacky_Liu
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi, Jentsch,

Thanks for sharing!

Currently I need to use action to call a restapi with post  boday in Json and resonse body in Json .  Is there any way to generate API specification with sample request body and Sample response body ?

 

Best regards!

Jacky Liu

 

 
TJe
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi Jacky,
this is planned for the Action Editor, but not available now.
regards
Thomas
Jacky_Liu
Product and Topic Expert
Product and Topic Expert
0 Kudos
Hi, Thomas,

Thanks!

That will save a lot of time and improve efficience ! I tried with swagger to generate open api file in Java springboot and it will take some effort to write deserialize logic to transfer from Json to class object .

Best regards!

Jacky Liu
AdrDen
Explorer
0 Kudos
thomas.jentsch

we have some serious problem with our PoC in SAP Build Process Automation trial instance:

  • When adding Actions project as a dependency to automation project, an empty page shows. It seems to be really unstable as it switches on and off from time to time. At the moment we can't add it to the project.



 




We'd be grateful if you can help us.

Best regards,

Adrian
TJe
Product and Topic Expert
Product and Topic Expert
Had some problems with Browse library on my trial tenant as well, seems to be ok now.
Have replied to the question in the other discussion when your action fails.

regards
Thomas
sudarshan005
Explorer
0 Kudos
Hi thomas.jentsch ,

 

I've created a action project and trying to fetch around 500 records of data from my ODATA service but I'm unable to fetch all the data. Can you please help me with it.

 

Best Regards,

Sudarshan Pattanayak
TJe
Product and Topic Expert
Product and Topic Expert
0 Kudos
You may have to split this in smaller chunks, you may also reduce the output parameters to the needed ones only. Not sure about the use case, why you need 500 records in a process.
sudarshan005
Explorer
0 Kudos
I've a use case which required around 500 material code to be shown in a dropdown. So, if I'm able to get all the 500 material code through action then I can integrate it to SAP Build Process Automation and move forward.

 
TJe
Product and Topic Expert
Product and Topic Expert
0 Kudos
Can you please check, if this will work if you reduce the output parameters of your action.
sudarshan005
Explorer
0 Kudos
Yes, I've checked and made the $top 70 then I'm able to receive the data but is there any way through which we can fetch all the 500 material code.
TJe
Product and Topic Expert
Product and Topic Expert
0 Kudos

As mentioned, please on the output parameters of the action, delete all parameters which are not needed for your use case. You may also use the $select, to retrieve only the needed values.

sudarshan005
Explorer
0 Kudos


This is my Output Tab, can you please help me to modify any changes that can be done
TJe
Product and Topic Expert
Product and Topic Expert
0 Kudos
If you unfold the results, you should get a list of parameters, You can select parameters and remove them from the list. If you use the action in your process, the data type in your SBPA project will show only the parameters which are still defined as output parameters.
sudarshan005
Explorer
0 Kudos
I did that just now but still I'm unable to see all the material code in the Test Tab.

 
TJe
Product and Topic Expert
Product and Topic Expert
0 Kudos
Two final ideas:
use $select to retrieve only the material code
Also you should test this in a process. The Test in the Action Editor may be limited.
sudarshan005
Explorer
0 Kudos
Thank you thomas.jentsch , I will try the above method and I've another query Is it like the result in the Test in the Action Editor will be limited but when I'll implemnet the action in SAP Build Process automation it will show all the data