QuickBooks API 创建客户 POST 请求失败

QuickBooks API Create Customer POST request FAIL

我想通过 q​​uickbooks 创建一个客户 API。

首先 GET 请求一切正常。

但是当我尝试 POST 请求时,我得到

错误代码="100">一般身份验证错误

这是 Oauth2 令牌 =>

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

这是 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": "johndoe@gmail.com"

   }

  }

这是 URL =>

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

任何人都可以帮助我,我看不出我做错了什么。

提前致谢。

请尝试使用 Postman 呼叫。以下博客 post 应该会有所帮助。 https://developer.intuit.com/hub/blog/2017/08/03/quick-start-quickbooks-online-rest-api-oauth-2-0

请检查您是否将内容类型作为 'application/json' 传递。

好的,我明白了!

这是从 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