<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/postman-s-pre-request-scripts-how-to-perform-http-post-requests-with-json-body-and-how-to-set-coo-qyu1gsak7" -->

---
title: Postman's pre-request scripts: how to perform HTTP POST...
description: A practical walkthrough explains how to use Postman's pre-request scripts to automate cookie-based authentication. It covers sending a POST request with a JSON...
canonical: https://daily.dev/posts/postman-s-pre-request-scripts-how-to-perform-http-post-requests-with-json-body-and-how-to-set-coo-qyu1gsak7
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Postman's pre-request scripts: how to perform HTTP POST requests (with JSON body) and how to set Cookie authentication. | daily.dev
og:description: A practical walkthrough explains how to use Postman's pre-request scripts to automate cookie-based authentication. It covers sending a POST request with a JSON...
og:url: https://daily.dev/posts/postman-s-pre-request-scripts-how-to-perform-http-post-requests-with-json-body-and-how-to-set-coo-qyu1gsak7
og:image: https://api.daily.dev/og/posts/qyu1gsak7.png
og:image:alt: Postman's pre-request scripts: how to perform HTTP POST requests (with JSON body) and how to set Cookie authentication.
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Postman's pre-request scripts: how to perform HTTP POST requests (with JSON body) and how to set Cookie authentication.

**[Code4IT](https://daily.dev/sources/code4it)** · 7 min read · 0 upvotes · 0 comments

## Summary

A practical walkthrough explains how to use Postman's pre-request scripts to automate cookie-based authentication. It covers sending a POST request with a JSON body via pm.sendRequest, correctly setting the options.raw.language field to avoid malformed requests, and storing the resulting token as a cookie using pm.cookies.jar(). It also addresses the common 'programmatic access is denied' error by explaining how to whitelist the target domain in Postman's Cookies Domain Allowlist. A full working script is provided at the end combining all steps.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.code4it.dev/blog/postman-prerequest-script-cookie-auth>

## Questions this post answers

### How do I fix the error 'CookieStore: programmatic access to domain is denied' in Postman?

This error occurs when trying to set a cookie via a pre-request script without first whitelisting the domain. Fix it by opening any request's headers section, clicking the Cookies button, selecting Domains Allowlist, and adding the target domain to the list. Once whitelisted, Postman allows the jar.set() call to succeed from script code.

_Developers automating API auth flows can track Postman workflow fixes like this one on daily.dev._

### How do I send a POST request with a JSON body inside a Postman pre-request script?

Use pm.sendRequest() with a request object specifying method POST, the target url, and a body with mode set to raw, raw set to JSON.stringify(yourObject), and options.raw.language set to json. Omitting the options.raw.language field causes the request to be malformed, since Postman needs it to know the content type of the raw body.

_Anyone scripting authentication flows in Postman can keep tutorials like this handy on daily.dev._

### How do I store a cookie programmatically in Postman after getting an auth token?

Cookies cannot be stored as plain variables; they must be added to a cookie jar via pm.cookies.jar(), then jar.set(domain, name, value, callback). This requires the domain to be whitelisted first in the Cookies Domain Allowlist, after which the cookie becomes available to subsequent requests in the collection.

_Teams building reusable Postman collections for cookie-authenticated APIs can revisit guides like this on daily.dev._

## Similar posts on daily.dev

- [Just use cURL](https://daily.dev/posts/just-use-curl-ywjbrmgrg) · Lobsters · 1 upvotes · 0 comments
- [Postman for Business Analysts: The One Tool That Makes API Discussions Easier](https://daily.dev/posts/postman-for-business-analysts-the-one-tool-that-makes-api-discussions-easier-wfqe2kcpu) · Medium · 0 upvotes · 0 comments
- [How to Import Postman Collections and Environments into Bruno \(Script Conversion and Debugging Guide\)](https://daily.dev/posts/how-to-import-postman-collections-and-environments-into-bruno-script-conversion-and-debugging-guide-eyfejtibe) · Bruno Blog · 0 upvotes · 0 comments
- [Auth Mastery Part 2: Sessions, Cookies, and Staying Authenticated](https://daily.dev/posts/auth-mastery-part-2-sessions-cookies-and-staying-authenticated-zk5kkxcot) · InfoSec Write-ups · 0 upvotes · 0 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript), [#testing](https://daily.dev/tags/testing), [#postman](https://daily.dev/tags/postman)

[View this post on daily.dev](https://daily.dev/posts/postman-s-pre-request-scripts-how-to-perform-http-post-requests-with-json-body-and-how-to-set-coo-qyu1gsak7)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Postman's pre-request scripts: how to perform HTTP POST requests (with JSON body) and how to set Cookie authentication.","url":"https://daily.dev/posts/postman-s-pre-request-scripts-how-to-perform-http-post-requests-with-json-body-and-how-to-set-coo-qyu1gsak7","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/postman-s-pre-request-scripts-how-to-perform-http-post-requests-with-json-body-and-how-to-set-coo-qyu1gsak7"},"datePublished":"2026-10-04T13:07:08.764Z","dateModified":"2026-10-04T13:16:23.081Z","description":"A practical walkthrough explains how to use Postman's pre-request scripts to automate cookie-based authentication. It covers sending a POST request with a JSON...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e81b326995d9c77ccea9d1e20904bb91?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/e81b326995d9c77ccea9d1e20904bb91?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Code4IT","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Code4IT","logo":"https://media.daily.dev/image/upload/s--OaaG4G10--/f_auto,q_auto/v1791119049/logos/code4it?_a=BAMAMicg0","url":"https://daily.dev/sources/code4it"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/postman-s-pre-request-scripts-how-to-perform-http-post-requests-with-json-body-and-how-to-set-coo-qyu1gsak7","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"javascript,testing,postman","timeRequired":"PT7M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Code4IT","item":"https://daily.dev/sources/code4it"},{"@type":"ListItem","position":3,"name":"Postman's pre-request scripts: how to perform HTTP POST requests (with JSON body) and how to set Cookie authentication."}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/postman-s-pre-request-scripts-how-to-perform-http-post-requests-with-json-body-and-how-to-set-coo-qyu1gsak7#faq","mainEntity":[{"@type":"Question","name":"How do I fix the error 'CookieStore: programmatic access to domain is denied' in Postman?","acceptedAnswer":{"@type":"Answer","text":"This error occurs when trying to set a cookie via a pre-request script without first whitelisting the domain. Fix it by opening any request's headers section, clicking the Cookies button, selecting Domains Allowlist, and adding the target domain to the list. Once whitelisted, Postman allows the jar.set() call to succeed from script code. Developers automating API auth flows can track Postman workflow fixes like this one on daily.dev."}},{"@type":"Question","name":"How do I send a POST request with a JSON body inside a Postman pre-request script?","acceptedAnswer":{"@type":"Answer","text":"Use pm.sendRequest() with a request object specifying method POST, the target url, and a body with mode set to raw, raw set to JSON.stringify(yourObject), and options.raw.language set to json. Omitting the options.raw.language field causes the request to be malformed, since Postman needs it to know the content type of the raw body. Anyone scripting authentication flows in Postman can keep tutorials like this handy on daily.dev."}},{"@type":"Question","name":"How do I store a cookie programmatically in Postman after getting an auth token?","acceptedAnswer":{"@type":"Answer","text":"Cookies cannot be stored as plain variables; they must be added to a cookie jar via pm.cookies.jar(), then jar.set(domain, name, value, callback). This requires the domain to be whitelisted first in the Cookies Domain Allowlist, after which the cookie becomes available to subsequent requests in the collection. Teams building reusable Postman collections for cookie-authenticated APIs can revisit guides like this on daily.dev."}}]}
```

