I’m just trying to authenticate with an API Endpoint which expects a fixed token to be passed as the Authorization HTTP header.
Does this look like it should work? I need to pull the token/API key from the Vault.
<arc:set attr="http.URL" value="https://api.XXXX.com/carrier/api/shipment-listing/[data.shipmentNumber]" />
<arc:set attr="http.header:Authorization" value="Bearer [Vault(My.API.Token)]"/>
<arc:set attr="http.contenttype" value="application/json"/>
<arc:call op="httpGet" in="http">
<arc:set attr="output.data" value="[http:content]" />
I’m getting a 401
Best answer by James BView original
Just out of curiosity, are you trying to pull the Bearer Token from Arc Vault?
Yes, It’s a fixed token with a long expiry (2 years for example)
I just tested this out and looks like the script is correct and it should work as it is. Since you are getting 401 Unauthorized on the URL, there can be two possible reasons:
In general, enabling the logs should give you more information on the exact issue. You can also use the _log.info item to log either the vault value or the value of http.header:authorization to the application log. This is helpful when debugging a script, to see what the value of certain attrs are at various steps in the script.
Just to add, if you can’t figure out, you can always reach out to Arc support for assistance at firstname.lastname@example.org.
Sorry, I’m struggling to get
<arc:set attr="_log.info" value="LOGGING! APIKey = [Vault(carrier.XXXX.com)]"/>
I have also tried
I assume I should be looking in the message log. Not logs.rst#application
Don’t worry I have found the logs in logs.rst#application
OKay, I can’t see any evidence that it is passing the Authroization header
is logging the expected Bearer token okay
I’m testing this with
<arc:set attr="http.header:X-Custom" value="test"/>
Auth = [http.header:*]
is reporting the headers that I set as expected.in Logs > Application
However when I use
<arc:set attr="http.verbosity" value="5"/>
<arc:set attr="http.logfile" value="D:\cData\logs\mylog.log"/>
I don’t see these headers going out
2023-05-23T13:59:13.160+01:00 2 [Request: 187] GET https://api.XXXX.com/carrier/api/shipment-listing/e0faca8c-XXXX-4a9c-ae6d-be886cf1bacb
2023-05-23T13:59:13.160+01:00 5 [Request: 187]
HTTP Auth Scheme: 0
GET /carrier/api/shipment-listing/e0faca8c-XXXX-4a9c-ae6d-be886cf1bacb HTTP/1.1
Accept-Encoding: gzip, deflate
User-Agent: CData Data Provider Engine - www.cdata.com - Accepts: gzip
2023-05-23T13:59:13.847+01:00 5 [Response: 187]
I believe that the problem here is that the arguments to the httpGet operation are different that what you are providing:
Instead of specifying the header with name as an argument to httpGet, you would provide both the name and values in a single array argument:
header:name#: The name for each custom header to pass with the request.
header:value#: The value for each custom header to pass with the request.
So this code:
Actually needs to be: