0
votes

I am new in quickbooks API implementation, I am always getting one error No apptoken detected; errorCode=003102; statusCode=401 when I am doing API call for customer add etc. I am giving my steps, please look over that.

My sandbox info like that

  • Consumer Key: qyprdffbBBInX4a82jG73Mreyy96tC
  • Consumer Secret: IgpJzJrYvb9FmmdB7A0ECDGHG62Cp7dqVWjfMTvU
  • Access Token: qyprdlo3WrK0KhGZMTeA857AuKiVy2eaAmpXsRvG3jycYaMQ
  • Access Token Secret: TdPGpcUI8AiAdWFiCyb8jAAygH16bzU7VRGaspx4

    I am Using PHP. First I have generated oauth_signature.

$URL = rawurlencode('https://sandbox-quickbooks.api.intuit.com/v3/company/408554291/customer'); $method = 'POST'; $parameter = rawurlencode('oauth_consumer_key=qyprdffbBBInX4a82jG73Mreyy96tC&oauth_nonce=BlyqIBbv3R4T0P4qglAv1RjoYisMZk1449659733&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1449659733&oauth_token=qyprdlo3WrK0KhGZMTeA857AuKiVy2eaAmpXsRvG3jycYaMQ&oauth_version=1.0');

$ukey = rawurlencode('IgpJzJrYvb9FmmdB7A0ECDGHG62Cp7dqVWjfMTvU').'&'.rawurlencode('TdPGpcUI8AiAdWFiCyb8jAAygH16bzU7VRGaspx4'); $hasmac = hash_hmac("sha1", $BaseURL,$ukey,1);

and My oauth_signature is jZ8JhECy/e0kpPbUdZp/o/EUC7U=

When i call API with this oauth_signature, i am getting Error 'No apptoken detected; errorCode=003102; statusCode=401'

My CURL call like this

curl -X POST -H 'Content-Type: application/json, Authorization: OAuth oauth_token=qyprdlo3WrK0KhGZMTeA857AuKiVy2eaAmpXsRvG3jycYaMQ,oauth_consumer_key=qyprdffbBBInX4a82jG73Mreyy96tC,oauth_signature_method=HMAC-SHA1,oauth_timestamp=1449659733,oauth_version=1.0,oauth_nonce=BlyqIBbv3R4T0P4qglAv1RjoYisMZk1449659733,oauth_signature=jZ8JhECy/e0kpPbUdZp/o/EUC7U=' -d '{"data": [{"BillAddr":{"Line1":"86 A Topsia","City":"Kolkata","Country":"India","CountrySubDivisionCode":"WB","PostalCode":"700102"},"Title":"Mr.","GivenName":"ApurbaK","MiddleName":"Kumar","FamilyName":"ApurbaK","PrimaryPhone":{"FreeFormNumber":"564545465"},"PrimaryEmailAddr":{"Address":"[email protected]"}}]}' 'https://sandbox-quickbooks.api.intuit.com/v3/company/408554291/customer'

Please look over that.

Thanks, Apurba

1

1 Answers

0
votes

Firstly, you don't want to be doing this yourself -- use a library. OAuth is complex, and implementing it yourself is going to be a hairy process, rife with errors.

Go grab a library:

Follow the quick-start guide linked there, and benefit from the examples:

With that said, if you do decide to write it yourself, make sure you follow the OAuth spec:

So far, the issues I immediately see with your implementation are:

  • You can't hard-code the timestamp like this: &oauth_timestamp=1449659733 The timestamp should be ever-changing, and set to the currenty timestamp.

  • You can't hard-code a nonce like this: &oauth_nonce=BlyqIBbv3R4T0P4qglAv1RjoYisMZk1449659733 The nonce has to change with every single request so this is going to fail after your first request.

  • You haven't normalized your request parameters / sorted them, per the spec.

  • This is the incorrect way to specify multiple headers with cURL: -H 'Content-Type: application/json, Authorization: OAuth .... Please see the cURL docs: http://curl.haxx.se/docs/manpage.html#-H

  • In the code you posted, you haven't actually set $BaseURL anywhere, so right now you're signing an empty string (unless you forgot to paste some code somewhere?)

  • What is $ukey set to? It doesn't appear to be defined in your code anywhere (did you forget to paste some code in?)