Skip to main content

Setting cookies

Cookies can be passed as array in cookies parameter. Remember to encode this parameter like in the examples below.

Cookies syntax

Cookies is an array of objects. "name" and "value" are required fields, other are optional. Example array with two cookies:

[{
"name": "cookie1",
"value": "cookie1value",
}, {
"name": "cookie2",
"value": "cookie2value",
"domain": "example.com",
"path": "/",
"expires": 100000,
"secure": true,
"httpOnly": false,
"sameSite": "Lax"
}]

name

Required string. Cookie's name.

value

Required string. Cookie's value.

domain

Optional string. Cookie's domain. You can either set domain and path or url. If you don't set any of the three, we use domain equal to domain of the desired url and path to /. For example, if you scrape https://example.com/some/path?arg1=value1&arg2=value2 and don't specify cookie's url, domain nor path then cookie will have domain set to example.com and path to /. See more info on MDN.

path

Optional string. Cookie's path. You can either set domain and path or url. If you don't set any of the three, we use domain equal to domain of the desired url and path to /. For example, if you scrape https://example.com/some/path?arg1=value1&arg2=value2 and don't specify cookie's url, domain nor path then cookie will have domain set to example.com and path to /. See more info on MDN.

url

Optional string. Cookie's url. You can either set domain and path or url. If you don't set any of the three, we use domain equal to domain of the desired url and path to /. For example, if you scrape https://example.com/some/path?arg1=value1&arg2=value2 and don't specify cookie's url, domain nor path then cookie will have domain set to example.com and path to /. See more info on MDN.

expires

Optional integer. Specifies cookie lifetime in Unix time in seconds. See more info about cookie's lifetime on MDN.

secure

Optional boolean. See more info on MDN.

httpOnly

Optional boolean. See more info on MDN.

sameSite

Optional. One of "Strict", "Lax", "None".

Example

The following example sets two cookies:

curl -G \
--data-urlencode 'url=https://example.com' \
--data-urlencode 'cookies=[{"name": "cookie1-name", "value": "cookie1-value"}, {"name": "cookie2-name", "value": "cookie2-value"}]' \
'https://scraping.narf.ai/api/v1/?api_key=[your api key]'