Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Call API-Trigger from automation.

FabriceArmbrust
Explorer
0 Kudos

Hello,

I like to call an API-Trigger during an automation to start a workflow.

I have tested the trigger with https://api.sap.com/api/SPA_Workflow_Runtime/tryout and got a positive result:

Unfortunately I am not able to call the trigger from the automation.

I tried it with the js-code-snippet from https://api.sap.com/api/SPA_Workflow_Runtime/tryout, but this just gives me the error:

var data = JSON.stringify({
  "definitionId": "eu10.hh8fmvfy8w5fn4lj.supplyon2.kundenauftragAnlegen",
  "context": {
    "kundenauftrag": ""
  }
});

var xhr = new XMLHttpRequest();
xhr.withCredentials = false;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    console.log(this.responseText);
  }
});

//setting request method
//API endpoint for API sandbox 
xhr.open("POST", "https://spa-api-gateway-bpi-eu-prod.cfapps.eu10.hana.ondemand.com/public/workflow/rest/v1/workflow-instances");


//adding request headers
xhr.setRequestHeader("Accept-Language", "Provide a preferred language. If a translation is available, relevant texts are returned in this language.");
xhr.setRequestHeader("Authorization", "Bearer eyJhbGciOiJSUzI1NiIsImprdSI6Imh0dHBzOi8vaGg4Zm12Znk4dzVmbjRsai5hdXRoZW50aWNhdGlvbi5ldTEwLmhhbmEub25kZW1hbmQuY29tL3Rva2VuX2tleXMiLCJraWQiOiJkZWZhdWx0LWp3dC1rZXktLTEzMzYyNDMwMDAiLCJ0eXAiOiJKV1QiLCJqaWQiOiAiYWFUYWVMQmVtTHlRdU9YTGY4SlZ4eE0zL1NsaXBpbGxkWXVEUi9vbUxERT0ifQ.eyJqdGkiOiIzYjYxZWE0YTlmYzg0MDU5ODdiMWU5N2Y4YzdkNmZlNiIsImV4dF9hdHRyIjp7ImVuaGFuY2VyIjoiWFNVQUEiLCJzdWJhY2NvdW50aWQiOiJiMDYwYWMxZC0wZWZmLTRlNWItYjQ5YS1kMTdmOGQyZjY2ZDkiLCJ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JyT55O_w-YkfoAXA5esMOmlvVnRHl66LpG3smAJFB-J7u-6M9Q6P08aL8yGJThb6bCjmcaXDF6e4m2-_FXWfyWG851dvFzpG5rdZLgaNYdoEve_RT33Yfv1FTRut11imn0TrY_MQqLwsfHwk0l1MqYndYYJpe_QvhEu4BxzLtmmKXBkzRcS6llvLndcPuQxEJN-NKr4AzpURMB6EnbNtZ5ufqTB4ZlgTDg3AZ5GbklI_XdvQBUYlXEVLLmf0UdcAtg");
xhr.setRequestHeader("DataServiceVersion", "2.0");
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");


//sending request
xhr.send(data);

Can you help me here please? What code do I need to use?

Thanks a lot!

Fabrice Armbruster

4 REPLIES 4

Archana
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Fabrice,

Now you do not need to use Web Service and code to call SBPA process in the automation. We have introduced the new activity in automation where you can discover and directly call the process. Refer this documentation

Hope that helps,
Archana

0 Kudos

Hello Archana,

unfortunately this does not work:

Here is my process (and I saved and gave it values of corse) that doesnt work.

I am not sure, what I do wrong here.

Can you guide me please?

Thank you!

Fabrice

FabriceArmbrust
Explorer
0 Kudos

Hello Archana,

unfortunately this does not work:

Here is my process (and I saved and gave it values of corse) that doesnt work.

I am not sure, what I do wrong here.

Can you guide me please?

Thank you!

Fabrice

It´s solved now:

-> Calling the process though an automation works, but it has limitations in the testing environment. Therefore you get an error message. One solution is to make a try-catch around it and test it manually. (I hope that SAP will catch up here and provide this in a future release).

-> Also check, if there are any certificates needed, as most companies require those for security reasons. Try to test it from another device, which doesn´t have this limitations.

Thanks!

Fabrice