Dear all,
I am faced with a challenge that ma API returns 20 values per response page and I have also instances, where more results exist. The API response body contains an URL for the next result page.
The URL is stated as “”__next": “Groups(‘M1XMSeeA6kFuCScyI7mdtO’)/Memberships?%24skiptoken=1yhyr&…” at the end of the response body.
I have tried to work with postman.setNextRequest etc. but as I am a newbie have not been able to get this work.
Are there some hints how I can use the collection feature and within the Test or re-request script to make this work?
Thanks for your support!
Mathias
Can you post the whole response body, and I’m sure we can help you with the logic.
This is covered in the fifteen days of Postman training. So it will be similar to that exercise.
let currentPageNumber = pm.collectionVariables.get("pageNumber");
if (response.next != null) {
currentPageNumber++;
console.log("current page number : " + currentPageNumber);
pm.collectionVariables.set("pageNumber", currentPageNumber);
postman.setNextRequest("get starships");
}
Hi Mike,
thanks for your feedback and the proposed code.
The call I am making is
https://jam12.sapjam.com/api/v1/OData/Groups(‘M1XMSeeA6kFuCScyI7mdtO’)/Memberships
and the response is as follows:
{
"d": {
"results": [
{
"__metadata": {
"uri": "GroupMemberships(GroupId='M1XMSeeA6kFuCScyI7mdtO',MemberId='AwlNGhgE724shZvUsICssv')",
"type": "SAPJam.GroupMembership"
},
"GroupId": "M1XMSeeA6kFuCScyI7mdtO",
"MemberId": "AwlNGhgE724shZvUsICssv",
"MemberType": "admin",
"CanCancelInvite": false,
"IsFeatured": false,
"FeaturedReason": null,
"IsDynamicFollower": false,
"Member": {
"__deferred": {
"uri": "GroupMemberships(GroupId='M1XMSeeA6kFuCScyI7mdtO',MemberId='AwlNGhgE724shZvUsICssv')/Member"
}
}
},
[ .. omitted ]
{
"__metadata": {
"uri": "GroupMemberships(GroupId='M1XMSeeA6kFuCScyI7mdtO',MemberId='MKIF7wPLQ4FVVJlirI9OU3')",
"type": "SAPJam.GroupMembership"
},
"GroupId": "M1XMSeeA6kFuCScyI7mdtO",
"MemberId": "MKIF7wPLQ4FVVJlirI9OU3",
"MemberType": "member",
"CanCancelInvite": false,
"IsFeatured": false,
"FeaturedReason": null,
"IsDynamicFollower": false,
"Member": {
"__deferred": {
"uri": "GroupMemberships(GroupId='M1XMSeeA6kFuCScyI7mdtO',MemberId='MKIF7wPLQ4FVVJlirI9OU3')/Member"
}
}
}
],
"__next": "Groups('M1XMSeeA6kFuCScyI7mdtO')/Memberships?%24skiptoken=1yhyr&oauth_body_hash=2jmj7l5rSw0yVb%2FvlWAYkK%2FYBwk%3D&oauth_callback=oob&oauth_consumer_key=zUN7VGKgFk7HfEiAANoh&oauth_nonce=VfyR9cF0HKI&oauth_signature=Mm0tv0vxWiUjpvsHGKSz44pstMk%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1689257289&oauth_token=KKUttqLiC6CtUFOAuH6tBvK16OhSyuOMq3fYxx43&oauth_verifier=VK3uu8oieomIZpYIB1AT&oauth_version=1.0"
}
}
Thanks
Mathias
It looks like you need to include a collection (or environment) variable in the URL starting at groups.
https://jam12.sapjam.com/api/v1/OData/{{Groups}}
With the initial value being
Groups(‘M1XMSeeA6kFuCScyI7mdtO’)/Memberships
The script in the tests tab would then look something like…
const response = pm.response.json();
console.log(response);
let requestName = pm.info.requestName
if (response.d.__next != null) {
pm.collectionVariables.set("Groups", response.d.__next);
postman.setNextRequest(requestName);
}