DataFlex / Postman API / Update an API
Back to Collection Items
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoHttp
Boolean iSuccess
Handle hoJson
Variant vSbRequestBody
Handle hoSbRequestBody
Variant vResp
Handle hoResp
Variant vSbResponseBody
Handle hoSbResponseBody
Handle hoJResp
Integer iRespStatusCode
String sId
String sName
String sSummary
String sDescription
String sCreatedBy
String sCreatedAt
String sUpdatedAt
String sTemp1
Boolean bTemp1
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "api": {
// "name": "New name",
// "description": "This is an updated Description"
// }
// }
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "api.name" "New name" To iSuccess
Get ComUpdateString Of hoJson "api.description" "This is an updated Description" To iSuccess
Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"
Send ComSetRequestHeader To hoHttp "X-API-Key" "{{postman_api_key}}"
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbRequestBody
If (Not(IsComObjectCreated(hoSbRequestBody))) Begin
Send CreateComObject of hoSbRequestBody
End
Get pvComObject of hoSbRequestBody to vSbRequestBody
Get ComEmitSb Of hoJson vSbRequestBody To iSuccess
Get pvComObject of hoSbRequestBody to vSbRequestBody
Get ComPTextSb Of hoHttp "PUT" "https://api.getpostman.com/apis/{{apiId}}" vSbRequestBody "utf-8" "application/json" False False To vResp
If (IsComObject(vResp)) Begin
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
Set pvComObject Of hoResp To vResp
End
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
If (Not(IsComObjectCreated(hoJResp))) Begin
Send CreateComObject of hoJResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
Set ComEmitCompact Of hoJResp To False
Showln "Response Body:"
Get ComEmit Of hoJResp To sTemp1
Showln sTemp1
Get ComStatusCode Of hoResp To iRespStatusCode
Showln "Response Status Code = " iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Header:"
Get ComHeader Of hoResp To sTemp1
Showln sTemp1
Showln "Failed."
Send Destroy of hoResp
Procedure_Return
End
Send Destroy of hoResp
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "api": {
// "id": "387c2863-6ee3-4a56-8210-225f774edade",
// "name": "Sync API",
// "summary": "This is a summary",
// "description": "This is a description.",
// "createdBy": "5665",
// "createdAt": "2019-02-12 19:34:49",
// "updatedAt": "2019-02-12 19:34:49"
// }
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
Get ComStringOf Of hoJResp "api.id" To sId
Get ComStringOf Of hoJResp "api.name" To sName
Get ComStringOf Of hoJResp "api.summary" To sSummary
Get ComStringOf Of hoJResp "api.description" To sDescription
Get ComStringOf Of hoJResp "api.createdBy" To sCreatedBy
Get ComStringOf Of hoJResp "api.createdAt" To sCreatedAt
Get ComStringOf Of hoJResp "api.updatedAt" To sUpdatedAt
End_Procedure
Curl Command
curl -X PUT
-H "X-API-Key: {{postman_api_key}}"
-H "Content-Type: application/json"
-d '{
"api": {
"name": "New name",
"description": "This is an updated Description"
}
}'
https://api.getpostman.com/apis/{{apiId}}
Postman Collection Item JSON
{
"name": "Update an API",
"request": {
"method": "PUT",
"header": [
{
"name": "Content-Type",
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"api\": {\n\t\t\"name\": \"New name\",\n\t\t\"description\": \"This is an updated Description\"\n\t}\n}"
},
"url": {
"raw": "https://api.getpostman.com/apis/{{apiId}}",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"apis",
"{{apiId}}"
]
},
"description": "This call updates an existing API . \n\nRequest body should contain an `api` object which should have the fields to be updated. Only `name`, `summary` and `description` fields can be edited for an API.\n\nResponse contains an `api` object with all the details related to the created API, namely, `id`, `name`, `summary`, `description` 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",
"originalRequest": {
"method": "PUT",
"header": [
{
"name": "Content-Type",
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"api\": {\n\t\t\"name\": \"New name\",\n\t\t\"description\": \"This is an updated Description\"\n\t}\n}"
},
"url": {
"raw": "https://api.getpostman.com/apis/{{apiId}}",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"apis",
"{{apiId}}"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"description": {
"content": "",
"type": "text/plain"
}
}
],
"cookie": [
],
"body": "{\n\t\"api\":{\n\t\t\"id\": \"387c2863-6ee3-4a56-8210-225f774edade\",\n\t\t\"name\": \"Sync API\",\n\t\t\"summary\": \"This is a summary\",\n\t\t\"description\": \"This is a description.\",\n\t\t\"createdBy\": \"5665\",\n\t\t\"createdAt\": \"2019-02-12 19:34:49\",\n\t\t\"updatedAt\": \"2019-02-12 19:34:49\"\n\t}\n}"
}
]
}