PowerBuilder / Postman API / Single Collection
Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Id
string ls_Name
string ls_V_Url
string ls_Method
string ls_Mode
string ls_RequestDescription
integer j
integer li_Count_j
string ls_Listen
string ls_V_Type
string ls_Exec
string ls_Key
string ls_Value
string ls_Description
string ls_Name
string ls_V_postman_id
string ls_Description
string ls_Schema
integer i
integer li_Count_i
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
destroy loo_Http
MessageBox("Error","Connecting to COM object failed")
return
end if
loo_Http.SetRequestHeader("X-API-Key","{{postman_api_key}}")
loo_SbResponseBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
li_Success = loo_Http.QuickGetSb("https://api.getpostman.com/collections/{{collection_uid}}",loo_SbResponseBody)
if li_Success = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_SbResponseBody
return
end if
loo_JResp = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")
loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0
Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()
li_RespStatusCode = loo_Http.LastStatus
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Http.LastHeader
Write-Debug "Failed."
destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "collection": {
// "variables": [
// ],
// "info": {
// "name": "Sample Collection",
// "_postman_id": "f2e66c2e-5297-e4a5-739e-20cbb90900e3",
// "description": "This is a sample collection that makes a tiny request to Postman Echo service to get the list of request headers sent by a HTTP client.",
// "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
// },
// "item": [
// {
// "id": "82ee981b-e19f-962a-401e-ea34ebfb4848",
// "name": "Request Headers",
// "event": [
// {
// "listen": "test",
// "script": {
// "type": "text/javascript",
// "exec": "var responseJSON;\ntry {\n tests[\"Body contains headers\"] = responseBody.has(\"headers\");\n responseJSON = JSON.parse(responseBody);\n tests[\"Header contains host\"] = \"host\" in responseJSON.headers;\n tests[\"Header contains test parameter sent as part of request header\"] = \"my-sample-header\" in responseJSON.headers;\n}\ncatch (e) { }\n\n\n\n"
// }
// }
// ],
// "request": {
// "url": "https://echo.getpostman.com/headers",
// "method": "GET",
// "header": [
// {
// "key": "my-sample-header",
// "value": "Lorem ipsum dolor sit amet",
// "description": ""
// }
// ],
// "body": {
// "mode": "formdata",
// "formdata": [
// ]
// },
// "description": ""
// },
// "response": [
// ]
// }
// ]
// }
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
ls_Name = loo_JResp.StringOf("collection.info.name")
ls_V_postman_id = loo_JResp.StringOf("collection.info._postman_id")
ls_Description = loo_JResp.StringOf("collection.info.description")
ls_Schema = loo_JResp.StringOf("collection.info.schema")
i = 0
li_Count_i = loo_JResp.SizeOfArray("collection.variables")
do while i < li_Count_i
loo_JResp.I = i
i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("collection.item")
do while i < li_Count_i
loo_JResp.I = i
ls_Id = loo_JResp.StringOf("collection.item[i].id")
ls_Name = loo_JResp.StringOf("collection.item[i].name")
ls_V_Url = loo_JResp.StringOf("collection.item[i].request.url")
ls_Method = loo_JResp.StringOf("collection.item[i].request.method")
ls_Mode = loo_JResp.StringOf("collection.item[i].request.body.mode")
ls_RequestDescription = loo_JResp.StringOf("collection.item[i].request.description")
j = 0
li_Count_j = loo_JResp.SizeOfArray("collection.item[i].event")
do while j < li_Count_j
loo_JResp.J = j
ls_Listen = loo_JResp.StringOf("collection.item[i].event[j].listen")
ls_V_Type = loo_JResp.StringOf("collection.item[i].event[j].script.type")
ls_Exec = loo_JResp.StringOf("collection.item[i].event[j].script.exec")
j = j + 1
loop
j = 0
li_Count_j = loo_JResp.SizeOfArray("collection.item[i].request.header")
do while j < li_Count_j
loo_JResp.J = j
ls_Key = loo_JResp.StringOf("collection.item[i].request.header[j].key")
ls_Value = loo_JResp.StringOf("collection.item[i].request.header[j].value")
ls_Description = loo_JResp.StringOf("collection.item[i].request.header[j].description")
j = j + 1
loop
j = 0
li_Count_j = loo_JResp.SizeOfArray("collection.item[i].request.body.formdata")
do while j < li_Count_j
loo_JResp.J = j
j = j + 1
loop
j = 0
li_Count_j = loo_JResp.SizeOfArray("collection.item[i].response")
do while j < li_Count_j
loo_JResp.J = j
j = j + 1
loop
i = i + 1
loop
destroy loo_Http
destroy loo_SbResponseBody
destroy loo_JResp
Curl Command
curl -X GET
-H "X-API-Key: {{postman_api_key}}"
https://api.getpostman.com/collections/{{collection_uid}}
Postman Collection Item JSON
{
"name": "Single Collection ",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"pm.test(\"response is ok\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"pm.test(\"response json data should not have errors\", function () {",
" pm.response.to.have.jsonBody();",
" pm.response.to.not.have.jsonBody('error');",
"});",
"",
"pm.test(\"response json should contain one collection\", function () {",
" pm.expect(pm.response.json()).to.have.property('collection').and.be.an('object');",
"});",
"",
"// additional tests to ensure that the relevant environment variables are present",
"pm.test('\"postman_api_key\" variable should be present', function () {",
" pm.expect(pm.variables.get('postman_api_key')).to.be.a('string');",
"});",
"",
"// you can unskip this test in case you want to have a stricter check on the selected",
"// environment.",
"pm.test.skip('\"collection_uid\" variable should be present', function () {",
" pm.expect(pm.variables.get('collection_uid')).to.be.a('string');",
"});"
]
}
}
],
"request": {
"method": "GET",
"header": [
],
"url": {
"raw": "https://api.getpostman.com/collections/{{collection_uid}}",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"collections",
"{{collection_uid}}"
]
},
"description": "Access the contents of a collection that is accessible to you using its unique id (`uid`).\n\n> Requires <a href=\"#authentication\">API Key</a> as `X-Api-Key` request header or `apikey` URL query parameter."
},
"response": [
{
"name": "Valid Response",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "https://api.getpostman.com/collections/{{collection_uid}}",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"collections",
"{{collection_uid}}"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"name": "Content-Type",
"description": {
"content": "",
"type": "text/plain"
}
}
],
"cookie": [
],
"body": "{\n \"collection\": {\n \"variables\": [],\n \"info\": {\n \"name\": \"Sample Collection\",\n \"_postman_id\": \"f2e66c2e-5297-e4a5-739e-20cbb90900e3\",\n \"description\": \"This is a sample collection that makes a tiny request to Postman Echo service to get the list of request headers sent by a HTTP client.\",\n \"schema\": \"https://schema.getpostman.com/json/collection/v2.0.0/collection.json\"\n },\n \"item\": [\n {\n \"id\": \"82ee981b-e19f-962a-401e-ea34ebfb4848\",\n \"name\": \"Request Headers\",\n \"event\": [\n {\n \"listen\": \"test\",\n \"script\": {\n \"type\": \"text/javascript\",\n \"exec\": \"var responseJSON;\\ntry {\\n tests[\\\"Body contains headers\\\"] = responseBody.has(\\\"headers\\\");\\n responseJSON = JSON.parse(responseBody);\\n tests[\\\"Header contains host\\\"] = \\\"host\\\" in responseJSON.headers;\\n tests[\\\"Header contains test parameter sent as part of request header\\\"] = \\\"my-sample-header\\\" in responseJSON.headers;\\n}\\ncatch (e) { }\\n\\n\\n\\n\"\n }\n }\n ],\n \"request\": {\n \"url\": \"https://echo.getpostman.com/headers\",\n \"method\": \"GET\",\n \"header\": [\n {\n \"key\": \"my-sample-header\",\n \"value\": \"Lorem ipsum dolor sit amet\",\n \"description\": \"\"\n }\n ],\n \"body\": {\n \"mode\": \"formdata\",\n \"formdata\": []\n },\n \"description\": \"\"\n },\n \"response\": []\n }\n ]\n }\n}"
}
]
}