Creating a ticket with extra fields through the API

6 Comments

  • Jeremy Heath

    Ok ive managed to get this working but the part im not understanding is it will not let me add any extra sections or info

    If i try and change the Type field for e.g. it never appears in the ticket

    Im using the method from the original post , "type": "problem" 

    any help?

     

    0
  • Andrew Dietrich

    Hi Jeremy,


    I've taken a look at some logs of the requests you are sending in and it looks like you are sending in a lot of this information, such as the ticket type and custom fields, within the comment object. The comment object should only contain the body and any uploads.

    I am also seeing that with custom fields you are referring to the fields via their title, not their field ID. Please see the examples here:

    https://developer.zendesk.com/rest_api/docs/core/tickets#setting-custom-field-values

    Hope this helps!

    0
  • Jeremy Heath

    Hi Andrew 

    Are uploads attachments to the post?

     

    The main issue im having is where to place the section you mention for e.g

    "custom_fields": [{"id": 21938362, "value": "hd_3000"}]

    where does it fit within the code i posted?Ive tried moving it into other sections , in between brackets, further to the front but i cant get it to work.

     

    where should it be added?

    0
  • Andrew Dietrich

    Hi Jeremy,

    Yep, uploads are attached files.


    The custom fields array can be placed anywhere in the ticket/request object, as long as it's not contained within anything else (i.e. it needs to be on the "top level"). So you could do something like this:

     

    curl https://****.zendesk.com/api/v2/requests.json \ -d '{"request": { "custom_fields": [{"id": 21938362, "value": "hd_3000"}],  "subject": "Help!" , "comment": {"body": "My printer is on fire!", "uploads": [...] }}}' \ -v -u *****/token:************* -X POST -H "Content-Type: application/json"

    0
  • Jeremy Heath

    Hi there

    Right this is what i tried before in my test attempts but it fails

    curl https://**********.zendesk.com/api/v2/requests.json -d '{"request": { "custom_fields": [{"id": 360005187612, "value": "Problems"}], {"subject": "Help!", "comment": {"body": "My printer is on fire!"}}}' -v -u ********/token:********** -X POST -H "Content-Type: application/json" 

    Now that is aimed at the Type field which should work as its a standard field.

    HttpOnly
    < expect-ct: max-age=604800, report-uri="https://report-*******expect-ct"
    < server: cloudflare
    < cf-ray: 475eec535a5d6b6d-LHR
    <
    * Connection #0 to host d*******.zendesk.com left intact
    {"error":"Unprocessable Entity","message":"Server could not parse JSON"}

    Thats the last bit of the error i get from the bash terminal

    I tried with a field i had created for testing and i get the same error

    Everytime i change the line of code i get the error

    Any thoughts?

    0
  • Andrew Dietrich

    Hi Jeremy,


    Looks like you added an extra { bracket before subject. Subject should be contained directly within the request object, so you can just delete it and the JSON should be parsable now.


    You can use this site to validate your JSON:

    https://jsonlint.com

    0

Please sign in to leave a comment.

Powered by Zendesk