cancel
Showing results for 
Search instead for 
Did you mean: 

Need advice to make a GET authentication API work in iRPA

Ludovic_MOOS
Participant
0 Kudos
327

Hi,

I would like to know if you could give me a quick hand regarding a pretty straight-forward API call that I have been trying to make in an automation in iRPA for a couple of days now. The problematic API is API 1 (API 2 is working like a charm in iRPA), see details as below.

The authentication process consists in calling two APIs consecutively:

  1. API 1: method GET, no parameter, returns a token named XSRF-TOKEN within the response cookie that I need to retrieve in order to use it in:

  2. API 2: method POST, header authorization encoded in base 64 with username and password, X-Xsrf-Token retrieved in API 1. Returns a bearer in response header.

API 1 is working in Postman but somehow I can't make it function in iRPA.

These are some of my attempts (code as part of a custom script), some of them might be awkward (sorry):

a.

 

return {
method: 'GET',
url:'https://sandbox.entreprises.xxxx.gouv.fr/api/init',
responseType: 'json',
resolveBodyOnly: false
headers:{
}
};

 

=> Response code 500 (Internal Servor Error)

b. (N.B.: that one was recommended by SAP Web services Best Practices, see screenshot below)

 

return {
method: 'GET',
url: 'https://sandbox.entreprises.xxxx.gouv.fr/api/init' ,
responseType:'json',
resolveBodyOnly: false
};

 

2024-10-25 11_20_04-Web services Best Practices - SAP Intelligent Robotic Process Automation Cloud S.png

=> Response code 500 (Internal Servor Error)

c. (this is the one I use for API 2, which is working, thought I would try the same for API 1)

 

const options = {
resolveBodyOnly : false,
responseType: 'json',
url: 'https://sandbox.entreprises.xxxx.gouv.fr/api/init',
method: 'GET',
headers: {
'Accept' : 'application/json',
'Content-Type': 'application/json',
}
};

const response = await irpa_core.request.call(options);
return response.headers;

 

=> Response code 500 (Internal Servor Error)

d.

 

async function fetchToken () {
const options = {
resolveBodyOnly : true,
responseType: 'json',
url: 'https://sandbox.entreprises.xxxx.gouv.fr/api/init',
method: 'GET',
headers: {
'Accept' : 'application/json',
'Content-Type': 'application/json',
'XSRF-TOKEN': 'fetch'
}
};
const response = await irpa_core.request.call(options);
return response;

 

=> Response code 500 (Internal Servor Error)

It is not the first time I handle API calls in SAP iRPA, and it always succeeded even with more complex ones. The irony of this being that I managed to make the API 2 work in iRPA.

Automation in itself is also quite simple: custom script (with no input) => call web service => create variable. See here:

2024-10-25 11_28_56-__ Amendes __ Programme de désignation automatique des ACO avec API - SAP Intell.png

Note that I already read detailed blogs, tutorials and videos (for which I am very grateful) before contacting you. I’m kind of disarmed in front of something that should supposedly be simple to run…

Would you have any clue how to make this work please?

Thanks beforehand for your time and I’m looking forward to reading you.

Kind regards,

LM.

View Entire Topic
Sankara1
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Ludovic, 

Thanks for confirmation.