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

1 Like

“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

1 Like