PowerBuilder / Postman API / All Mocks
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_Owner
string ls_Uid
string ls_Collection
string ls_Environment
string ls_MockUrl
string ls_Name
integer li_MatchBody
integer li_MatchQueryParams
integer li_MatchWildcards
string ls_Delay
string ls_CreatedAt
string ls_UpdatedAt
integer li_IsPublic
integer j
integer li_Count_j
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/mocks",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)
// {
// "mocks": [
// {
// "id": "e782b64e-406b-4a6c-8fe9-9ebe84aeb706",
// "owner": "1686168",
// "uid": "1686168-e782b64e-406b-4a6c-8fe9-9ebe84aeb706",
// "collection": "1686168-39fee52f-b806-3ffa-1173-00a6f5b183dc",
// "environment": "1686168-2b90cdd8-e9ac-4086-91c2-bc4cad659511",
// "mockUrl": "https://e782b64e-406b-4a6c-8fe9-9ebe84aeb706.mock.pstmn.io",
// "name": "mock1",
// "config": {
// "headers": [
// ],
// "matchBody": false,
// "matchQueryParams": true,
// "matchWildcards": true,
// "delay": null
// },
// "createdAt": "2020-12-15T06:44:37.000Z",
// "updatedAt": "2020-12-15T06:44:37.000Z",
// "isPublic": false
// },
// {
// "id": "8f9d4b95-780d-455d-af38-772277bc9393",
// "owner": "1686168",
// "uid": "1686168-8f9d4b95-780d-455d-af38-772277bc9393",
// "collection": "1686168-37eeb72f-5d3e-48b4-8022-6b9cca6d2664",
// "mockUrl": "https://8f9d4b95-780d-455d-af38-772277bc93936.mock.pstmn.io",
// "name": "mock2",
// "config": {
// "headers": [
// ],
// "matchBody": false,
// "matchQueryParams": true,
// "matchWildcards": true,
// "delay": null
// },
// "createdAt": "2020-11-15T06:44:37.000Z",
// "updatedAt": "2020-12-15T06:48:37.000Z",
// "isPublic": true
// }
// ]
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
i = 0
li_Count_i = loo_JResp.SizeOfArray("mocks")
do while i < li_Count_i
loo_JResp.I = i
ls_Id = loo_JResp.StringOf("mocks[i].id")
ls_Owner = loo_JResp.StringOf("mocks[i].owner")
ls_Uid = loo_JResp.StringOf("mocks[i].uid")
ls_Collection = loo_JResp.StringOf("mocks[i].collection")
ls_Environment = loo_JResp.StringOf("mocks[i].environment")
ls_MockUrl = loo_JResp.StringOf("mocks[i].mockUrl")
ls_Name = loo_JResp.StringOf("mocks[i].name")
li_MatchBody = loo_JResp.BoolOf("mocks[i].config.matchBody")
li_MatchQueryParams = loo_JResp.BoolOf("mocks[i].config.matchQueryParams")
li_MatchWildcards = loo_JResp.BoolOf("mocks[i].config.matchWildcards")
ls_Delay = loo_JResp.StringOf("mocks[i].config.delay")
ls_CreatedAt = loo_JResp.StringOf("mocks[i].createdAt")
ls_UpdatedAt = loo_JResp.StringOf("mocks[i].updatedAt")
li_IsPublic = loo_JResp.BoolOf("mocks[i].isPublic")
j = 0
li_Count_j = loo_JResp.SizeOfArray("mocks[i].config.headers")
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/mocks
Postman Collection Item JSON
{
"name": "All Mocks",
"request": {
"method": "GET",
"header": [
],
"url": {
"raw": "https://api.getpostman.com/mocks",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"mocks"
]
},
"description": "This endpoint fetches all the mocks that you have created.\n\n> Requires <a href=\"#authentication\">API Key</a> as `X-Api-Key` request header or `apikey` URL query parameter."
},
"response": [
{
"name": "Successful Response",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "https://api.getpostman.com/mocks",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"mocks"
]
}
},
"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 \"mocks\": [\n {\n \"id\": \"e782b64e-406b-4a6c-8fe9-9ebe84aeb706\",\n \"owner\": \"1686168\",\n \"uid\": \"1686168-e782b64e-406b-4a6c-8fe9-9ebe84aeb706\",\n \"collection\": \"1686168-39fee52f-b806-3ffa-1173-00a6f5b183dc\",\n \"environment\": \"1686168-2b90cdd8-e9ac-4086-91c2-bc4cad659511\",\n \"mockUrl\": \"https://e782b64e-406b-4a6c-8fe9-9ebe84aeb706.mock.pstmn.io\",\n \"name\": \"mock1\",\n \"config\": {\n \"headers\": [],\n \"matchBody\": false,\n \"matchQueryParams\": true,\n \"matchWildcards\": true,\n \"delay\": null\n },\n \"createdAt\": \"2020-12-15T06:44:37.000Z\",\n \"updatedAt\": \"2020-12-15T06:44:37.000Z\",\n \"isPublic\": false\n },\n {\n \"id\": \"8f9d4b95-780d-455d-af38-772277bc9393\",\n \"owner\": \"1686168\",\n \"uid\": \"1686168-8f9d4b95-780d-455d-af38-772277bc9393\",\n \"collection\": \"1686168-37eeb72f-5d3e-48b4-8022-6b9cca6d2664\",\n \"mockUrl\": \"https://8f9d4b95-780d-455d-af38-772277bc93936.mock.pstmn.io\",\n \"name\": \"mock2\",\n \"config\": {\n \"headers\": [],\n \"matchBody\": false,\n \"matchQueryParams\": true,\n \"matchWildcards\": true,\n \"delay\": null\n },\n \"createdAt\": \"2020-11-15T06:44:37.000Z\",\n \"updatedAt\": \"2020-12-15T06:48:37.000Z\",\n \"isPublic\": true\n }\n ]\n}"
}
]
}