Skip to Content
0
Dec 16, 2022 at 10:03 AM

Error calling external service in CAP: Failed to build headers

486 Views

Hi, I am trying to connect to an external service inside my sap cap service. I have connected the destinations service to my cap service. I have created a destination with OAuth2ClientCredentials authentication pointing to the url and the service I want to consume and in the package.json I have defined the destination I am going to use. But when I call the destination using the code I get the following error:

image.png

The external service that I want to consume has double authentication that is to say first I need to call to a url to give me a token and with that bearer token call to the external api. Theoretically defining the OAuth2ClientCredentials should do it only with the destination but for some reason it is failing me.

I have tried to separate the authentication of the service in two parts, one to collect the token and another to make the call directly, but it does not work either.

I have also tried to make the call with the library { executeHttpRequest } of the sdk '@sap-cloud-sdk/core' but it still doesn't work.

Does anyone know how to solve this problem? Is there any other way to make an external call ?

I attach the captures here:


Package.json

image.png

Service.j

image.png


Destination:

image.png




Thanks in advance.

Attachments

image.png (43.6 kB)
image.png (43.6 kB)
image.png (15.9 kB)
image.png (63.3 kB)
image.png (31.5 kB)