knwpsk
knwpsk

Reputation: 31

How do I set two cookies in headers using URLFetchApp

Working with an old SOAP api. When I login, it returns two cookies. Both cookies must be included in the headers of subsequent api calls. I can't figure out how to set two cookies in URLFetchApp.
Any help?

Here's what I have so far (typical):

tempHeader = {'Cookie':myCookieString1};
tempParameters = {"method":"GET", "headers":tempHeader}; 

(etc, I skipped irrelevant stuff)

tempResponse = UrlFetchApp.fetch(targetURL, tempParameters);

Since tempHeader is an object, I can't add two "Cookie" properties with the same name. I tried variations of giving it an array of objects, etc, but none of that worked.

Upvotes: 1

Views: 527

Answers (1)

knwpsk
knwpsk

Reputation: 31

Thanks to TheMaster who gave me the right answer.

var tempHeader = {'Cookie':'JSESSIONID=ABC123; NSC_stuff=test; '}
// this represents the *two* cookies I need to send, separated by semicolon, and ended by a semicolon and a space.

tempParameters = {"method":"GET", "headers":tempHeader}; 
myResult = UrlFetchApp.fetch(targetURL, tempParameters);

Upvotes: 2

Related Questions