# Newman collection run is failing to send cookie

**URL:** <https://community.postman.com/t/newman-collection-run-is-failing-to-send-cookie/45642>\
**Category:** Help Hub\
**Tags:** newman-project\
**Created:** [March 27, 2023, 1:35pm UTC](https://community.postman.com/t/newman-collection-run-is-failing-to-send-cookie/45642 "2023-03-27T13:35:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rashusm](https://avatars.discourse-cdn.com/v4/letter/r/db5fbb/32.png) [@rashusm](https://community.postman.com/u/rashusm)\
**Post date:** [March 27, 2023, 1:35pm UTC](https://community.postman.com/t/newman-collection-run-is-failing-to-send-cookie/45642/1 "2023-03-27T13:35:41Z")

</div>

> **Archived topic — this may be out of date.**  
> Newman has been replaced by the **[Postman CLI](https://learning.postman.com/docs/postman-cli/postman-cli-overview/)**, Postman’s official, signed command-line tool. It runs collections as Newman did, and also lints API specs, runs mocks and monitors, and syncs local files with Postman from your terminal, CI/CD pipeline or coding agent.  
> Working with an AI coding agent? The [Postman plugin](https://github.com/postmanlabs/postman-plugin) lets agents in Claude Code, Cursor, Codex and others design, mock, test and ship APIs with Postman.  
> For current help, see the [Postman docs](https://learning.postman.com/docs/), try the free [Postman tools](https://www.postman.com/tools) (no account needed), or join us on [Discord](https://discord.gg/58aNNsRBGR).

I’m a beginner and trying to run postman collection in Newman using linux system. I have created collection with Post login request under Folder1, stopping the ldap server on and trying to add,update,delete user requests under Folder 2 to get “server down message” status 400

The issue is with the FOlder 2 . From Postman, I get a 200 OK by disabling cookie jar, and from Newman, the same request returns 401 Unauthorized not 400.  
Even though i added header cookie value on Folder2 requests after stopping the server.

This is how the authorization works for this API:

2 set-cookies values are obtained from the login request, specifically from the response headers, where we have 2 Set-Cookie headers with the corresponding values for the cookies.

How I’m obtaining the values and using them

In the request 1 (login) (Folder1) I have the following code in the Test tab:  
// Save cookies from response headers to use it in subsequent requests  
const cookies = pm.response.headers.all().filter(headerObj =\> headerObj.key === ‘Set-Cookie’).map(headerObj =\> headerObj.value.split(‘;’)[0]);  
pm.environment.set(‘cookies’, cookies.join('; '));

If I print the saved values I obtain something like this:

Bearer=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJkYjZlN2QzMy04OGI4LTQ3OTQtODliYy01Y2E3ZWE0ZGJlZTkiLCJleHAiOjE2Nzk5MjI2NTcsImZyZXNoIjp0cnVlLCJpYXQiOjE2Nzk5MjE3NTcsInR5cGUiOiJhY2Nlc3MiLCJuYmYiOjE2Nzk5MjE3NTcsImlkZW50aXR5Ijp7InVzZXJuYW1lIjoiYWRtaW4iLCJyb2xlIjoic3VwZXJ1c2VycyIsInJqdGkiOiI3YWY3ZmZjZi0yOGI1LTQ0YjQtOTFhYS1hMGEyODliYzRlYjMifX0.bJ5db8W5orFIWqTBUygZA8mK2y6AjFs7N8dvax\_LZVY; Refresh=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI3YWY3ZmZjZi0yOGI1LTQ0YjQtOTFhYS1hMGEyODliYzRlYjMiLCJleHAiOjE2ODI1MTM3NTcsImlhdCI6MTY3OTkyMTc1NywidHlwZSI6InJlZnJlc2giLCJuYmYiOjE2Nzk5MjE3NTcsImlkZW50aXR5Ijp7InVzZXJuYW1lIjoiYWRtaW4iLCJzZXNzaW9uVGltZW91dCI6MTUsInJvbGUiOiJzdXBlcnVzZXJzIn19.S5f0A6HC9XNe4xMo6ODKLzYyXLOoUGsDqz8sguH-10o

In the request 2 (Folder2) (Edit users) I do the following in the pre-request tab:

pm.request.headers.add({  
key: “Cookie”,  
value: pm.environment.get(“cookies”)  
});  
Note: Also tried inserting the varaibles directly in headers ex: Cookie: {{cookies}} but with the same result.

So, if I run this from Postman, this second request respond 200 and the item is created (expected response).  
When running it from Newman I get 401. Please help

Here is the new man shell script which i am running , both the folders are under “ldap-down.postman\_collection.json”  
newman run ldap-down.postman\_collection.json -e L1-70.postman\_environment.json --folder folder1 -r htmlextra -k  
systemctl stop slapd  
newman run ldap-down.postman\_collection.json -e L1-70.postman\_environment.json --folder folder2 -r htmlextra -k  
systemctl start slapd
