json for attachments (requests api) | Community
Skip to main content

json for attachments (requests api)

  • October 23, 2019
  • 2 replies
  • 0 views

 

 


I've got a nearly complete demo for our Maintenance team, consisting of a web front end to create work orders, which uses the "Requests" API to create tickets in Zendesk.

The last bit I can't figure out is how to attach a photo, can you help me out with this CURL statement? It does work correctly on Windows, a ticket gets created on the helpdesk, but there is no photo attached, and nothing in the CURL response to indicate error in any way

curl https://MySiteHere.zendesk.com/api/v2/requests.json -u my.email@address.com/token:MyApiKeyHere -H "Content-Type: application/json" -v -X POST -d "{\"request\":{\"subject\":\"testing attachments\",\"priority\":\"low\",\"recipient\":\"my.email@address.com/\",\"comment\":{\"body\":\"testing attachments\",\"upload\":\"c:\test.jpg\"}}}"

If you can help me out with a sample for attaching files to a customer request that would be amazing, i can translate from Linux to windows if required, just can't find sample code online.

Cheers!

This topic has been closed for replies.

2 replies

  • Author
  • October 28, 2019

Thanks Thomas, that's perfect, I was able to port to Windows with one bit of functionality missing - inside zendesk tickets the link to attachment is named correctly but downloads a 10-byte file with the contents "ata-binary" I've checked that the token i'm referencing during ticket creation is the one being returned via the uploads api. Got any idea what I'm missing? 


  • Author
  • November 4, 2019

Hey Thomas, thanks again for your help, the double-dash prefix for "data-binary" got this working with CURL on Windows, thanks for your help, here's the code i'm using:

create the upload:

curl.exe https://fixhbb.zendesk.com/api/v2/uploads.json?filename="descriptive name" -v -u my.email@place.com/token:0a0a0a00a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0 -H "Content-Type: application/binary" --data-binary @"c:\test.jpg" -X POST

get back the token:

{"upload":{"token":"LwCInHodcDmFTWMizIlhOQj4c" ........

create ticket via Request API, attach the upload via it's token:
curl https://fixhbb.zendesk.com/api/v2/requests.json -u my.email@place.com/token:0a0a0a00a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0 -H "Content-Type: application/json" -v -X POST -d "{\"request\":{\"subject\":\"testing attachments\",\"priority\":\"low\",\"recipient\":\"my.email@place.com\",\"comment\":{\"body\":\"testing attachments\",\"uploads\":[\"LwCInHodcDmFTWMizIlhOQj4c\"]}}}"