Best answer

Zapier CLI testing

  • 5 September 2020
  • 2 replies

Userlevel 2


I am new to Zapier and try to make a Zapier CLI integration work.

I have created an integration with Zapier UI, converted it with zapier convert, and I can successfully “zappier push” it back.

However I have issues when doing “zapier test”:

  • I receive a 401 error from my server when each unit test is run
  • In fact, it is normal, because the unit test passes “Authorization: Bearer {{bundle.authData.access_token}}” litterally, without replacing the access_token with its actual value
  • And the session authentication (which should return an access_token from the email/password) is not even called from the tests.

So I have 2 questions:

  • how to manage the tests so that it uses a valid access_token?
  • how to make sure that {{bundle.authData.access_token}} is replaced with its value?

These are probably dummy questions, but I could not find any answer in the documentation. 

Many thanks!


Best answer by bfredo123 5 September 2020, 22:20

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 7
Badge +12

Hi @bfredo123 - Just use normal ES6 string interpolation because the double curly braces string interpolation won’t work inside functions. In your case, it should look like the following:



  headers: {

    Authorization: `Bearer ${bundle.authData.access_token}`



Also, in your unit tests, the authentication won’t happen automatically, you should actually define the access_token in your bundle.authData. You can use this example as a reference.


Userlevel 2

Many thanks, it works!

What I did into more details, if it may help others:

  1. I created a 0_auth folder in the test folder (‘0’ to make sure it’s invoked at first, with alphabetical order).
  1. In this folder, I do like the provided example, in a ‘testAuth.js’ test module, and I store the access_token received from the server in a variable exported by this test module (in the example, the ‘secret’ token does not work in my case, as the server returns a token which I cannot control on the client side)
  1. In any other test, I set the bundle.authData.access_token to this testAuth.access_token 
  2. Actually, leaving the simple quotes as ‘Bearer {{bundle.authData.access_token}}’ does the job (otherwise, I guss that the headers would be initialized at the test startup, even before the access_token has been retrieved from the server

Thanks again, I was really wondering how to properly organize my test bench.