Chilkat Online Tools

Java / Support API / Create Ticket Form

Back to Collection Items

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttp http = new CkHttp();
    boolean success;

    http.put_BasicAuth(true);
    http.put_Login("login");
    http.put_Password("password");

    http.SetRequestHeader("Accept","application/json");

    CkHttpResponse resp = http.QuickRequest("POST","https://example.zendesk.com/api/v2/ticket_forms");
    if (http.get_LastMethodSuccess() == false) {
        System.out.println(http.lastErrorText());
        return;
        }

    CkStringBuilder sbResponseBody = new CkStringBuilder();
    resp.GetBodySb(sbResponseBody);

    CkJsonObject jResp = new CkJsonObject();
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    System.out.println("Response Body:");
    System.out.println(jResp.emit());

    int respStatusCode = resp.get_StatusCode();
    System.out.println("Response Status Code = " + respStatusCode);
    if (respStatusCode >= 400) {
        System.out.println("Response Header:");
        System.out.println(resp.header());
        System.out.println("Failed.");

        return;
        }

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

    // {
    //   "ticket_form": {
    //     "name": "<string>",
    //     "active": "<boolean>",
    //     "agent_conditions": [
    //       {
    //         "aliqua6": "proident deserunt",
    //         "Lorem_d": "cillum dolor Excepteur ut",
    //         "mollit_cf": -33059877,
    //         "ullamco_f7": "dolore occaeca"
    //       },
    //       {
    //         "consequate_": 29214347.18513973,
    //         "consectetur_00": 83697330,
    //         "laborum50": "cillum Ut"
    //       }
    //     ],
    //     "created_at": "<dateTime>",
    //     "default": "<boolean>",
    //     "display_name": "<string>",
    //     "end_user_conditions": [
    //       {
    //         "irure__c": false,
    //         "Excepteur_38": -15203265.607602075,
    //         "sunt_8": "culpa laboris Ut"
    //       },
    //       {
    //         "nulla_48": "quis esse",
    //         "ullamco_f6": -25516091.19614251
    //       }
    //     ],
    //     "end_user_visible": "<boolean>",
    //     "id": "<integer>",
    //     "in_all_brands": "<boolean>",
    //     "position": "<integer>",
    //     "raw_display_name": "<string>",
    //     "raw_name": "<string>",
    //     "restricted_brand_ids": [
    //       "<integer>",
    //       "<integer>"
    //     ],
    //     "ticket_field_ids": [
    //       "<integer>",
    //       "<integer>"
    //     ],
    //     "updated_at": "<dateTime>",
    //     "url": "<string>"
    //   }
    // }

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

    String aliqua6;
    String Lorem_d;
    int mollit_cf;
    String ullamco_f7;
    String consequate_;
    int consectetur_00;
    String laborum50;
    boolean irure__c;
    String Excepteur_38;
    String sunt_8;
    String nulla_48;
    String ullamco_f6;
    String strVal;

    String Name = jResp.stringOf("ticket_form.name");
    String Active = jResp.stringOf("ticket_form.active");
    String Created_at = jResp.stringOf("ticket_form.created_at");
    String Default = jResp.stringOf("ticket_form.default");
    String Display_name = jResp.stringOf("ticket_form.display_name");
    String End_user_visible = jResp.stringOf("ticket_form.end_user_visible");
    String Id = jResp.stringOf("ticket_form.id");
    String In_all_brands = jResp.stringOf("ticket_form.in_all_brands");
    String Position = jResp.stringOf("ticket_form.position");
    String Raw_display_name = jResp.stringOf("ticket_form.raw_display_name");
    String Raw_name = jResp.stringOf("ticket_form.raw_name");
    String Updated_at = jResp.stringOf("ticket_form.updated_at");
    String v_Url = jResp.stringOf("ticket_form.url");
    int i = 0;
    int count_i = jResp.SizeOfArray("ticket_form.agent_conditions");
    while (i < count_i) {
        jResp.put_I(i);
        aliqua6 = jResp.stringOf("ticket_form.agent_conditions[i].aliqua6");
        Lorem_d = jResp.stringOf("ticket_form.agent_conditions[i].Lorem_d");
        mollit_cf = jResp.IntOf("ticket_form.agent_conditions[i].mollit_cf");
        ullamco_f7 = jResp.stringOf("ticket_form.agent_conditions[i].ullamco_f7");
        consequate_ = jResp.stringOf("ticket_form.agent_conditions[i].consequate_");
        consectetur_00 = jResp.IntOf("ticket_form.agent_conditions[i].consectetur_00");
        laborum50 = jResp.stringOf("ticket_form.agent_conditions[i].laborum50");
        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("ticket_form.end_user_conditions");
    while (i < count_i) {
        jResp.put_I(i);
        irure__c = jResp.BoolOf("ticket_form.end_user_conditions[i].irure__c");
        Excepteur_38 = jResp.stringOf("ticket_form.end_user_conditions[i].Excepteur_38");
        sunt_8 = jResp.stringOf("ticket_form.end_user_conditions[i].sunt_8");
        nulla_48 = jResp.stringOf("ticket_form.end_user_conditions[i].nulla_48");
        ullamco_f6 = jResp.stringOf("ticket_form.end_user_conditions[i].ullamco_f6");
        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("ticket_form.restricted_brand_ids");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("ticket_form.restricted_brand_ids[i]");
        i = i+1;
        }

    i = 0;
    count_i = jResp.SizeOfArray("ticket_form.ticket_field_ids");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("ticket_form.ticket_field_ids[i]");
        i = i+1;
        }
  }
}

Curl Command

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

Postman Collection Item JSON

{
  "name": "Create Ticket Form",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/ticket_forms",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "ticket_forms"
      ]
    },
    "description": "#### Allowed For\n\n* Admins\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/ticket_forms",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "ticket_forms"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"ticket_form\": {\n    \"name\": \"<string>\",\n    \"active\": \"<boolean>\",\n    \"agent_conditions\": [\n      {\n        \"aliqua6\": \"proident deserunt\",\n        \"Lorem_d\": \"cillum dolor Excepteur ut\",\n        \"mollit_cf\": -33059877,\n        \"ullamco_f7\": \"dolore occaeca\"\n      },\n      {\n        \"consequate_\": 29214347.18513973,\n        \"consectetur_00\": 83697330,\n        \"laborum50\": \"cillum Ut\"\n      }\n    ],\n    \"created_at\": \"<dateTime>\",\n    \"default\": \"<boolean>\",\n    \"display_name\": \"<string>\",\n    \"end_user_conditions\": [\n      {\n        \"irure__c\": false,\n        \"Excepteur_38\": -15203265.607602075,\n        \"sunt_8\": \"culpa laboris Ut\"\n      },\n      {\n        \"nulla_48\": \"quis esse\",\n        \"ullamco_f6\": -25516091.19614251\n      }\n    ],\n    \"end_user_visible\": \"<boolean>\",\n    \"id\": \"<integer>\",\n    \"in_all_brands\": \"<boolean>\",\n    \"position\": \"<integer>\",\n    \"raw_display_name\": \"<string>\",\n    \"raw_name\": \"<string>\",\n    \"restricted_brand_ids\": [\n      \"<integer>\",\n      \"<integer>\"\n    ],\n    \"ticket_field_ids\": [\n      \"<integer>\",\n      \"<integer>\"\n    ],\n    \"updated_at\": \"<dateTime>\",\n    \"url\": \"<string>\"\n  }\n}"
    }
  ]
}