Chilkat Online Tools

DataFlex / Support API / Show Target

Back to Collection Items

Use ChilkatAx-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sProject_id
    String sResource
    String sTarget_url
    String sTitle
    String sToken
    String sV_Type
    String sActive
    String sCreated_at
    String sId
    String sMessage_id
    String sPassword
    String sTodo_list_id
    String sUsername
    String sTemp1

    // 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

    Set ComBasicAuth Of hoHttp To True
    Set ComLogin Of hoHttp To "login"
    Set ComPassword Of hoHttp To "password"

    Send ComSetRequestHeader To hoHttp "Accept" "application/json"

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComQuickGetSb Of hoHttp "https://example.zendesk.com/api/v2/targets/:target_id" vSbResponseBody To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    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 ComLastStatus Of hoHttp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComLastHeader Of hoHttp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Procedure_Return
    End

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "target": {
    //     "project_id": "<string>",
    //     "resource": "<string>",
    //     "target_url": "<string>",
    //     "title": "<string>",
    //     "token": "<string>",
    //     "type": "<string>",
    //     "active": "<boolean>",
    //     "created_at": "<dateTime>",
    //     "id": "<integer>",
    //     "message_id": "<string>",
    //     "password": "<string>",
    //     "todo_list_id": "<string>",
    //     "username": "<string>"
    //   }
    // }

    // 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 "target.project_id" To sProject_id
    Get ComStringOf Of hoJResp "target.resource" To sResource
    Get ComStringOf Of hoJResp "target.target_url" To sTarget_url
    Get ComStringOf Of hoJResp "target.title" To sTitle
    Get ComStringOf Of hoJResp "target.token" To sToken
    Get ComStringOf Of hoJResp "target.type" To sV_Type
    Get ComStringOf Of hoJResp "target.active" To sActive
    Get ComStringOf Of hoJResp "target.created_at" To sCreated_at
    Get ComStringOf Of hoJResp "target.id" To sId
    Get ComStringOf Of hoJResp "target.message_id" To sMessage_id
    Get ComStringOf Of hoJResp "target.password" To sPassword
    Get ComStringOf Of hoJResp "target.todo_list_id" To sTodo_list_id
    Get ComStringOf Of hoJResp "target.username" To sUsername


End_Procedure

Curl Command

curl  -u login:password -X GET
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/targets/:target_id

Postman Collection Item JSON

{
  "name": "Show Target",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/targets/:target_id",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "targets",
        ":target_id"
      ],
      "variable": [
        {
          "key": "target_id",
          "value": "<integer>"
        }
      ]
    },
    "description": "#### Allowed For\n\n* Agents\n"
  },
  "response": [
    {
      "name": "Success response",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/targets/:target_id",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "targets",
            ":target_id"
          ],
          "variable": [
            {
              "key": "target_id"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"target\": {\n    \"project_id\": \"<string>\",\n    \"resource\": \"<string>\",\n    \"target_url\": \"<string>\",\n    \"title\": \"<string>\",\n    \"token\": \"<string>\",\n    \"type\": \"<string>\",\n    \"active\": \"<boolean>\",\n    \"created_at\": \"<dateTime>\",\n    \"id\": \"<integer>\",\n    \"message_id\": \"<string>\",\n    \"password\": \"<string>\",\n    \"todo_list_id\": \"<string>\",\n    \"username\": \"<string>\"\n  }\n}"
    }
  ]
}