# Struggling to pass a POST result in a variable - Help!

**URL:** <https://community.postman.com/t/struggling-to-pass-a-post-result-in-a-variable-help/24968>\
**Category:** Help Hub\
**Created:** [June 17, 2021, 4:37pm UTC](https://community.postman.com/t/struggling-to-pass-a-post-result-in-a-variable-help/24968 "2021-06-17T16:37:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dmangin](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@dmangin](https://community.postman.com/u/dmangin)\
**Post date:** [June 17, 2021, 4:37pm UTC](https://community.postman.com/t/struggling-to-pass-a-post-result-in-a-variable-help/24968/1 "2021-06-17T16:37:08Z")

</div>

Hi Community!

I am struggling to set a variable from a POST result.  
In POST request #1, I create a user group called “Groupe 2”. I would like to store the record Id in a variable (“Groupe2Id”). In POST request #2, I create new users and would like to assign to them the default\_group\_id = {{Groupe2Id}}.

POST #1 result:

{  
“group”: {  
“url”: “[https://z3ntest2delphine.zendesk.com/api/v2/groups/360007949978.json](https://z3ntest2delphine.zendesk.com/api/v2/groups/360007949978.json)”,  
“id”: 360007949978,  
“name”: “Groupe 2”,  
“description”: “”,  
“default”: false,  
“deleted”: false,  
“created\_at”: “2021-06-17T16:23:57Z”,  
“updated\_at”: “2021-06-17T16:23:57Z”  
}  
}

To store my variable, I have in the Test script of POST #1 :

var response = pm.response.json();  
pm.environment.set(“Groupe2Id”, response.id);

--------\> The variable is well created, but the value is null ☹

I precise that :

- I have created an environment and my requests are in a collection.
- I have searched during many hours in documentation + this forum (I precise that I am a new / not a coder).

Can you please help me? Where am I wrong?  
Thanks a lot

 ![Screenshot 2021-06-17 at 18.39.22](https://us1.discourse-cdn.com/getpostman/original/3X/4/b/4b68c0f67accb6fedeca3a0ad783e8c9e4c48260.png)

---

<div class="post-metadata">

**Author:** ![dmangin](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@dmangin](https://community.postman.com/u/dmangin)\
**Post date:** [June 17, 2021, 4:56pm UTC](https://community.postman.com/t/struggling-to-pass-a-post-result-in-a-variable-help/24968/2 "2021-06-17T16:56:46Z")

</div>

Hey! I think I (FINALLY) found my error! It works with  
var response = pm.response.json();  
pm.environment.set(“Groupe2Id”, response.group.id);

And I found also my error on GET. It works with  
var response = pm.response.json();  
pm.environment.set(“2Groupe2Id”, response.results[0].id);

Can you confirm that it is the good way?

---

<div class="post-metadata">

**Author:** ![hannah.neil](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/hannah.neil/32/4477_2.png) [@hannah.neil](https://community.postman.com/u/hannah.neil)\
**Post date:** [June 18, 2021, 12:28am UTC](https://community.postman.com/t/struggling-to-pass-a-post-result-in-a-variable-help/24968/3 "2021-06-18T00:28:59Z")

</div>

Hi @dmangin ! Welcome to the Postman Community 🚀

If it works, it works! Congrats on finding the answer.
