New to postman and REST, can you help?

Hello,

I am new to postman, but I have the basics down, as far as setting up the keys, variables, and making a Call.

I’m hoping someone could guide me - if this is even possible - do I use “pre-request scripts” or set some kind of dynamic/array variables, or use ‘Runner’, or what approach exactly?

Here is what I’m trying to do:
when I make a call to one endpoint, I get a bunch of output like this
],
“approvalSchemes”: “none”,
“deniedCommentsRequired”: false,
“description”: “Role for I.T.”,
“disabled”: false,
“displayName”: “Developer Role”,
“id”: “3c918286759540f70175c7a8025x401b”,
“identityCount”: 0,
“name”: “Developer Role”,
“owner”: “services”,
“requestCommentsRequired”: false,
“requestable”: false,
“revokeRequestApprovalSchemes”: null,
“selector”: null
},
{

If I take that id value, and enter that into a different CALL like this
{{api-url}}/cc/api/role/get/?id=3c918286759540f70175c7a8025x401b

I get a bunch of output like this
“children”: [
{
“children”: ,
“key”: {
“property”: “attribute.jobTitle”,
“sourceId”: “”,
“type”: “IDENTITY”
},
“operation”: “EQUALS”,
“value”: “Developer level 2”
},

All this output… all I really want is one thing from the first call, and two from the second call.
“displayName”: “Developer Role”
“property”: “attribute.jobTitle”,
value": “Developer level 2”

But also - I have a bunch of these, is there any way to automatically put the ID from one call to the other?

Hi @codythesailpointpost,

Welcome to the community! :clap:

Your use case should be simple enough. You can save the id as a variable in a Postman Environment in a test script, and then you can use that variable in subsequent Postman Requests, and then save those two values you are looking for.

Before we get more into the details of the code, are you trying to run this in an automated fashion, where you click once, and this is done for every ID that exists, or do you want to manually control each step, where you only have to click “Send” and get the information you’re looking for.

If you’re doing completely automated, then you will want Collection Runner (or Newman). If manual, then you can do this outside of Collection Runner (or Newman).

Lastly, is there any way you are looking to save this output data? In a CSV file, or manually?

With this info set, it will be easy enough to continue. I’d also recommend searching in the
Postman Learning Center, where you can find plenty of script snippets that will assist with pulling data out of your response for testing, saving, etc.

Best,
Orest

2 Likes

“Before we get more into the details of the code, are you trying to run this in an automated fashion, where you click once, and this is done for every ID that exists, or do you want to manually control each step, where you only have to click “Send” and get the information you’re looking for.”

  • Automated would be the best, but if it’s super complicated, I understand what you mean storing each as a variable and then manually running for each different variable (the problem with that approach is… we have about 600 of these, that’s a lot of variables!)

Saving to a CSV would be great.
And I will definitely read the link you mentioned because I have no idea how to pull just the lines I want. I would probably need to find-and-replace-color-coated is the only solution I could think of.

Hi @codythesailpointpost,

It’s not super complicated at all, as the process is repetitive and shouldn’t require different logic, unless there are error cases that need to be handled.

Sounds like having 600 different IDs means automation would be better. However, you don’t have to use a new variable for a new ID every time, you can reuse the old variable. Difference now would be persisting the ID with the response you are looking for.

Sounds like Newman should do you justice. Actually, @vdespa just made a great video on how to read, and write to a CSV in a Postman test. This is semi advanced, but I find it would be a great long term goal for you, given how many IDs you have.

In the mean time, you can easily do this manually(ish) do this with the following in your Tests section of your request:
pm.environment.set("id", pm.response.json()["id"])

This should roughly get the variable you are looking for, depending on structure of the json.

Then, you can use that variable in another postman request using the following syntax:
{{api-url}}/cc/api/role/get?id={{id}}

Then you can save the output using the following syntax in your Tests script for the second request that uses the ID, similar to the above:
pm.environment.set("displayName", pm.response.json()["key"]["displayName"])
pm.environment.set("property", pm.response.json()["key"]["property"])
pm.environment.set("value", pm.response.json()["key"]["value"])

Something like this should suffice to start.

Let me know if this helps!

Orest

2 Likes

Orest, I never thanked you.
Thank you for your time!
I had a lot of learning to do, but your advice was very useful.

After implementing all your suggestions my only issue with this solution (which I honestly didn’t explain very well) was the json structure was more complicated and this recommended piece didn’t work:
pm.environment.set(“property”, pm.response.json()[“key”][“property”])

I found the structure was something more like this:
pm.environment.set(“property”, pm.response.json().selector.key.property[1].value);

I’m not very fluent with json (and hopefully it’s OK to reference outside links) I discovered this webpage where you just copy and paste the json and it spits out the exact thing to pull in the test script. Hopefully this helps someone else down the road.
https://jsonpathfinder.com/

1 Like

@codythesailpointpost you’re welcome, and thanks for sharing your ultimate solution! I’m sure this will be helpful to others in the future, especially the jsonpathfinder.com.

Glad you were able to eventually create a solution that works for you.

Best,
Orest