If you have added custom fields to your ticket form and you wish to create or update tickets with values for those custom fields via API, you landed up in a right place to know how to do.


Say, you want to update value for the custom field which goes by the label Weapon in your ticket form


Note: API_KEY and domain.freshdesk.com in curl command should be replaced by your API key and your domain url respectively.


STEP 1 : To get the name of the custom field.


To get the name of the custom field Weapon, the following API call would help you.

This API will list all the ticket fields both default (like status, requester email, priority, etc.) and custom.


Request uri: http://domain.freshdesk.com/ticket_fields.json

Request Method: GET


Sample Code:   

curl -u API_KEY:X -H "Content-Type: application/json" -X GET http://domain.freshdesk.com/ticket_fields.json

    

Sample Response: 

[
    {
        "ticket_field": {
            "active": true,
            "created_at": "2013-12-11T18:39:01+05:30",
            "description": "",
            "editable_in_portal": false,
            "field_options": null,
            "field_type": "custom_text",
            "flexifield_def_entry_id": 1,
            "id": 11,
            "label": "Weapon",
            "label_in_portal": "Weapon",
            "name": "weapon_1",
            "position":2,"required": false,
            "required_for_closure": false,
            "required_in_portal": false,
            "updated_at": "2014-01-30T16:20:01+05:30",
            "visible_in_portal": true,
            "choices": [],
            "nested_ticket_fields": []
        }
    },
    {
        "ticket_field": {
            "active": true,
            "created_at": "2013-12-11T18:11:30+05:30",
            "description": "Ticket requester",
            "editable_in_portal": true,
            "field_options": {
                "portalcc": false,
                "portalcc_to": "company"
            },
            "field_type": "default_requester",
            "flexifield_def_entry_id": null,
            "id": 1,
            "label": "Search a requester",
            "label_in_portal": "Requester",
            "name": "requester",
            "position": 1,
            "required": true,
            "required_for_closure": false,
            "required_in_portal": true,
            "updated_at": "2013-12-11T18:39:01+05:30",
            "visible_in_portal": true,
            "choices": [],
            "nested_ticket_fields": []
        }
    }
]

  

You can filter the ticket field which has label tag as Weapon. In the above example, the name of our custom field is weapon_1.


STEP 2a : Create ticket with custom fields


Request uri: http://domain.freshdesk.com/helpdesk/tickets.json

Request Method: POST 

 

Sample Code:  

curl -u API_KEY:X -H "Content-Type: application/json" -d '{ "helpdesk_ticket": { "description": "Details about the issue...", "subject": "Support Needed...", "email": "tom@outerspace.com", "priority": 1, "status": 2, "custom_field": { "weapon_1": "Laser Gun"} },  "cc_emails":"ram@freshdesk.com, diana@freshdesk.com" }' -X POST http://domain.freshdesk.com/helpdesk/tickets.json

    

Sample Repsonse: 

{
  "helpdesk_ticket" : {
    "cc_email" : {
      "cc_emails" : [
        "ram@freshdesk.com",
        "diana@freshdesk.com"
      ],
      "fwd_emails" : [ ]
    },
    "created_at" : "2014-01-07T18:48:33+05:30",
    "deleted" : false,
    "delta" : true,
    "description" : "Some details on the...",
    "description_html" : "<div>Some details on the...</div>",
    "display_id" : 141,
    "due_by" : "2014-01-10T17:00:00+05:30",
    "email_config_id" : null,
    "frDueBy" : "2014-01-08T17:00:00+05:30",
    "fr_escalated" : false,
    "group_id" : null,
    "id" : 141,
    "isescalated" : false,
    "notes" : [ ],
    "owner_id" : null,
    "priority" : 1,
    "requester_id" : 18,
    "responder_id" : null,
    "source" : 2,
    "spam" : false,
    "status" : 2,
    "subject" : "Support needed..",
    "ticket_type" : "Question",
    "to_email" : null,
    "trained" : false,
    "updated_at" : "2014-01-07T18:48:33+05:30",
    "urgent" : false,
    "status_name" : "Open",
    "requester_status_name" : "Being Processed",
    "priority_name" : "Low",
    "source_name" : "Portal",
    "requester_name" : "tom",
    "responder_name" : "No Agent",
    "product_id" : 123456,
    "to_emails" : null,
    "custom_field" : {
      "weapon_1" : "Laser Gun"
    },
    "attachments" : [ ]
    "tags":[]
  }
}

 

STEP 2b : Update ticket with custom fields


Request uri: http://domain.freshdesk.com/helpdesk/tickets/[id].json

Request Method: PUT

 

Sample Code:    

curl -u API_KEY:X -H "Content-Type: application/json" -X PUT -d '{ "helpdesk_ticket": { "priority":1, "status":2, "custom_field": {"weapon_1": "Laser Gun"} }}' http://domain.freshdesk.com/helpdesk/tickets/1.json

     

Sample Response:

{
  "ticket" : {
    "deleted" : false,
    "display_id" : 1,
    "subject" : "freshdesk test",
    "status_name" : "Pending",
    "requester_status_name" : "Awaiting your Reply",
    "priority_name" : "High",
    "source_name" : "Portal",
    "requester_name" : "freshdesk",
    "responder_name" : "Support",
    "to_emails" : null
  }
}