Passing Basic Auth and API Key to a chained Proxy

cboyd
Participant II

Hi All,

I have chained a local Apigee API to another and I am getting a 401 error

{
    "fault": {
        "faultstring": "Execution of ServiceCallout ServiceCalloutSKU failed. Reason: ResponseCode 401 is treated as error",
        "detail": {
            "errorcode": "steps.servicecallout.ExecutionFailed"
        }
    }
}

Am I right in thinking this is an authentication error?

Both of these APIs use the same Basic Authentication and API keys....so I am not sure why this error is happening.

Here is my Service Callout:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="ServiceCalloutSKU">
    <DisplayName>ServiceCalloutSKU</DisplayName>
    <Properties/>
    <Request clearPayload="true" variable="myRequest">
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
        <Set>
            <QueryParams>
                <QueryParam name="sku">{apigee.request_prod_sku}</QueryParam>
            </QueryParams>
        </Set>
    </Request>
    <Response>calloutResponse</Response>
    <LocalTargetConnection>
        <APIProxy>ProductSKU</APIProxy>
        <ProxyEndpoint>default</ProxyEndpoint>
    </LocalTargetConnection>
</ServiceCallout>

Any thoughts?

Thanks.

Solved Solved
0 5 829
1 ACCEPTED SOLUTION

sidd-harth
Participant V

If the local API Proxy is using same Basic Authentication and API keys, then those should also be Set in Service callout policy before calling the local api.

Use same Set to set headers and api key.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="ServiceCalloutSKU">
    <DisplayName>ServiceCalloutSKU</DisplayName>
    <Properties/>
    <Request clearPayload="true" variable="myRequest">
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
        <Set>
	     <Headers>
		<Header name="Authorization">request.header.Authorization</Header>
	     </Headers>
            <QueryParams>
                <QueryParam name="sku">{apigee.request_prod_sku}</QueryParam>
		<QueryParam name="apikey">request.queryparam.apikey</QueryParam>
            </QueryParams>
        </Set>
    </Request>
    <Response>calloutResponse</Response>
    <LocalTargetConnection>
        <APIProxy>ProductSKU</APIProxy>
        <ProxyEndpoint>default</ProxyEndpoint>
    </LocalTargetConnection>
</ServiceCallout>

View solution in original post

5 REPLIES 5

sidd-harth
Participant V

If the local API Proxy is using same Basic Authentication and API keys, then those should also be Set in Service callout policy before calling the local api.

Use same Set to set headers and api key.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="ServiceCalloutSKU">
    <DisplayName>ServiceCalloutSKU</DisplayName>
    <Properties/>
    <Request clearPayload="true" variable="myRequest">
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
        <Set>
	     <Headers>
		<Header name="Authorization">request.header.Authorization</Header>
	     </Headers>
            <QueryParams>
                <QueryParam name="sku">{apigee.request_prod_sku}</QueryParam>
		<QueryParam name="apikey">request.queryparam.apikey</QueryParam>
            </QueryParams>
        </Set>
    </Request>
    <Response>calloutResponse</Response>
    <LocalTargetConnection>
        <APIProxy>ProductSKU</APIProxy>
        <ProxyEndpoint>default</ProxyEndpoint>
    </LocalTargetConnection>
</ServiceCallout>

Hi @Siddharth Barahalikar, thanks again for the helpful reply.

So I did as you suggested and that got me further, but now I am getting the following error:

Error 401: Full authentication is required to access this resource

The service call out looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="ServiceCalloutSKU">
    <DisplayName>ServiceCalloutSKU</DisplayName>
    <Properties/>
    <Request clearPayload="true" variable="myRequest">
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
        <Set>
            <Headers>
                <Header name="Authorization">request.header.Authorization</Header>
                <Header name="apikey">{apigee.client_id}</Header>
            </Headers>
            <QueryParams>
                <QueryParam name="sku">{apigee.request_prod_sku}</QueryParam>
            </QueryParams>
        </Set>
    </Request>
    <Response>calloutResponse</Response>
    <LocalTargetConnection>
        <APIProxy>ProductSKU</APIProxy>
        <ProxyEndpoint>default</ProxyEndpoint>
    </LocalTargetConnection>
</ServiceCallout>

My api key is part of the header, thus that is where I placed it for this code.

Any ideas on this error?

Again, thanks for your time thus far. You have been tremendously helpful to this n00b.

🙂

I figured it out! I needed the curly braces around the request.header.Authorization

Thanks again!

Sorry, I forgot to add the braces. It is a flow variable so we need to add braces, or else it is going to take it as String value.

No worries! You got me 99% of the way there. It is good for me to work a little at this.

🙂

Thanks again for your help!