If you have a ticket form with custom fields in them, you can create or update tickets with value for those custom fields - entirely via APIs. Say, you want to update value for the custom field which goes by the label Gadget in your ticket form, then follow the steps below. Replace API_KEY and domain.freshdesk.com wherever it occurs with your API key and domain URL respectively.

Step 1: Get the name of the Custom Field

To get the name of the custom field Gadget, use the following API call. This API will list all the ticket fields - both default (like status, requester email, priority, etc.) and custom.
Request URI: https://domain.freshdesk.com/api/v2/ticket_fields 

Request Method: GET


Sample Code:
 

 

curl -u API_KEY:X -X GET https://domain.freshdesk.com/api/v2/ticket_fields

   

Sample Response:      

 

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

 

[
  {
    "id": 13,
    "default": false,
    "description": "",
    "label": "gadget",
    "name": "gadget",
    "position": 1,
    "required_for_closure": false,
    "type": "custom_text",
    "required_for_agents": false,
    "required_for_customers": false,
    "label_for_customers": "gadget",
    "customers_can_edit": true,
    "displayed_to_customers": true,
    "created_at": "2016-02-05T13:35:39Z",
    "updated_at": "2016-02-05T13:35:39Z"
  },
  {
    "id": 1,
    "default": true,
    "description": "Ticket requester",
    "label": "Search a requester",
    "name": "requester",
    "position": 4,
    "required_for_closure": false,
    "portal_cc": false,
    "portal_cc_to": "company",
    "type": "default_requester",
    "required_for_agents": true,
    "required_for_customers": true,
    "label_for_customers": "Requester",
    "customers_can_edit": true,
    "displayed_to_customers": true,
    "created_at": "2016-01-04T09:19:43Z",
    "updated_at": "2016-02-05T13:35:40Z"
  },
  {
    "id": 2,
    "default": true,
    "description": "Ticket subject",
    "label": "Subject",
    "name": "subject",
    "position": 5,
    "required_for_closure": false,
    "type": "default_subject",
    "required_for_agents": true,
    "required_for_customers": true,
    "label_for_customers": "Subject",
    "customers_can_edit": true,
    "displayed_to_customers": true,
    "created_at": "2016-01-04T09:19:43Z",
    "updated_at": "2016-02-05T13:35:40Z"
  },
]

  

Step 2: Create tickets with custom fields

Request uri: https://domain.freshdesk.com/api/v2/tickets

Request Method: POST


 

Sample Code: 

 

curl -u API_KEY:X -H "Content-Type: application/json" -X POST -d '{ "description": "Details about the issue...", "subject": "Support Needed...", "email": "tom@outerspace.com", "priority": 1, "status": 2, "cc_emails": ["ram@freshdesk.com","diana@freshdesk.com"], "custom_fields" : { "gadget": "Cold Welder"} }' 'https://domain.freshdesk.com/api/v2/tickets'

 

Sample Response:

 

{
  "cc_emails":[
    "ram@freshdesk.com",
    "diana@freshdesk.com"
  ],
  "fwd_emails":[ ],
  "reply_cc_emails":[ ],
  "description":"Details about the issue...",
  "description_html":"
Details about the issue\u2026
",   "fr_escalated":false,   "spam":false,   "email_config_id":null,   "group_id":null,   "priority":1,   "requester_id":119,   "responder_id":null,   "source":2,   "status":2,   "subject":"Support Needed...",   "custom_fields":{       "gadget":"Cold Welder"   },   "to_emails":null,   "product_id":null,   "id":8,   "type":null,   "created_at":"2016-02-05T13:44:35Z",   "updated_at":"2016-02-05T13:44:35Z",   "due_by":"2016-02-10T11:30:00Z",   "fr_due_by":"2016-02-08T11:30:00Z",   "is_escalated":false,   "tags":[ ],   "attachments":[ ] }

 

STEP 3: Update ticket with custom fields
 
Request uri: https://domain.freshdesk.com/api/v2/tickets/[id] 

Request Method: PUT

 

Sample Code: 

 

curl -u API_KEY:X -H "Content-Type: application/json" -X PUT -d '{ "subject": "Support Required", "priority": 2, "custom_fields" : { "gadget": "Plasma Cutter"} } 'https://domain.freshdesk.com/api/v2/tickets/8

   

Sample Response:
 

 

{
  "cc_emails":[
    "ram@freshdesk.com",
    "diana@freshdesk.com"
  ],
  "fwd_emails":[ ],
  "reply_cc_emails":[ ],
  "description":"Details about the issue...",
  "description_html":"
Details about the issue\u2026
",   "fr_escalated":false,   "spam":false,   "email_config_id":null,   "group_id":null,   "priority":2,   "requester_id":119,   "responder_id":null,   "source":2,   "status":2,   "subject":"Support Required",   "custom_fields":{       "gadget":"Plasma Cutter"   },   "to_emails":null,   "product_id":null,   "id":8,   "type":null,   "created_at":"2016-02-05T13:44:35Z",   "updated_at":"2016-02-05T13:44:35Z",   "due_by":"2016-02-10T11:30:00Z",   "fr_due_by":"2016-02-08T11:30:00Z",   "is_escalated":false,   "tags":[ ],   "attachments":[ ] }


NOTE 1: (This applies only for ticket custom_fields and not for contact/company custom_fields)

Names of custom fields are derived from the labels given to them during creation. If you create a custom field with the label 'test', then the name of the custom_field will be 'cf_test'. All custom fields will have 'cf_' prepended to its name.


NOTE 2: All API calls are dependent on the Name of the custom field and not its Label.