Skip to content

Conversation

@vbuck
Copy link
Contributor

@vbuck vbuck commented Jan 13, 2015

When using endpoints like POST /api/v2/uploads.json where binary data is transferred in the request body, we need to extend the abstract class to allow for such non-JSON data. We also need a means for setting the content-type associated with the transfer, which this update provides.

For backwards compatibility, these additions will fall back to their previous implementation (JSON-specific) when not used.

As a side-effect, this caused logging errors because of non UTF-8 characters in the request body. So that also needed to be accounted for.

With this update, it's now possible to use the attachments resource in the following way:

$extendingClass->_call(
  'uploads.json',
  array('filename' => $name, 'token' => $token),
  'POST',
  file_get_contents($someImage),
  array('Content-Type' => 'image/png')
);

Ref: https://developer.zendesk.com/rest_api/docs/core/attachments#uploading-files

…data, prevent exceptions caused by logging non UTF-8 data
@jwswj
Copy link
Contributor

jwswj commented Jan 20, 2015

This looks fine. What are you using the uploads API for?

@vbuck
Copy link
Contributor Author

vbuck commented Jan 20, 2015

I'm building an import tool to migrate data from an existing support ticket platform (Magento extension) to Zendesk. So part of the import process involves transferring attachments to obtain upload tokens which are added to the request bodies bound for imports/tickets.json.

@jwswj
Copy link
Contributor

jwswj commented Jan 22, 2015

Cool - would love to hear more about the tool. Email me jsmale@zendesk.com 👍

jwswj pushed a commit that referenced this pull request Jan 22, 2015
Add headers param to API calls, auto-detect JSON for encoding to raw data, prevent exceptions caused by logging non UTF-8 data
@jwswj jwswj merged commit 7a2353d into agnostack:master Jan 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants