Skip to main content

I am accessing an API that uses basic auth for its endpoints.  One of the challenges, however, is that the vendor requires changing the account’s password every 7 days.

To handle this, I have a Zap that makes the change, then stores the updated credentials in Zapier Storage.  The storage_secret and storage_key have been added to the authentication.js script as fields.

In my application, I need a way to retrieve these credentials before each call to the vendor’s endpoint.  To achieve this, I wrote this function:

const addAuthHeader = (request, z, bundle) => {

console.log('***** addAuthHeader *****')

const options = {
url: 'https://store.zapier.com/api/records?key={{bundle.authData.storage_key}}',
method: 'GET',
headers: {
'accept': 'application/json',
'X-Secret': bundle.authData.storage_secret
},
}

return z.request(options).then((response) => {

const results = response.json;

const username = resultsrbundle.authData.storage_key]g'Username']
const password = resultsrbundle.authData.storage_key]g'Password']

const authorization = "Basic " + Buffer.from(`${ username }:${ password }`).toString('base64')
request.headers.Authorization = authorization

return request;

});

};

In the application’s index.js file, I reference the function:

module.exports = {
version: require('./package.json').version,
platformVersion: require('zapier-platform-core').version,
authentication: authentication,
beforeRequest: RaddAuthHeader],
searches: { ... },
creates: { ... },
};

Unfortunately, when I run one of the searches, I get an error in the addAuthHeader function when it attempts to make the request:

 TypeError: z.request is not a function

 

Am I misunderstanding how the z object works in this situation?