PowerBuilder / Postman API / Update Mock
Back to Collection Items
integer li_rc
oleobject loo_Http
integer li_Success
oleobject loo_Json
oleobject loo_SbRequestBody
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
integer li_RespStatusCode
string ls_Id
string ls_Owner
string ls_Uid
string ls_Collection
string ls_MockUrl
string ls_Name
integer li_MatchBody
integer li_MatchQueryParams
integer li_MatchWildcards
string ls_Environment
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
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "mock": {
// "name": "My Mock Server",
// "environment": "11582779-ac1b6608-deb7-4c05-9d48-ee775aabfc19",
// "description": "example describing update mock description",
// "private": false,
// "versionTag": "abf07d3d-f8ec-47d4-8015-9fe83078b4ec"
// }
// }
loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")
loo_Json.UpdateString("mock.name","My Mock Server")
loo_Json.UpdateString("mock.environment","11582779-ac1b6608-deb7-4c05-9d48-ee775aabfc19")
loo_Json.UpdateString("mock.description","example describing update mock description")
loo_Json.UpdateBool("mock.private",0)
loo_Json.UpdateString("mock.versionTag","abf07d3d-f8ec-47d4-8015-9fe83078b4ec")
loo_Http.SetRequestHeader("Content-Type","application/json")
loo_Http.SetRequestHeader("X-API-Key","{{postman_api_key}}")
loo_SbRequestBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Json.EmitSb(loo_SbRequestBody)
loo_Resp = loo_Http.PTextSb("PUT","https://api.getpostman.com/mocks/{{mock_uid}}",loo_SbRequestBody,"utf-8","application/json",0,0)
if loo_Http.LastMethodSuccess = 0 then
Write-Debug loo_Http.LastErrorText
destroy loo_Http
destroy loo_Json
destroy loo_SbRequestBody
return
end if
loo_SbResponseBody = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")
loo_Resp.GetBodySb(loo_SbResponseBody)
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_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
Write-Debug "Response Header:"
Write-Debug loo_Resp.Header
Write-Debug "Failed."
destroy loo_Resp
destroy loo_Http
destroy loo_Json
destroy loo_SbRequestBody
destroy loo_SbResponseBody
destroy loo_JResp
return
end if
destroy loo_Resp
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "mock": {
// "id": "06040138-dd6b-4cce-9a02-7e1c1ab59723",
// "owner": "11582779",
// "uid": "11582779-06040138-dd6b-4cce-9a02-7e1c1ab59723",
// "collection": "11582779-fd6797e2-de6b-4699-975c-85290e4c2499",
// "mockUrl": "https://06040138-dd6b-4cce-9a02-7e1c1ab59723.mock.pstmn.io",
// "name": "My Mock Server",
// "config": {
// "headers": [
// ],
// "matchBody": false,
// "matchQueryParams": true,
// "matchWildcards": true
// },
// "environment": "11582779-ac1b6608-deb7-4c05-9d48-ee775aabfc19"
// }
// }
// 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("mock.id")
ls_Owner = loo_JResp.StringOf("mock.owner")
ls_Uid = loo_JResp.StringOf("mock.uid")
ls_Collection = loo_JResp.StringOf("mock.collection")
ls_MockUrl = loo_JResp.StringOf("mock.mockUrl")
ls_Name = loo_JResp.StringOf("mock.name")
li_MatchBody = loo_JResp.BoolOf("mock.config.matchBody")
li_MatchQueryParams = loo_JResp.BoolOf("mock.config.matchQueryParams")
li_MatchWildcards = loo_JResp.BoolOf("mock.config.matchWildcards")
ls_Environment = loo_JResp.StringOf("mock.environment")
i = 0
li_Count_i = loo_JResp.SizeOfArray("mock.config.headers")
do while i < li_Count_i
loo_JResp.I = i
i = i + 1
loop
destroy loo_Http
destroy loo_Json
destroy loo_SbRequestBody
destroy loo_SbResponseBody
destroy loo_JResp
Curl Command
curl -X PUT
-H "X-API-Key: {{postman_api_key}}"
-H "Content-Type: application/json"
-d '{
"mock": {
"name": "My Mock Server",
"environment": "11582779-ac1b6608-deb7-4c05-9d48-ee775aabfc19",
"description": "example describing update mock description",
"private": false,
"versionTag": "abf07d3d-f8ec-47d4-8015-9fe83078b4ec"
}
}'
https://api.getpostman.com/mocks/{{mock_uid}}
Postman Collection Item JSON
{
"name": "Update Mock",
"request": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"mock\": {\n \"name\": \"My Mock Server\",\n \"environment\": \"11582779-ac1b6608-deb7-4c05-9d48-ee775aabfc19\",\n \"description\": \"example describing update mock description\",\n \"private\": false,\n \"versionTag\": \"abf07d3d-f8ec-47d4-8015-9fe83078b4ec\"\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.getpostman.com/mocks/{{mock_uid}}",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"mocks",
"{{mock_uid}}"
]
},
"description": "This endpoint allows you to update a mock you have created using its `uid`. The endpoint allows you to edit fields,\n* name\n* environment\n* description\n* private\n* versionTag\n\n> Requires <a href=\"#authentication\">API Key</a> as `X-Api-Key` request header or `apikey` URL query parameter."
},
"response": [
{
"name": "success Response",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"mock\": {\n \"name\": \"My Mock Server\",\n \"environment\": \"11582779-ac1b6608-deb7-4c05-9d48-ee775aabfc19\",\n \"description\": \"example describing update mock description\",\n \"private\": false,\n \"versionTag\": \"abf07d3d-f8ec-47d4-8015-9fe83078b4ec\"\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.getpostman.com/mocks/{{mock_uid}}",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"mocks",
"{{mock_uid}}"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"mock\": {\n \"id\": \"06040138-dd6b-4cce-9a02-7e1c1ab59723\",\n \"owner\": \"11582779\",\n \"uid\": \"11582779-06040138-dd6b-4cce-9a02-7e1c1ab59723\",\n \"collection\": \"11582779-fd6797e2-de6b-4699-975c-85290e4c2499\",\n \"mockUrl\": \"https://06040138-dd6b-4cce-9a02-7e1c1ab59723.mock.pstmn.io\",\n \"name\": \"My Mock Server\",\n \"config\": {\n \"headers\": [],\n \"matchBody\": false,\n \"matchQueryParams\": true,\n \"matchWildcards\": true\n },\n \"environment\": \"11582779-ac1b6608-deb7-4c05-9d48-ee775aabfc19\"\n }\n}"
}
]
}