Go / Postman API / Single Environment
Back to Collection Items
// This example assumes the Chilkat API to have been previously unlocked.
// See Global_Ref.html">Global Unlock Sample for sample code.
http := chilkat.NewHttp()
var success bool
http.SetRequestHeader("X-API-Key","{{postman_api_key}}")
sbResponseBody := chilkat.NewStringBuilder()
success = http.QuickGetSb("https://api.getpostman.com/environments/{{environment_uid}}",sbResponseBody)
if success == false {
fmt.Println(http.LastErrorText())
http.DisposeHttp()
sbResponseBody.DisposeStringBuilder()
return
}
jResp := chilkat.NewJsonObject()
jResp.LoadSb(sbResponseBody)
jResp.SetEmitCompact(false)
fmt.Println("Response Body:")
fmt.Println(*jResp.Emit())
respStatusCode := http.LastStatus()
fmt.Println("Response Status Code = ", respStatusCode)
if respStatusCode >= 400 {
fmt.Println("Response Header:")
fmt.Println(http.LastHeader())
fmt.Println("Failed.")
http.DisposeHttp()
sbResponseBody.DisposeStringBuilder()
jResp.DisposeJsonObject()
return
}
// 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
var key *string = new(string)
var value *string = new(string)
var enabled bool
Id := jResp.StringOf("environment.id")
Name := jResp.StringOf("environment.name")
Owner := jResp.StringOf("environment.owner")
CreatedAt := jResp.StringOf("environment.createdAt")
UpdatedAt := jResp.StringOf("environment.updatedAt")
IsPublic := jResp.BoolOf("environment.isPublic")
i := 0
count_i := jResp.SizeOfArray("environment.values")
for i < count_i {
jResp.SetI(i)
key = jResp.StringOf("environment.values[i].key")
value = jResp.StringOf("environment.values[i].value")
enabled = jResp.BoolOf("environment.values[i].enabled")
i = i + 1
}
http.DisposeHttp()
sbResponseBody.DisposeStringBuilder()
jResp.DisposeJsonObject()
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}"
}
]
}