Best answer

What is the "z" variable?

  • 17 January 2023
  • 2 replies
  • 423 views

Badge +1

What is the z variable that is injected into many of the CLI-applications’ methods?  For example: https://github.com/zapier/zapier-platform-example-app-session-auth/blob/16ec7a76bcd51f9a6100cde74a31e3ca2a83c58b/authentication.js#L19.

Is there any documentation? 

In particular, I’d like to know if the z.request method supports POSTing a SSL certificate and key.

icon

Best answer by shalgrim 17 January 2023, 20:53

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

2 replies

Userlevel 6
Badge +8

Hey Benjamin,

We document the z object here. You can definitely send POST requests, but I don’t know for sure about the SSL cert and key. You might need to play around to find out.

Let us know if you have any more questions!

Badge +1

Thanks for the response and the reference.

I don’t see any request options that would allow me to provide these files.

I’m trying to do this (node):

const https = require('https')
const querystring = require('querystring')

const options = {
cert: "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n",
key: "-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----\n",
host: 'accounts.adp.com',
path: '/auth/oauth/v2/token',
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}

const requestData = {
grant_type: 'client_credentials',
client_id: 'REDACTED',
client_secret: 'REDACTED',
}

const requestBody = querystring.stringify(requestData);

const req = https.request(options, (res) => {
let response = ''

console.log('Status Code:', res.statusCode);

res.on('data', (chunk) => {
response += chunk
})
res.on('end', ()=>{
console.log('Body: ', JSON.parse(response));
})
}).on("error", (err) => {
console.error("Error: ", err.message);
});

req.write(requestBody)
req.end()

Can this be done with your z object natively?