Scripting API

relay.cookies

The cookies the response set.

Declaration

relay.cookies: PropertyList

Overview

Post-response scripts only. relay.cookies lists the cookies in the response's Set-Cookie headers, by name. It's the same list as relay.response.cookies, and it's read-only. In a pre-request script, it's empty.

test("Sets a session cookie", () => {
  expect(relay.cookies.has("session")).toBe(true);
});

relay.environment.set("sessionId", relay.cookies.get("session"));

Unless cookies are turned off for the workspace, Relay adds the cookies a response sets to the workspace's cookie jar and sends them with later requests, so you don't need a script to carry a session from one request to the next.

Topics

Reading cookies

get(name)

relay.cookies.get(name: string): string | undefined

Returns the value of the cookie called name.

has(name)

relay.cookies.has(name: string): boolean

Returns whether there's a cookie called name.

one(name)

relay.cookies.one(name: string): { key: string, value: string } | undefined

Returns the cookie called name as an entry whose key is the cookie's name.

toObject()

relay.cookies.toObject(): object

Returns the cookies as an object of names and values.

all()

relay.cookies.all(): { key: string, value: string }[]

Returns every cookie as an array.

The list has the other reading and iterating methods of a PropertyList, such as count(), each(fn) and filter(fn).

Unsupported members

jar()

relay.cookies.jar()

Postman's cookie jar. Calling it throws an error. To see or change the cookies a workspace sends, choose Edit Workspaces… from the workspace menu and click Cookies.

See Also

  • Managing cookies: View, add and edit the cookies a workspace sends and receives.
  • relay.response: The response a post-response script checks, with its status, headers and body.
  • PropertyList: The list of keys and values behind headers, query parameters, form fields and cookies.