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

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”,
“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 :frowning:

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

1 Like

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?

1 Like

Hi @dmangin ! Welcome to the Postman Community :rocket:

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