Passing Cookies HTTP header to the API GET request


#1

Hi,
I’m testing the API sending direct API requests(without using the browser).

In order to authenticate, I have to add the http header Cookie value with LoginToken that changes at every request.

I tried to set a GlobalVariable.gl_Cookies with the cookie value, but not sure how I can pass this value to the Web service Request Object so that WS.verifyResponseStatusCode(response, 200) passes.

There is an option in Katalon to set the http header Cookie manually via the Object Repository, but I want this process to run automatically.

Is it possible in Katalon?


#2

Hi Lily,

this article may be helpful for you - https://www.katalon.com/resources-center/tutorials/create-rest-api-requests-manually/


#3

Hi Marek,

Thank you for a prompt response,

Indeed this article was helpful. However, it seems that a single function which would have dealt with the cookie would have saved me the requirement to manually create an API request and its verification functions.
Is there any other alternative just for setting the http cookie header function?


#4

Just to make sure - you have WS object in Object repository and you want to put there Cookies header dynamically on test run, right?


#5

I currently have an Object similar to the SampleRequestObject from the article you sent so I can set the http cookie header dynamically, and wanted to use verifyResponseStatusCode() or verifyElementPropertyValue functions.


#6

If you follow my article and you want to add a new header, just add a new line:

TestObjectProperty header4 = new TestObjectProperty("Cookie", ConditionType.EQUALS, "anyCookieHere")

Then, you can fire a request with Cookie in HTTP header.


#7

This is what I eventually did and it worked.
Thank you.


#8

A way for a newby like me does this is that I
1. Login to my website with my credentials and get the cookie.
2. Create a Global variable for the cookie.
3. Create a Web Service Object.
4. Click the Variables tab and create a variable which is bound to the global variable, like so:
5. Click the Http Header tab and add a cookie under the Http Header tab, like so:

variable.png

cookie.png


#9

Hello.
It’s not working for me … :frowning:
Is there another way to pass cookies in get request ?
Tks :slight_smile:


#10

Hi,

The above process Which Kathy had suggested is working.

  1. 1st request get a cookie value
  2. Assign to a Global Variable(Cookie)
  3. In 2nd request. Create a local variable and refer to a Global Variable(Refer above Kathy image)
  4. In HTTP Header, select Authorization in value column select ${Cookie}

#11

Hi,

I have a problem the same.
Ex : When cookies: PHPSESSID: 121213123

How to enter the PHPSESSID cookie into katalon.?

Thank you.