Operation Cannot consume content type is not supported. when trying to upload a file to sandbox-quickbooks.api.intuit.com - quickbooks

We are making a POST to
sandbox-quickbooks.api.intuit.com/v3/company/{realm_id}/attachable
with header:
Content-Type: multipart/form-data; boundary="--fdlkjflksd--"
and body:
--fdlkjflksd--
Content-Disposition: form-data; name="file_metadata_01"; filename="attachment.json"
Content-Type: application/json; charset=UTF-8
Content-Transfer-Encoding: 8bit
{"AttachableRef": [{"EntityRef": {"type": "Purchase", "value": "144"}}], "FileName": "one_pixel.jpeg", "ContentType": "image/jpeg"}
--fdlkjflksd--
Content-Disposition: form-data; name="file_content_01"; filename="one_pixel.jpeg"
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
/9j/2wBDAP//////////////////////////////////////////////////////////////////////////////////////wAALCAABAAEBAREA/8QAFAABAAAAAAAAAAAAAAAAAAAAA//EABQQAQAAAAAAAAAAAAAAAAAAAAD/2gAIAQEAAD8AN//Z
--fdlkjflksd--
and we are getting in response:
{"Fault":{"Error":[{"Message":"Unsupported Operation","Detail":"Operation Cannot consume content type is not supported.","code":"500"}],"type":"ValidationFault"},"time":"2020-03-07T03:00:51.600-08:00"}
we followed this example

The /attachable endpoint is for linking EXISTING attachments to an object, and the Content-Type is:
application/json
Docs are here: https://developer.intuit.com/app/developer/qbo/docs/develop/tutorials/attach-images-and-notes#attaching-a-note-to-an-object
The /upload endpoint is for uploading NEW attachments, and the Content-Type is:
multipart/form-data
Docs: https://developer.intuit.com/app/developer/qbo/docs/develop/tutorials/attach-images-and-notes#uploading-files-to-the-attachment-list
It looks like you've mixed then up - it looks like you're trying to upload a new file to the existing file endpoint.

Related

Cannot exchange authorization code for long-lived access token with SurveyMonkey API

I've got the initial half of an OAuth flow working with the SurveyMonkey API, but when I try to exchange the short-lived authorization code for a long-lived OAuth access token, I get an HTTP 400 response. This is step 3 of the SurveyMonkey OAuth Guide.
Here's a scrubbed version of the full exchange:
POST /oauth/token?api_key=<removed> HTTP/1.1
Accept: application/json
Accept-Encoding: gzip, deflate, compress
Content-Length: 338
Content-Type: application/json; charset=utf-8
Host: api.surveymonkey.net
User-Agent: HTTPie/0.7.2
{
"client_id": "<removed>",
"client_secret": "<removed>",
"code": "dKkIJYnimBli3TMHoTdHoT-zkzkUFzfHeaWJJyPVmrYG35R5Q-jLLU-Y7Fg3BR0n3tVTQ6sAmDnwVxHXSjZVdiYTJ7u7SWbLCKgQa061bKJYXSpRhTsEL0v5GMWcMEBC2vje5UjRHp3SScFQEwIIjHKZH5raC5RQJJh.JYWEOqw8Iy-2Ds7km1zYaHGGlxqu",
"grant_type": "authorization_code",
"redirect_uri": "https://app.hubspotqa.com"
}
HTTP/1.1 400 Bad Request
Cache-Control: no-store
Connection: keep-alive
Content-Length: 96
Content-Type: application/json; charset=UTF-8
Date: Fri, 24 Jan 2014 00:05:53 GMT
SM-Request-ID: 41264d11-b93d-4f8b-ad1a-c656ccfa268b
Server: nginx
{
"error": "invalid_request",
"error_description": "Invalid POST body or Content-Type received."
}
I'm able to reproduce the exact same error using other HTTP clients as well, but I have no trouble manually getting an access token using the SurveyMonkey API console. What am I doing wrong?
Side question: the OAuth guide says that step 3 accepts a redirect_uri but the example Python guide uses redirect_url. Which is the correct parameter? Can I omit it entirely? My server certainly does not care about getting redirected anywhere.
As it turns out, the required Content-Type for this POST is form encoding – application/x-www-form-urlencoded, not JSON.
Note that the documentation does not actually say that anywhere; it's implied by the example usage of the Python requests library.

Error "503 : Service unavailable" while trying to upload a video with the YouTube API

Answered :
The X-Upload-Content-Length value had a space in it.
Question :
I want to use the Youtube API to upload videos from a desktop application, in C++. I implemented the Resumable Upload, everything worked on Friday 19/07 in the afternoon, I could upload a couple of small videos, and since then I always get an error when using my app : "503 : Service Unavailable".
I found several threads treating this topic, it seems there were two solutions :
Retry the request several times in a row
Wait, it somehow works again after a while
Doing the same request again and again didn't solve it for me (I tried to do the request 5 times in a row, maybe I should do more requests ? How many ?). Here is a sample request and the response I get :
Request :
POST https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable&part=snippet HTTP/1.1
Accept: */*
Accept-Language: xx
Authorization: Bearer MY_ACCESS_KEY
X-GData-Key: key=MY_DEV_KEY
Content-Type: application/json
X-Upload-Content-Type: video/avi
X-Upload-Content-Length: 302 080
User-Agent: SOME_PRIVATE_STUFF
Host: www.googleapis.com
Content-Length: 167
Connection: Keep-Alive
Cache-Control: no-cache
{
"snippet": {
"title": "My video title",
"description": "This is a description of my video",
"tags": ["cool", "video", "more keywords"],
"categoryId": 22
}
}
Response :
HTTP/1.1 503 Service Unavailable
Date: Fri, 26 Jul 2013 16:33:27 GMT
Server: HTTP Upload Server Built on Jul 21 2013 19:20:38 (1374459638)
Content-Length: 0
Content-Type: text/html; charset=UTF-8
Thanks for any help, I really don't know what to do right now.

OAuth 2.0 access token isn't refreshed, gives 401 Error : Token Invalid when used

I am currently using the Youtube API for a desktop application in C++. I am trying to implement the direct upload, which requires an authentication. I naturally choose OAuth 2.0, I followed the Google example and apparently everything worked well, I've got an access token and a refresh token, without any error returned.
However, when I try to use the access token to upload a video (I put it in the Authorization : Bearer header), I get an error 401 : Unauthorized with the description Token Invalid.
I then tried to refresh the access token right before requesting the upload (which means I try to refresh right after retrieving the access token, since the two operations are consecutive in my application's flow). The access token remained unchanged : I received the same access token from the refresh request and the exchange request.
I first thought it meant an access token should be refreshed only when it expires, but it is apparently not true : using the OAuth 2.0 Playground, it seems clear that refreshing a not yet expired token works fine and gives a different access token.
Any idea on what the problem could be ? Is the 401 error linked to the fact that I am not able to refresh the token ?
Edit : Here are the request and the response as shown in Fiddler
Request :
POST http://uploads.gdata.youtube.com/feeds/api/users/default/uploads HTTP/1.1
Accept: */*
Accept-Language: xx
Authorization: Bearer MY_ACCESS_TOKEN
GData-Version: 2
X-GData-Key: key=MY_DEV_KEY
Slug: test.avi
Content-Type: multipart/related; boundary="f93dcbA3"
Pragma: no-cache
User-Agent: SOME_STUFF
Host: uploads.gdata.youtube.com
Content-Length: 23686
Connection: Keep-Alive
--f93dcbA3
Content-Type: application/atom+xml; charset=UTF-8
<?xml version="1.0"?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007"><media:group><media:title type="plain">Bad Wedding Toast</media:title><media:description type="plain">I gave a bad toast at my friend's wedding.</media:description><media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People</media:category><media:keywords>toast, wedding</media:keywords></media:group></entry>
--f93dcbA3
Content-Type: video/avi
Content-Transfer-Encoding: binary
<My file binary data>
--f93dcbA3--
Response
HTTP/1.1 401 Unauthorized
X-GData-User-Country: FR
WWW-Authenticate: Bearer realm="https://accounts.google.com/o/oauth2/auth",service="youtube"
Content-Type: text/html; charset=UTF-8
Content-Length: 13
X-GUploader-UploadID: AEnB2UrVDA94Fk5VFn1ng-2q9VFOo2KifLvIEHFOxQ4m66IUSC8sRf3mo5S8UH94mLyupbfANeLQvxMPhPLo6L0wlcaguQW9CQ
Date: Wed, 17 Jul 2013 09:51:23 GMT
Server: HTTP Upload Server Built on Jul 8 2013 15:32:26 (1373322746)
Token invalid
Edit 2 : Request and response using Youtube API v3
Request :
POST /upload/youtube/v3/videos?part="snippet" HTTP/1.1
Host: www.googleapis.com
X-gdata-key: DEV_KEY
Content-length: 42190
Content-type: multipart/related; boundary="===============1679429526=="
Authorization: ACCESS_TOKEN
--===============1679429526==
Content-type: application/json
{
"snippet":
{
"title": "test"
}
}
--===============1679429526==
Content-type: video/avi
<BINARY DATA - 41984B>
--===============1679429526==--
Response :
HTTP/1.1 400 Bad Request
Content-length: 229
Via: HTTP/1.1 GWA
X-google-cache-control: remote-fetch
Server: HTTP Upload Server Built on Jul 8 2013 15:32:26 (1373322746)
Date: Wed, 17 Jul 2013 22:14:03 GMT
Content-type: application/json
{
"error": {
"errors": [
{
"domain": "global",
"reason": "badContent",
"message": "Unsupported content with type: video/avi"
}
],
"code": 400,
"message": "Unsupported content with type: video/avi"
}
}

404 error when posting new forum post in Desire2Learn 10.0

I'm working with the D2L API,and am having difficulty with some POST requests.
Doing a version check (POST) using the JSON object:
[{ "ProductCode": "lp", "Version": "1.0" }]
returns correctly, providing me a valid JSON object in response, that being said I'm confident that my code to issue the call is working correctly.
When I issue a POST to create a post in a forum, however, I get a 404 in response. The JSON object I'm sending for this call is:
[
{
"ParentPostId": null,
"Subject": "API Posted",
"Message": {
"Text": "This message has been posted by the API",
"HTML": "This message has been posted by the API"
},
"IsAnonymous": false
}
]
And the URL submitted to is /d2l/api/le/{ver}/{orgId}/discussions/forums/{forumId}/topics/{topicId}/posts/
I've verified that ver/orgId/forumId/topicId are all valid using a GET of a post in the same forum and topic. I've also tried quoting the values for ParentPostId and IsAnonymous both separately and in unison.
Try removing the square brackets from the JSON.
An example of a successful request and response follows:
REQUEST
POST https://valence.desire2learn.com/d2l/api/le/1.0/7664/discussions/forums/203/topics/508/posts/?x_b=TwULqrltMXvTE8utuLCN5O&x_a=L2Hd9WvDTcyiyu5n2AEgpg&x_d=nF61tBeuzd0EPTW7nm8iGc4MB7NeJZaNM2VlzHp0bwU&x_c=I3i_k2aANTIf2X6aFsiOdvlElSR_avvOYnA2ibcWabA&x_t=1343335429 HTTP/1.1
Accept-Encoding: gzip,deflate
Accept: application/json
Content-Type: application/json
{ "ParentPostId": null, "Subject": "API Posted", "Message": { "Content": "This message has been posted by the API", "Type": "HTML" }, "IsAnonymous": false }
RESPONSE
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Length: 369
Content-Type: application/json; charset=UTF-8
Expires: -1
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Date: Thu, 26 Jul 2012 20:43:58 GMT
{"ForumId":203,"PostId":574,"TopicId":508,"PostingUserId":3667,"ThreadId":205,"ParentPostId":null,"Message":{"Text":"","Html":"This message has been posted by the API"},"Subject":"API Posted","DatePosted":"2012-07-26T20:43:58.920Z","IsAnonymous":false,"RequiresApproval":false,"IsDeleted":false,"LastEditDate":null,"LastEditedBy":null,"CanRate":false,"ReplyPostIds":[]}
Looking at the documentation for that route at http://docs.valence.desire2learn.com/res/discuss.html#post--d2l-api-le-(D2LVERSION-version)-(D2LID-orgUnitId)-discussions-forums-(D2LID-forumId)-topics-(D2LID-topicId)-posts-, it looks like the required data structure uses a RichTextInput not a RichText for Message.
Try changing your Message field to:
{
"Content": "This message has been posted by the API",
"Type": "Text"
}

Neo4j REST Encoding

I'm using neo4jclient. When I try to create/update an node, special chars like äöü are replaced with �.
Do I have to set a specific http header like content-type, content-encoding? If yes, what kind of header and what is the value of this header?
Thanks.
EDIT:
This is how the request looks like:
POST http://...........:7474/db/data/batch HTTP/1.1
Accept: application/json;stream=true
User-Agent: RestSharp 103.1.0.0
Content-Type: application/json
Host: ............:7474
Content-Length: 267
Accept-Encoding: gzip, deflate
[
{
"method": "POST",
"to": "/node",
"body": {
"Name": "äöü",
"State": "Active",
"Id": 0,
"CreateDate": "2012-07-12T18:48:45.3343526+02:00",
"ChangeDate": "0001-01-01T00:00:00+00:00"
},
"id": 0
}
]
Or is it bug in the batch execution? If yes, I'll need the fix very quick:)
Now it works
After analyzing the messages.log we found out, that the file.encoding wasn't utf-8.
--> DEBUG [neo4j.diagnostics]: file.encoding = Cp1252
So we set in the neo4j-wrapper.conf file this property:
wrapper.java.additional.3=-Dfile.encoding=UTF-8
Now it works!!! :)
Thanks to my brother! Always good to know a Java developer. :)
There are tests for this in the codebase, so it should be handled correctly, see https://github.com/neo4j/community/blob/master/server/src/functionaltest/java/org/neo4j/server/rest/BatchOperationFunctionalTest.java#L322 . However, there might be encoding problems in the client?

Resources