title: How to use Freshdesk API to create a new ticket with custom fields using javascript
body: <p>I have a function that is fired when the user clicks "submit" on a form.  Everything will get submitted to freshdesk except for <strong>custom_fields</strong>.</p>
  
  <p>I'm using Angular 1.4 with controller so ctrl is my controller.  Here's my code:</p>
  
  <pre><code>   function postTicket() {
    var formdata = new FormData();
  
    var customFields = {
      "serial_number": ctrl.newTicket.serialnumber
    };
    customFields = JSON.stringify(customFields);
  
  
    formdata.append('description', ctrl.newTicket.description);
    formdata.append('subject', ctrl.newTicket.subject);
    formdata.append('type', ctrl.newTicket.type);
    formdata.append('email', ctrl.newTicket.email);
    formdata.append('custom_fields', customFields);
    formdata.append('status', 2); // open
    formdata.append('priority', 1); // low
  
    supportResource.postTicket(formdata).then(
      results =&gt; {
        console.log('it worked! ', results);
        ctrl.formSent = true;
      },
      error =&gt; {
        console.log('something went wrong. ', error);
      });
  }
  </code></pre>
  
  <p>and here's the supportResource code:</p>
  
  <pre><code>function postTicket(ticket) {
    return $q(function(fulfill, reject) {
      $http({
        url: `https://${MYACCOUNT}.freshdesk.com/api/v2/tickets`,
        method: 'POST',
        headers: {
          'Authorization': 'Basic ' + btoa(MYKEY),
          'Content-Type': undefined
        },
        data: ticket
      }).then(
        results =&gt; {
          fulfill(results.data);
        },
        error =&gt; reject(error));
    });
  }
  </code></pre>
  
  <p>I get back the following error: "Value set is of type String.It should be a/an key/value pair"
  <a href="https://i.stack.imgur.com/mZ7v1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mZ7v1.png" alt="enter image description here"></a></p>
  
  <p>I have followed the example from here: 
  <a href="https://github.com/freshdesk/fresh-samples/blob/master/jquery/create_ticket_with_attachment.html" rel="nofollow noreferrer">https://github.com/freshdesk/fresh-samples/blob/master/jquery/create_ticket_with_attachment.html</a></p>
  
  <p>and also I see this: <a href="https://support.freshdesk.com/support/solutions/articles/216548-create-and-update-tickets-with-custom-fields-using-api" rel="nofollow noreferrer">https://support.freshdesk.com/support/solutions/articles/216548-create-and-update-tickets-with-custom-fields-using-api</a></p>
  
  <p>but this example is using CURL, I'm not sure how to send the data using FormData() <a href="http://developer.mozilla.org/en-US/docs/Web/API/FormData" rel="nofollow noreferrer">http://developer.mozilla.org/en-US/docs/Web/API/FormData</a> </p>