-1

I am new to Quickbooks API. I have found APIs list under API Exolorer link in Quickbooks. They have shown the Request URI & Request Headers that are needed for making the API call. I can understand that. But how to call that URI or how to integrate that API with PHP is not exactly specified. I tried to call the URI and get the results using curl,but it didn't succeed. I have lost lot of time for this integration. I have searched google in all possible way. But most of the results coming related to PHP SDKs. But I need to integrate the Quickbooks Online API.

The Request URI for creating an entity is looks like below.

https://{{baseurl}}/v3/company/{{companyid}}/account

Please help me to sort this out.

Nithinkumar CN
  • 287
  • 1
  • 5
  • 18
  • use the sdk. https://developer.intuit.com/docs/0100_quickbooks_online/0400_tools/0005_sdks/0209_php – Jonathan Apr 10 '17 at 05:36
  • Thanks for the reply. Using SDK its fine. But I have to use Quickbooks online API as mentioned in my question. – Nithinkumar CN Apr 10 '17 at 05:50
  • The SDK makes use the online API. – Jonathan Apr 10 '17 at 05:50
  • Ok..fine..thanks..Please let me know one thing..Is there any way for us to directly call APIs without using SDK? – Nithinkumar CN Apr 10 '17 at 06:00
  • 1
    Yes, you just need to read the docs. https://developer.intuit.com/docs/api/accounting – Jonathan Apr 10 '17 at 06:02
  • Yes. I read the docs and tried to implement the integration via the specified URIs. I used 'cUrl' to get the response from the API. But I got stuck with the following error. HTTP/1.1 400 Illegal character 0x20 – Nithinkumar CN Apr 10 '17 at 06:17
  • 1
    You need to edit your post to include this error message - that's a key part of your question that's missing. Please read [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) for other tips. – DaveyDaveDave Apr 10 '17 at 07:51
  • Can anyone post a code which allows to generate oauth_signature. I've integrated this with postman and even with curl. I couldn't generate oauth_signature randomnly which allow to authenticate with quickbox. I found out that, Postman uses their own code to generate oauth_signature. Can anyone suggest a code which creates oauth_signature correctly using php or curl. – Visal Varghese Apr 10 '17 at 12:15
  • Possible duplicate of [QuickBooks API (php) Integration](http://stackoverflow.com/questions/20393709/quickbooks-api-php-integration) – Keith Palmer Jr. Apr 10 '17 at 12:46
  • Search before you post please. This has been asked MANY times before on StackOverflow, and answered MANY times as well. – Keith Palmer Jr. Apr 10 '17 at 12:47

1 Answers1

1

As most people suggested, using the PHP SDK is going to be the easier way for integrating QuickBooks Online with PHP: https://github.com/intuit/QuickBooks-V3-PHP-SDK

However, using plain PHP cURL is also possible, but a few concepts you need to understand before making the API call:

1) OAuth 1.0 protocol

It is what most developer get confused of. QuickBooks Online use OAuth 1.0 as authorization protocol. You need to spend sometime to understand how it worked. For documentation, you can read it here: https://developer.intuit.com/docs/0100_quickbooks_online/0100_essentials/000500_authentication_and_authorization/connect_from_within_your_app

However, I suggest you play with the OAuth playground, it gives you a feeling for how it looked like when you implement it: https://appcenter.intuit.com/Playground/OAuth/IA/ (fill your Consumer key and secrets, click on Connect to Quickbooks Button)

During the process, it will return something called: RealmID. That is the companyid in QBO, put it on the URL.

2) The base URL

When you create an app at developer.intuit.com, under keys tab, you will see Development Keys and Production Keys. The corresponding keys at the right side is what you need to fill for the {baseurl} part(For example, besides development keys, there is place called "Accounting Sandbox Url" : "sandbox-quickbooks.api.intuit.com"). For each API entity endpoint, refer to the documentation: https://developer.intuit.com/docs/api/accounting/customer

3) Authorization header

You are unlikely to implement it by yourself for OAuth 1.0. Twitter has a good link for how to use the Access Token and Access Token secrets from step 1) to generate signature: https://dev.twitter.com/oauth/overview/creating-signatures

You will put the signature as part of the authorization header.

If you are using POSTMAN, they have OAuth 1.0 as authorization protocol available for you. Here is an example

    <?php

    $curl = curl_init();
    curl_setopt_array($curl, array(
    CURLOPT_URL => "https://sandbox-quickbooks.api.intuit.com/v3/company/193514340994122/account/1",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => array(
    "authorization: OAuth oauth_consumer_key=\"qyprdDjYtPpiEpbwFQZuUoAjubpVqm\",oauth_token=\"lvprdfblXv4LqNVhIv2WH2JebiSZgNs9POiEoCJxMwEhqbgc\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"1494441064\",oauth_nonce=\"cfh0b7\",oauth_version=\"1.0\",oauth_signature=\"KqpN9ximPGWnWJBaXg1Vs9urJLY%3D\"",
    "cache-control: no-cache",
    "postman-token: 7c570691-c6cd-a706-67a0-984c5ddb1e6a"
  ),
));

  $response = curl_exec($curl);
  $err = curl_error($curl);

  curl_close($curl);

  if ($err) {
     echo "cURL Error #:" . $err;
  } else {
     echo $response;
  }
hlu2
  • 109
  • 3