Creating a ticket with extra fields through the API | Community
Skip to main content

Creating a ticket with extra fields through the API

  • November 1, 2018
  • 6 replies
  • 0 views

Ok ive got some servers that dont really give me good info for reports etc.

Now ive realised i have to create custom fields then get the server to fill them so i get the info i need. So i decided to run a test to get me started

I used powershell on my machine as i cant mess about on the servers willy nilly. and sent this command

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

Invoke-WebRequest : Parameter cannot be processed because the parameter name 'u' is ambiguous. Possible matches include: -UseBasicParsing -Uri -UseDefaultCredentials -UserAgent. At line:1 char:170 + ... ody": "My printer is on fire!", "uploads": [...] }}}' \ -v -u simple- ... + ~~ + CategoryInfo : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException + FullyQualifiedErrorId : AmbiguousParameter,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

But i get the error? can anyone throw some light on what im doing wrong?

The snippet is from here https://developer.zendesk.com/rest_api/docs/core/requests#create-request

.

What im trying to get to is a message that i can add other fields to be filled in on the tickets once i get this working.

This topic has been closed for replies.

6 replies

  • Author
  • November 5, 2018

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?

 


  • November 5, 2018

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!


  • Author
  • November 6, 2018

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?


  • November 6, 2018

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"


  • Author
  • November 7, 2018

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?


  • November 14, 2018

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