Chilkat Online Tools

PureBasic / Support API / Create Request

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

    ; This example assumes the Chilkat API to have been previously unlocked.
    ; See Global Unlock Sample for sample code.

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    CkHttp::setCkBasicAuth(http, 1)
    CkHttp::setCkLogin(http, "login")
    CkHttp::setCkPassword(http, "password")

    CkHttp::ckSetRequestHeader(http,"Accept","application/json")

    resp.i = CkHttp::ckQuickRequest(http,"POST","https://example.zendesk.com/api/v2/requests")
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        ProcedureReturn
    EndIf

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkHttpResponse::ckGetBodySb(resp,sbResponseBody)

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(jResp,sbResponseBody)
    CkJsonObject::setCkEmitCompact(jResp, 0)

    Debug "Response Body:"
    Debug CkJsonObject::ckEmit(jResp)

    respStatusCode.i = CkHttpResponse::ckStatusCode(resp)
    Debug "Response Status Code = " + Str(respStatusCode)
    If respStatusCode >= 400
        Debug "Response Header:"
        Debug CkHttpResponse::ckHeader(resp)
        Debug "Failed."
        CkHttpResponse::ckDispose(resp)

        CkHttp::ckDispose(http)
        CkStringBuilder::ckDispose(sbResponseBody)
        CkJsonObject::ckDispose(jResp)
        ProcedureReturn
    EndIf

    CkHttpResponse::ckDispose(resp)

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

    ; {
    ;   "request": {
    ;     "subject": "<string>",
    ;     "assignee_id": "<integer>",
    ;     "can_be_solved_by_me": "<boolean>",
    ;     "collaborator_ids": [
    ;       "<integer>",
    ;       "<integer>"
    ;     ],
    ;     "created_at": "<dateTime>",
    ;     "custom_fields": [
    ;       {
    ;         "id": "<integer>",
    ;         "value": "<string>"
    ;       },
    ;       {
    ;         "id": "<integer>",
    ;         "value": "<string>"
    ;       }
    ;     ],
    ;     "custom_status_id": "<integer>",
    ;     "description": "<string>",
    ;     "due_at": "<dateTime>",
    ;     "email_cc_ids": [
    ;       "<integer>",
    ;       "<integer>"
    ;     ],
    ;     "followup_source_id": "<integer>",
    ;     "group_id": "<integer>",
    ;     "id": "<integer>",
    ;     "is_public": "<boolean>",
    ;     "organization_id": "<integer>",
    ;     "priority": "<string>",
    ;     "recipient": "<string>",
    ;     "requester_id": "<integer>",
    ;     "solved": "<boolean>",
    ;     "status": "<string>",
    ;     "ticket_form_id": "<integer>",
    ;     "type": "<string>",
    ;     "updated_at": "<dateTime>",
    ;     "url": "<string>",
    ;     "via": {
    ;       "channel": "<string>",
    ;       "source": {
    ;         "est__": false
    ;       }
    ;     }
    ;   }
    ; }

    ; Sample code for parsing the JSON response...
    ; Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    strVal.s
    id.s
    value.s

    Subject.s = CkJsonObject::ckStringOf(jResp,"request.subject")
    Assignee_id.s = CkJsonObject::ckStringOf(jResp,"request.assignee_id")
    Can_be_solved_by_me.s = CkJsonObject::ckStringOf(jResp,"request.can_be_solved_by_me")
    Created_at.s = CkJsonObject::ckStringOf(jResp,"request.created_at")
    Custom_status_id.s = CkJsonObject::ckStringOf(jResp,"request.custom_status_id")
    Description.s = CkJsonObject::ckStringOf(jResp,"request.description")
    Due_at.s = CkJsonObject::ckStringOf(jResp,"request.due_at")
    Followup_source_id.s = CkJsonObject::ckStringOf(jResp,"request.followup_source_id")
    Group_id.s = CkJsonObject::ckStringOf(jResp,"request.group_id")
    Id.s = CkJsonObject::ckStringOf(jResp,"request.id")
    Is_public.s = CkJsonObject::ckStringOf(jResp,"request.is_public")
    Organization_id.s = CkJsonObject::ckStringOf(jResp,"request.organization_id")
    Priority.s = CkJsonObject::ckStringOf(jResp,"request.priority")
    Recipient.s = CkJsonObject::ckStringOf(jResp,"request.recipient")
    Requester_id.s = CkJsonObject::ckStringOf(jResp,"request.requester_id")
    Solved.s = CkJsonObject::ckStringOf(jResp,"request.solved")
    Status.s = CkJsonObject::ckStringOf(jResp,"request.status")
    Ticket_form_id.s = CkJsonObject::ckStringOf(jResp,"request.ticket_form_id")
    v_Type.s = CkJsonObject::ckStringOf(jResp,"request.type")
    Updated_at.s = CkJsonObject::ckStringOf(jResp,"request.updated_at")
    v_Url.s = CkJsonObject::ckStringOf(jResp,"request.url")
    Channel.s = CkJsonObject::ckStringOf(jResp,"request.via.channel")
    Est__.i = CkJsonObject::ckBoolOf(jResp,"request.via.source.est__")
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"request.collaborator_ids")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        strVal = CkJsonObject::ckStringOf(jResp,"request.collaborator_ids[i]")
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jResp,"request.custom_fields")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        id = CkJsonObject::ckStringOf(jResp,"request.custom_fields[i].id")
        value = CkJsonObject::ckStringOf(jResp,"request.custom_fields[i].value")
        i = i + 1
    Wend
    i = 0
    count_i = CkJsonObject::ckSizeOfArray(jResp,"request.email_cc_ids")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        strVal = CkJsonObject::ckStringOf(jResp,"request.email_cc_ids[i]")
        i = i + 1
    Wend


    CkHttp::ckDispose(http)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure

Curl Command

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

Postman Collection Item JSON

{
  "name": "Create Request",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/requests",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "requests"
      ]
    },
    "description": "Accepts a `request` object that sets one or more properties.\n\n#### Allowed for\n\n* End users\n* Anonymous users (rate limit of 5 requests per hour for [trial accounts](/documentation/developer-tools/getting-started/getting-a-trial-or-sponsored-account-for-development/))\n\n#### Additional properties\n\nIn addition to the writable request properties in the [JSON Format table](#json-format) above, you can set the following properties when creating a request.\n\n| Name                | Type   | Mandatory | Comment\n| ----------------    | -------| --------- | -------\n| comment             | object | yes       | Describes the problem, incident, question, or task. See [Request comments](#request-comments)\n| collaborators       | array  | no        | Adds collaborators (cc's) to the request. An email notification is sent to them when the ticket is created. See [Setting collaborators](/documentation/ticketing/managing-tickets/creating-and-managing-requests#setting-collaborators)\n| requester           | object | yes*      | \\*Required for anonymous requests. Specifies the requester of the anonymous request. See [Creating anonymous requests](/documentation/ticketing/managing-tickets/creating-and-managing-requests#creating-anonymous-requests)\n\n#### Creating follow-up requests\n\nOnce a ticket is closed (as distinct from solved), it can't be reopened. However, you can create a new request that references the closed ticket. To create the follow-up request, include a `via_followup_source_id` property in the `request` object that specifies the closed ticket. The parameter only works with closed tickets. It has no effect with other tickets.\n"
  },
  "response": [
    {
      "name": "Created response",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/requests",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "requests"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"request\": {\n    \"subject\": \"<string>\",\n    \"assignee_id\": \"<integer>\",\n    \"can_be_solved_by_me\": \"<boolean>\",\n    \"collaborator_ids\": [\n      \"<integer>\",\n      \"<integer>\"\n    ],\n    \"created_at\": \"<dateTime>\",\n    \"custom_fields\": [\n      {\n        \"id\": \"<integer>\",\n        \"value\": \"<string>\"\n      },\n      {\n        \"id\": \"<integer>\",\n        \"value\": \"<string>\"\n      }\n    ],\n    \"custom_status_id\": \"<integer>\",\n    \"description\": \"<string>\",\n    \"due_at\": \"<dateTime>\",\n    \"email_cc_ids\": [\n      \"<integer>\",\n      \"<integer>\"\n    ],\n    \"followup_source_id\": \"<integer>\",\n    \"group_id\": \"<integer>\",\n    \"id\": \"<integer>\",\n    \"is_public\": \"<boolean>\",\n    \"organization_id\": \"<integer>\",\n    \"priority\": \"<string>\",\n    \"recipient\": \"<string>\",\n    \"requester_id\": \"<integer>\",\n    \"solved\": \"<boolean>\",\n    \"status\": \"<string>\",\n    \"ticket_form_id\": \"<integer>\",\n    \"type\": \"<string>\",\n    \"updated_at\": \"<dateTime>\",\n    \"url\": \"<string>\",\n    \"via\": {\n      \"channel\": \"<string>\",\n      \"source\": {\n        \"est__\": false\n      }\n    }\n  }\n}"
    }
  ]
}