I have been looking for solution from last-2 days, also this is my first question here so bear with me.
I am trying to upload jpg image with upload qbo api, but keep getting a error code 500 with message Unsupported OperationOperation Cannot consume content type is not supported.
My request is:
@client = Signet::OAuth1::Client.new(
:temporary_credential_uri => "https://oauth.intuit.com/oauth/v1/get_request_token",
:authorization_uri => "https://appcenter.intuit.com/Connect/Begin",
:token_credential_uri => "https://oauth.intuit.com/oauth/v1/get_access_token",
:client_credential_key => App.find_by_name('quickbooks').clientid,
:client_credential_secret => App.find_by_name('quickbooks').clientsecret
)
@client.token_credential_key = quickbooks.accesstoken
@client.token_credential_secret = quickbooks.refreshtoken
realmid =quickbooks.uid
url = Rails.env.eql?("development")? "sandbox-quickbooks.api.intuit.com" : "quickbooks.api.intuit.com"
object = {
"AttachableRef": [
{
"EntityRef": {
"type": "Invoice",
"value": "95"
}
}
],
"FileName": params[:file].original_filename,
"ContentType": "image/jpg"
}
original_request = [
'Post',
"https://#{url}/v3/company/#{realmid}/upload",
[
['Content-Type', 'application/json'],
['boundary', '0be01941e049'],
],
[object.to_json]
]
response = @client.fetch_protected_resource(:request => original_request)
In response got:
<Error code=\"500\"><Message>Unsupported Operation</Message><Detail>Operation Cannot consume content type is not supported.</Detail></Error></Fault></IntuitResponse>"
Any kinda help would be appreciated. Thanks
:EDIT
Using quickbook-ruby gem---- 'github.com/ruckus/quickbooks-ruby#uploading-an-actual-file'
::QB_OAUTH_CONSUMER = OAuth::Consumer.new(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET, {
:site => "https://oauth.intuit.com",
:request_token_path => "/oauth/v1/get_request_token",
:authorize_url => "https://appcenter.intuit.com/Connect/Begin",
:access_token_path => "/oauth/v1/get_access_token"
})
meta = Quickbooks::Model::Attachable.new
meta.file_name = "monkey.jpg"
meta.note = "A note"
meta.content_type = "image/jpg"
entity = Quickbooks::Model::BaseReference.new(123, type: 'Transfer')
meta.attachable_ref = Quickbooks::Model::AttachableRef.new(entity)
doc_path = 'Add file path'
upload_service = Quickbooks::Service::Upload.new(:realm_id=> '123XXX', :access_token=> 'QTYXXXXX')
result = upload_service.upload(doc_path, "image/jpeg")
I am facing an error NoMethodError: undefined method `post_with_multipart' for "erXXXXXXXXXXXXXXXX6":String
Even though i'm not using any method named post_with_multipart in my code, This is something i'm getting in response when I try to upload image result = upload_service.upload(doc_path, "image/jpeg")
So if anyone lands here in search of solution, This is how I fixed it. So what I was collectively doing wrong is I wasn't passing access token with OAuth.
token = OAuth::AccessToken.new($qb, oauth_token, oauth_secret)