Jordan Mcn
Jordan Mcn

Reputation: 55

QuickBooks API Create Customer POST request FAIL

I would like to create a customer by quickbooks API.

First thing everything is working well with a GET request.

But when I try a POST request I get

Error code="100">General Authentication Error

Here's the Oauth2 token =>

at = OAuth2::AccessToken.new(::QB_OAUTH2_CONSUMER, acces_token)

Here's the new_customer =>

new_customer =

  {

   "BillAddr": {

     "Line1": "10 rue Des Champs",

     "City": "Paris",

     "Country": "FRANCE",

     "CountrySubDivisionCode": "FR",

     "PostalCode": "75020"

   },

   "Notes": "Just a test",

   "Title": "Mr",

   "GivenName": "John",

   "MiddleName": "",

   "FamilyName": "Doe",

   "Suffix": "",

   "FullyQualifiedName": "John Doe",

   "CompanyName": "DonwtownLA",

   "DisplayName": "DonwtownLA",

   "PrimaryPhone": {

     "FreeFormNumber": "0123456789"

   },

   "PrimaryEmailAddr": {

     "Address": "[email protected]"

   }

  }

Here's the URL =>

at.post("https://quickbooks.api.intuit.com/v3/company/#{realm_id}/customer")

Anyone can help me for this I cant see what I'm doing wrong.

Thanks in advance.

Upvotes: 0

Views: 628

Answers (2)

Manas Mukherjee
Manas Mukherjee

Reputation: 5340

Please try the call using Postman. The following blog post should be helpful. https://developer.intuit.com/hub/blog/2017/08/03/quick-start-quickbooks-online-rest-api-oauth-2-0

Please check if you are passing the content-type as 'application/json'.

Upvotes: 0

Jordan Mcn
Jordan Mcn

Reputation: 55

Ok I got It !

Here's the code for creating user from Quickbooks Controller

def create_qb_customer
    data =
    {
      "Notes": "This is from Darta",
      "GivenName": "#{params[:first_name]}",
      "FamilyName": "#{params[:last_name]}",
      "CompanyName": "#{params[:company]}",
   "PrimaryEmailAddr": {
     "Address": "#{params[:email]}"
   }
    }
  realm_id = QbToken.last.realm_id
  url = URI("https://sandbox-quickbooks.api.intuit.com/v3/company/#{realm_id}/customer/")
  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true
  request = Net::HTTP::Post.new(url)
  request["Content-Type"] = 'application/json'
  request["Authorization"] = "Bearer #{QbToken.last.serial}"
  request["Cache-Control"] = 'no-cache'
  request["Postman-Token"] = 'XXXXXX-cf4c-XXXXX-8d7c-XXXXXXXXX'
  request.body = data.to_json
  response = http.request(request)
  p response.read_body
  flash.notice = "Your QuickBooks customer is successfully created !"
  redirect_to list_all_project_path
  end

Upvotes: 1

Related Questions