HTTP client using ApiKey header Auth

Hi,

I’m trying to call a REST Api throught https protocol using the api-key auth.
If I try to call it throught a curl command it works and it response with an error in json format.

I expect to get the same error in webmethods.

I have configured a client:http invoke, where I have set an header field called “API-KEY” but when I try to execute the service I get this error :

com.wm.app.b2b.server.ServiceException: com.wm.net.NetException: [ISC.0064.9314] Authorization Required

Btw I should get the error also if I don’t set any api-key, but in webMethods I get the authorization required error.

What should I do to fix the error?

Thanks in advance

Hello,
Authorisation errors are treated as exceptions in webMethods flow. The exception is showing that the error is the same. You need to wrap your call in a try catch if you want to trap this error.

If you are using the API Gateway to enforce your authorisation policy then you need to set the header key as
‘x-Gateway-APIKey’

You will then get a 200 response.

regards
John
Product Manager
Integration & Microservice Runtime

Hi Jhon,

this is my client:http pipeline where I have set the header API-KEY

and this is the error which I get from the catch block

It seems all correct but I can’t get the right error in json format from the ws

Thanks

How do you mean the right format?
Your service has terminated and trapped the error which is represented by lastError.

Do you want your service to propagate an error to an external caller of your service is that it?

In which case you can simple call the following services in your catch block

pub.flow:setResponse2 - Provide an error message formatted as you wish
pub.flow:setResponseCode - Set the response code to any 4xx that you want.

If you want to pass the existing error, you can simply remove the try/catch and the http exception will get propagated as is.

regards
John.