Type/Priority/Custom fields not set when creating request

Answered


Posted Aug 03, 2022

I'm attempting to add some custom fields to our tickets (both Text) when created through the requests API.
I'm POSTing the following data (from Javascript) to https://oursite.zendesk.com/api/v2/requests.json

{
request:{
type: 'incident',
priority: 'high',
requester:{name:'John Doe',email:'john.doe@email.com'},
subject: 'Something bad happened!',
comment:{
body: 'Can you look into this?',
},
custom_fields: [
{ id: 8296782846740, value: 'custom 1'},
{ id: 8296695964692, value: 'custom 2'},
]
}
}

The requester, subject, and comment all show up on the ticket fine, but the type, priority, and custom fields are not being set (they just become the defaults, which in this case is low for priorty, not set for type, and the custom fields are empty)

I'm referencing the Create Request documentation, and I think that should be the right format?


0

3

3 comments

Ahmed Zaid
That was it! Those fields populate correctly now. Thanks!
We don't want these custom fields showing up to the user when submitting a request though, so I'll look into other ways of adding the info (possible adding an internal note)

0


CJ Johnson Thanks for the reply!
Sorry, I should have clarified, this is a Javascript object that's converted to JSON eventually by our request handler (hence no quotes on keys; single quotes are just the codebase style)
This is the JSON data being sent out:

{
  "request": {
    "type": "incident",
    "priority": "high",
    "custom_fields": [
      {
        "id": 8296782846740,
        "value": "custom 1"
      },
      {
        "id": 8296695964692,
        "value": "custom 2'"
      }
    ],
    "requester": {
      "name": "John Doe",
      "email": "john.doe@email.com"
    },
    "subject": "Something bad happened!",
    "comment": {
      "body": "Can you look into this?"
    }
  }
}

0


This endpoint is a real pain about not telling you when things aren't formatted the way it needs. You will need to add quotes to a lot of places to get this to work, and change some of your single quotes, to doubles. Try this: 

{
"request":{
    "type": "incident",
    "priority": "high",
    "requester":{"name":"John Doe","email":"john.doe@email.com"},
    "subject": "Something bad happened!",
    "comment":{
        "body": "Can you look into this?",
        },
    "custom_fields": [
        { "id": "8296782846740", "value": "custom 1"},
        { "id": "8296695964692", "value": "custom 2"},
    ]
}

To figure out if you have syntax issues, I recommend the free products Sublime, or Visual Studio, which let you paste in code, and tell it what flavor it is, and then it highlights any problems: 

Additionally, Postman, a GUI interface for interacting with APIs, has a built in syntax checker that has helped me find stray commas and the like before I send, all the time.  That can make it a little quicker/easier to deal with the API returning a syntax error, because the sending/checking/receiving it all in the same window: 

0


Sign in to leave a comment.

Didn't find what you're looking for?

New post