How to correlate the cookie value in headers?

Hello team,

Kindly assist me with the following.
I have recorded the UI as a HAR file and converted into k6 script. I had a cookie with dynamic data in the headers. What is the best way to correlate the cookie value in headers?

Following is the script for reference

import { sleep } from 'k6'
import http from 'k6/http'

export default function main() {
  let response

  response = http.post('url',
    '{"service_code":"","transaction_id":""}',
    {
      headers: {
        Accept: '*/*',
        'Accept-Encoding': 'gzip, deflate, br',
        'Accept-Language': 'en-US,en;q=0.9',
        Connection: 'keep-alive',
        'Content-Type': 'application/json',
        Cookie:
          '_ga=GA1.1.1918531824.1643868166; _ga_59FHH7RPJL=GS1.1.1660642190.5.0.1660642190.0; _hjSession_2746721==; _hjAbsoluteSessionInProgress=0; _hjSessionUser_2746721===; _hjIncludedInPageviewSample=1; _hjIncludedInSessionSample=0; EXPRESS_CHECKOUT=there is a DYNAMIC value here',
        Host: 'online._________',
        Origin: 'https://_______',
        Referer:
          'https://access_key=accesskey&encrypted_payload=payload',
        'Sec-Fetch-Dest': 'empty',
        'Sec-Fetch-Mode': 'cors',
        'Sec-Fetch-Site': 'same-origin',
        'User-Agent':
          'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
        'sec-ch-ua': '"Not?A_Brand";v="8", "Chromium";v="108", "Google Chrome";v="108"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Windows"',
      },
    })
sleep(1)
}

Hi @Niveditha

k6 handles cookies automatically by default. If you did not need more control over cookies you could probably skip that part.

For more control on cookies you can have a look at the Cookies example in the docs. CookieJar can help you with Cookies if you need finer control.

Let me know if that helps, or if we can provide more concrete guidance on the topic.

Cheers!