I am developing a custom CLI app.
There is some data returning after a successful login. I want to use that data in the triggers, but unfortunately, the data is not saving to `bundle.authData` or `bundle.inputData`.
authentication.js
"use strict";
const test = async (z, bundle) => {
const config = {
method: "post",
url: "https://api.xxxxxxxxxx.com/v1/sec/login",
headers: {
cname: "mapp.xxxxxxxx.com",
"Content-Type": "application/x-www-form-urlencoded",
},
body: {
login: bundle.authData.username,
password: bundle.authData.password,
},
};
const response = await z.request(config);
const result = response.json;
if (result.errors && result.errors.length > 0) {
throw new z.errors.Error("Invalid response from the service", 400);
}
return result;
};
const includeBearerToken = (request, z, bundle) => {
z.console.log('includeBearerToken >>> ', bundle);
return request;
};
const handleBadResponses = (response, z, bundle) => {
z.console.log('handleBadResponses >>> ', bundle);
return response;
};
module.exports = {
config: {
type: "basic",
fields:
{
key: "username",
label: "Username",
required: true,
type: "string",
},
{
key: "password",
label: "Password",
required: true,
type: "password",
},
],
test,
connectionLabel: `{{bundle.authData.username}}`,
},
befores: includeBearerToken],
afters: handleBadResponses],
};
Sample data that is sent for a successful login:
{
name: 'Ministry of External Affairs (XP Division)',
login: 'meaxp',
picture: '',
gender: '',
ent_name: 'Ministry of External Affairs',
ent_mobile: xxxxxxxxxxx,
cname: 'mapp.xxxxxxx.com',
'x-api-key': 'xxxxxxxxxxxxxxxxxxxxxxxxx',
web_url: 'https://mapp.xxxxxxxxxxxxxxxx.com'
}
Actually, I want to use the `x-api-key` in future requests that I will make via triggers or searches.
This is what I got in my trigger logs. There's no sign of the data that was returned by the authentication:
{
authData: { username: 'meaxp', password: 'xxxxxxxxxx' },
inputData: {},
inputDataRaw: {},
meta: {
isLoadingSample: false,
isFillingDynamicDropdown: true,
isTestingAuth: false,
isPopulatingDedupe: false,
limit: null,
page: 0,
isBulkRead: false,
zap: {
help: :Array],
id: 'invoke:-:xxxxxxxx',
link: 'https://zapier.com/app/editor/invoke:-:xxxxxxx',
live: true,
name: 'A Zap',
user: :Object],
trigger: :Object],
action: :Object]
}
}
}
Thank you