Skip to main content

Hello,

 

I'm not a confirmed Zapier user, so please bear with me.

And sorry for my English, I use a translator for ease.

 

I'm trying to use an API to fetch data automatically using WEBHOOKS.

It looks like the POST authentication mode is session auth.

The POST response just gives a single line of text (username connected).

But I noticed that there is a hidden Header in this answer, which contains a Cookie (JSESSIONID) that I need for the following steps, since I have to use this value (sort of TOKEN) for each of my following requests (GET).


How would it be possible to access this JSESSIONID from the first step (POST) to configure the second step (GET) and the following ones ?

 

The problem is that in the POST response, I see nothing but the small line of text (because the response header information is hidden).

 

I don’t know if this is clear, but It would really help me if someone could be able to explain to me how to do that.

 

 

I had already done some research and found two topics that seemed to be similar to my question :

 

But unfortunately I don’t understand these answers… :-(

 

Thank you in advance for your help.

 

Best Regards,

 

Romain

Hi @RomainH 

 

Welcome to Zapier! 

 

As the second thread mentioned, you need to use Code by Zapier to get the required data since webhooks wont return except the body. 
 


So after your webhook action, use the mentioned code to get the data from the header. 
 

Does that make sense?


Hello @MohSwellam,

Thank you for your quick answer.

 

Unfortunately I tried, but can’t make it work 😰

 

Here are some screenshots that explain what I intend to do.

 

 

First of all, my WebHook POST to connect to the API (Session Authentification).

It works perfectly fine, but the body response is only a simple text : “User connected”

 

 

To understand better what is happening in this step, I’ve been using POSTMAN to explore this POST step.

Here is what I get :

 

It clearly shows that there is an automatic Cookie (JSESSIONID) that is hidden in ZAPIER.

And I would like to access this Cookie to automatically put it in my next steps (GET) in ZAPIER.

 

Here is another capture of the headers of the answer :

 

 

With all these informations, would you be able to show me exactly what to do to automatically put the Cookie Value (JSESSIONID) from the POST authentification in my “WebHooks GET steps” please ?

 

Here is where I am with my ZAP.

 

As I’m really new on ZAPIER, and a novice in code, don’t hesitate to give a lot of details 😅

 

Thank you so much for your help.

Have a good day.

Romain


Hi @RomainH 

 

You seem to be already there :) 

 

You just need to add the values 

 

 'username': USERNAME VALUE,
'password': PASSWORD VALUE,
'apiKey': API KEY VALUE,
'timestamp': TIMESTAMP VALUE

You might need the TimeStamp value IF it is required, if not then you can just ignore it. (remove the line and not forget to remove the comma after API Key Value)

You need to add those values as actual inputs using your username and password, etc. 

 

Also where it says URL

let response = await fetch(URL, {

 you need to input the Webhook URL here 

 

P.S.: I have zero coding experience :D 


Ok thank you, it gives me hope 😂

 

Here is what I do with my values :

 

 

And the error I get

 

 


2 things I see here (again, not an expert in JavaScript)

 

  1. You did not pass the API value (is it not required? Do you get the response from the Webhooks with the hidden cookie without passing the API Key?)
  2. You have an extra comma after password 

I don’t know about the API value.

I don’t see it in POSTMAN, and even less in ZAPIER.

 

The comma was in the initial code :


let response = await fetch(URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
'username': USERNAME VALUE,
'password': PASSWORD VALUE,
'apiKey': API KEY VALUE,
'timestamp': TIMESTAMP VALUE
})
});

let headers = await response.headers;

return headers

 

So I didn’t remove them (commas).

 

Also, I don’t know if I put my URL correctly at the right place..?


The comma means there is still a value, this is why it’s after all values except timestamp. So since you removed API Key and Time Stamp, you should also remove the comma. 

 

And yes you are right, the URL is in the wrong place, it should replace the word URL in the code. So your code becomes

 

 

let response = await fetch(Your URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
'username': USERNAME VALUE,
'password': PASSWORD VALUE
})
});

let headers = await response.headers;

return headers

Sorry, I have been in a meeting for 1 hour.

 

Thank you for the info of the “comma information”. 

This is the kind of tips/explications that really helps me.

 

 

I applied the correction to my code, but I’m still getting an error :

Failed to create a run javascript in Code by Zapier
SyntaxError: missing ) after argument list

 

It seems that I’m getting close, but I don’t see this “missing bracket”.

 

Do you see something ?


Hi @RomainH 

 

I have played around with it and the only explanation I see is there is a SPACE in the username or the password, are they not connected characters? 

 

Maybe try to input the login and password using the Input Data above? 


Unfortunately it doesn’t work.

There is no SPACE in login and password.

 

And I tried to input the login and password using the Input Data above, but it didn’t work :-(


Hi @RomainH 

 

In this case, let me know which API you are trying to use. There might be something wrong with the request. You can also share the screenshot for the request in Postman. Just wanna make sure you are adding the correct parameters. 


Hi @RomainH 

You need to wrap all users inserted values in double quotes (“”). So where you have https:// it needs to be “https://….”. You need to do the same for the username and password values


Hi @RomainH 

You need to wrap all users inserted values in double quotes (“”). So where you have https:// it needs to be “https://….”. You need to do the same for the username and password values

 

Thank you a lot, it worked !

By putting my “values” (URL, Login, Password) in “double quotes”, I have been able to get the headers informations in the responses.

 

Again, big thanks !