Hello,
I am using the CLI to create a custom call to our REST API. I need to add a custom Authorization header value to include in the request. The calculation to define the Auth value require the URL being called along with some token data. My issue is the lack of availability of the url in the includeApiKey function where it would be needed to create the Auth header. I thought perhaps I could just create the Auth header in the test const but unfortunately the request object is not available there for me to add it. Looks like the includeApiKey fires before the test const, so not sure how I can get the url in that function. For now I am using the sample code added via the tutorial. Any suggestions how I can accomplish this? Any help appreciated.
Here’s the code snippet:
const test = (z, bundle) =>
// The request object here might work as I can just add my custom Authorization header as part of the outbound call here.
z.request({ url: 'https://auth-json-server.zapier-staging.com/me' });
const includeApiKey = (request, z, bundle) => {
// The url here would be ideal as I can generate the Authorization header using standard functionality, but this is called prior to the test const above, so it's not yet available here.
if (bundle.authData.apiKey) {
// Use these lines to include the API key in the querystring
//request.params = request.params || {};
//request.params.api_key = bundle.authData.apiKey;
// If you want to include the API key in the header instead, uncomment this:
request.headers.Authorization = bundle.authData.apiKey;
}
return request;
};