Skip to Content
4
Apr 08, 2020 at 11:04 AM

CAP with external API service

882 Views Last edit Apr 08, 2020 at 11:31 AM 2 rev

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 ?