cancel
Showing results for 
Search instead for 
Did you mean: 

CAP with external API service

JérémyChabert
Participant

Hello SAP community,

I have a question to submit.

We are using CAP to reach an API from ApiManagement hosted on Neo.

Our model is defined in package.json as follow
"cds":{    
    "requires : {            
        "orders": {          
             "kind": "odata",          
             "model": "srv/external/OrdersMetadata.json",          
             "credentials": {
                 "APIKey": <API_KEY> <--- we tried here
                 "requestTimeout": 10000,            
                 "destination": "dest_orders"          
             },          
             "pool": {            
                    "min": 1,            
                    "max": 10          
             }       
        }    
    }
}
We tried while working locally for now to provide the credentials (APIKey) in destination defined in a default-env.jsonfile
{
            "name": "dest_orders",
            "url": "https://<API_MANAGEMENT_DEST>/v0/orderTracking",
            "headers": {
                "APIKey": <API_KEY> <--- and we tried here
            }
}

but so far we are getting a 401 unauthorized and this error :
{  fault: 
    {    
        faultstring: 'Failed to resolve API Key variable request.header.APIKey',    
        detail: { errorcode: 'steps.oauth.v2.FailedToResolveAPIKey' }  
     }
}
So our guess is that APIKey is not forwarded with the request but we cannot find how to send the APIKey with the request.
We have tried to set req._.req.headers in an before handler on our service but it didn't consider it.
Do you have any suggestions ?
View Entire Topic

Hi,

setting headers is supported with the next release (approximately end of August). Please check the documentation here:
https://github.wdf.sap.corp/pages/cap/node.js/api#srv-emit

const tx = service.transaction()
const resultUsingHeaders = await tx.emit({ query: SELECT.from('Entity'), headers: { header1: 'content' } })

Best regards

Samuel

gregorw
Active Contributor
0 Kudos

Hi Samuel,

please be aware that this is an external forum and the external link is:

https://cap.cloud.sap/docs/node.js/api#srv-emit

Best regards
Gregor

JérémyChabert
Participant
0 Kudos

Hi Samuel, thanks for the tip !

Best regards,

Jérémy