How to create Global variable for dynamic id?


I have issue to create global variable while sending request.

I’m sending request to add a comment in photo but every time after sending the request It creates different IDs for each comment.

So I need this IDs values in Global variables in order to put it in the next request in my collection to delete the last created comment from photo.

This is my response of the request:

    "status": "success",
    **"id": "5cc4b8bd824f6e6c5f338f2e",**
    "user": {
        "id": 178473687364,
        "username": "test username",
        "name": "Test Name",
        "photo": "https://picture/example.jpg"
    "text": "Hello World!",
    "created": "2019-04-27T20:17:01.960Z"

I need the Id which I marked bold.
And this is the code which I write in “Tests” section of the request

let jsonDataCommentId = pm.response.json();
  pm.globals.set("New generated commend id ",["id"]);

So as a result I see that the Global variable is created in “Environments” section but the value fields are empty.

See the screenshot.

Please help and suggest some solution.

Thanks in advance.

Hey @sero.barseghyan

Welcome to the community :wave:

If I understand the question correctly, to get that value from the response and set the variable, all you would need to do is drop the ["id"] part.


@dannydainton Yes, It works now, Thank you :slightly_smiling_face:

1 Like

You’re very welcome! :trophy: