Recent searches


No recent searches

Image upload via upload api



Posted Sep 28, 2021

My requirement is to give customer option to upload image & this image needs to be send to zen desk. Do I need to upload the image on some server before using the upload function of zen desk.

Following is the code i m trying, but its not working

$uri = 'https://company.zendesk.com/api/v2/uploads.json?filename=image.jpg';
$target_file = $_FILES['file']['tmp_name'];
$fildata = file_get_contents($_FILES["fileToUpload"]["tmp_name"]);
$ch = curl_init();

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_USERPWD, "xxxx@test.com/token:xxxxx");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/binary'));
curl_setopt($ch, CURLOPT_POST, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, $fildata);
curl_setopt($ch, CURLOPT_INFILE, $file);
curl_setopt($ch, CURLOPT_INFILESIZE, $size);
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_VERBOSE, true);
$output = curl_exec($ch);

 


0

5

5 comments

image avatar

Eric Nelson

Zendesk Developer Advocacy

Hey Shweta,

If you go to the admin panel then down to settings/customers do you see that 'Require authentication for request and uploads APIs' is enabled?

Thanks!

Have a wonderful day!

Eric Nelson | Manager - Developer Advocacy

0


Hi I am also facing same problem.Can you send screen shot of this so that i can use upload api  for image uploading?

Regards,

Awaiting for your nice response.

0


image avatar

Eric Nelson

Zendesk Developer Advocacy

Hey Lisa,

Are you looking for a screenshot of where the setting is in your Zendesk interface?

Have a wonderful day!

Eric Nelson | Manager - Developer Advocacy

0


Hi Eric,

The setting is unticked for now. My understanding is it has to be unticked only.

Thanks

0


This is the only thing that would work for me. If i didn't do it like this, a blank image was appearing in the response:

$fileName = 'test.png';
$filePath = 'test.png';

$url = 'https://test.zendesk.com/api/v2/uploads.json?filename=' . urlencode($fileName);
$file = fopen($filePath, "r");
$mimeContentType = mime_content_type($file);
$size = filesize($filePath);


$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,true);
curl_setopt($ch, CURLOPT_POST ,true);
curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($filePath));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: {$mimeContentType}"));
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_USERPWD, "test@test.com/token:XXXXXXXXXXXXXXXXXXX");
$output = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
fclose($file);
curl_close($ch);

0


Please sign in to leave a comment.

Didn't find what you're looking for?

New post