PowerBuilder / Postman API / Update an API Version
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_Name
string ls_CreatedAt
string ls_UpdatedAt
string ls_Api
string ls_CreatedBy
string ls_UpdatedBy
// 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.
// {
// "version": {
// "name": "2.0"
// }
// }
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("version.name","2.0")
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/apis/{{apiId}}/versions/{{apiVersionId}}",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)
// {
// "version": {
// "id": "d71cf403-c549-4c7c-9dc6-a6a105acf67c",
// "name": "2.0",
// "createdAt": "2019-07-26T11:24:15.000Z",
// "updatedAt": "2019-08-09T09:27:36.000Z",
// "api": "2b95d07c-8379-4bd1-924f-e7e1af185284",
// "createdBy": "12",
// "updatedBy": "5665"
// }
// }
// 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("version.id")
ls_Name = loo_JResp.StringOf("version.name")
ls_CreatedAt = loo_JResp.StringOf("version.createdAt")
ls_UpdatedAt = loo_JResp.StringOf("version.updatedAt")
ls_Api = loo_JResp.StringOf("version.api")
ls_CreatedBy = loo_JResp.StringOf("version.createdBy")
ls_UpdatedBy = loo_JResp.StringOf("version.updatedBy")
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 '{
"version": {
"name": "2.0"
}
}'
https://api.getpostman.com/apis/{{apiId}}/versions/{{apiVersionId}}
Postman Collection Item JSON
{
"name": "Update an API Version",
"request": {
"method": "PUT",
"header": [
{
"name": "Content-Type",
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"version\": {\n\t\t\"name\": \"2.0\"\n\t}\n}"
},
"url": {
"raw": "https://api.getpostman.com/apis/{{apiId}}/versions/{{apiVersionId}}",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"apis",
"{{apiId}}",
"versions",
"{{apiVersionId}}"
]
},
"description": "This call updates an existing API Version. \n\nRequest body should contain a `version` object with the fields which need to be updated. Only field which can be updated is `name`.\n\nResponse contains a `version` object with all the details related to the created API Version, namely, `id`, `name`, `api` etc.\n\n> Requires <a href=\"#authentication\">API Key</a> as `X-Api-Key` request header or `apikey` URL query parameter."
},
"response": [
{
"name": "Update an API version",
"originalRequest": {
"method": "PUT",
"header": [
{
"name": "Content-Type",
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"version\": {\n\t\t\"name\": \"2.0\"\n\t}\n}"
},
"url": {
"raw": "https://api.getpostman.com/apis/{{apiId}}/versions/{{versionId}}",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"apis",
"{{apiId}}",
"versions",
"{{versionId}}"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"description": {
"content": "",
"type": "text/plain"
}
}
],
"cookie": [
],
"body": "{\n\t\"version\": {\n\t\t\"id\": \"d71cf403-c549-4c7c-9dc6-a6a105acf67c\",\n\t \"name\": \"2.0\",\n\t \"createdAt\": \"2019-07-26T11:24:15.000Z\",\n\t \"updatedAt\": \"2019-08-09T09:27:36.000Z\",\n\t \"api\": \"2b95d07c-8379-4bd1-924f-e7e1af185284\",\n\t \"createdBy\": \"12\",\n\t \"updatedBy\": \"5665\"\n\t}\n}"
}
]
}