Chilkat Online Tools

PowerBuilder / Postman API / Single Environment

Back to Collection Items

integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Key
string ls_Value
integer li_Enabled
string ls_Id
string ls_Name
string ls_Owner
string ls_CreatedAt
string ls_UpdatedAt
integer li_IsPublic
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
li_rc = loo_Http.ConnectToNewObject("Chilkat_9_5_0.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
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

li_Success = loo_Http.QuickGetSb("https://api.getpostman.com/environments/{{environment_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
li_rc = loo_JResp.ConnectToNewObject("Chilkat_9_5_0.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)

// {
//   "environment": {
//     "id": "1b163ddc-62ff-41d9-b74b-71424b9aa69d",
//     "name": "Contract Test Environment",
//     "owner": "10016724",
//     "createdAt": "2020-11-05T13:59:22.000Z",
//     "updatedAt": "2020-11-05T13:59:23.000Z",
//     "values": [
//       {
//         "key": "env-apiKey",
//         "value": "",
//         "enabled": true
//       }
//     ],
//     "isPublic": false
//   }
// }

// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

ls_Id = loo_JResp.StringOf("environment.id")
ls_Name = loo_JResp.StringOf("environment.name")
ls_Owner = loo_JResp.StringOf("environment.owner")
ls_CreatedAt = loo_JResp.StringOf("environment.createdAt")
ls_UpdatedAt = loo_JResp.StringOf("environment.updatedAt")
li_IsPublic = loo_JResp.BoolOf("environment.isPublic")
i = 0
li_Count_i = loo_JResp.SizeOfArray("environment.values")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Key = loo_JResp.StringOf("environment.values[i].key")
    ls_Value = loo_JResp.StringOf("environment.values[i].value")
    li_Enabled = loo_JResp.BoolOf("environment.values[i].enabled")
    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/environments/{{environment_uid}}

Postman Collection Item JSON

{
  "name": "Single Environment",
  "event": [
    {
      "listen": "test",
      "script": {
        "type": "text/javascript",
        "exec": [
          "var responseJSON;",
          "",
          "// parse response body as JSON",
          "try { responseJSON = JSON.parse(responseBody); } catch (e) { }",
          "tests['received a valid response JSON'] = !!responseJSON;",
          "!responseJSON && (responseJSON = {});",
          "",
          "tests['status code is 200'] = (responseCode.code === 200);",
          "tests['response does not have errors'] = (!responseJSON.error);",
          "",
          "tests['response has an environment object'] = (typeof responseJSON.environment === 'object');"
        ]
      }
    }
  ],
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "https://api.getpostman.com/environments/{{environment_uid}}",
      "protocol": "https",
      "host": [
        "api",
        "getpostman",
        "com"
      ],
      "path": [
        "environments",
        "{{environment_uid}}"
      ]
    },
    "description": "Access the contents of an environment 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/environments/{{environment_uid}}",
          "protocol": "https",
          "host": [
            "api",
            "getpostman",
            "com"
          ],
          "path": [
            "environments",
            "{{environment_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    \"environment\": {\n        \"id\": \"1b163ddc-62ff-41d9-b74b-71424b9aa69d\",\n        \"name\": \"Contract Test Environment\",\n        \"owner\": \"10016724\",\n        \"createdAt\": \"2020-11-05T13:59:22.000Z\",\n        \"updatedAt\": \"2020-11-05T13:59:23.000Z\",\n        \"values\": [\n            {\n                \"key\": \"env-apiKey\",\n                \"value\": \"\",\n                \"enabled\": true\n            }\n        ],\n        \"isPublic\": false\n    }\n}"
    }
  ]
}