Recommend this page to a friend! |
PHP OAuth Library | > | All threads | > | Many thanks for this class and the... | > | (Un) Subscribe thread alerts |
|
Murray Russell rated this package as follows:
Utility: | Good |
---|---|
Consistency: | Good |
Documentation: | Sufficient |
Examples: | Sufficient |
Murray Russell - 2017-03-03 14:35:48
Many thanks for this class and the subsequent support which has been great
Manuel Lemos - 2017-03-03 22:51:39 - In reply to message 1 from Murray Russell
You're welcome. Just let me know if is there anything that is missing or is not so good that you would like to be better.
Murray Russell - 2017-03-08 21:49:43 - In reply to message 2 from Manuel Lemos
Thanks to you I can extract lists of customers and lists of items from Quickbooks online. I can also create new customers within QBO, however I get errors while trying to create invoices. Unfortunately I am not getting much joy from Intuit support. Please feel free to tell me this is outside your scope and I will continue to hound Intuit.
They say I should send the following for a single line invoice {"Line":[{"Id":"1","Amount":"167.70","DetailType":"SalesItemLineDetail","SalesItemLineDetail":{"ItemRef":{"value":"1","name":"Services"}},"Description":"JOB456 - Wrex Tarr - 2.15 hours"}],"CustomerRef":{"value":"79"}} but I get the error alert(it was not possible to access the API call: it was returned an unexpected response status 400 Response: {"Fault":{"Error":[{"Message":"Request has invalid or unsupported property","Detail":"Property Name:Can not instanti specified is unsupported or invalid","code":"2010"}],"type":"ValidationFault"}, "time":"2017-03-08T12:30:24.731-08:00"}); My code as follows $i = 0; $db->query("select * from ".$crndb.".".$table." where selected = 'Y'"); $rows = $db->resultset(); $parameters = new stdClass; $line = new stdClass; $salesitemlinedetail = new stdClass; $itemref = new stdClass; foreach ($rows as $row) { extract($row); $description = $jobno.' - '.trim($operator.' '.$machine).' - '.$hours.' hours'; $i = $i + 1; $itemref->value = 1; $itemref->name = 'Services'; $salesitemlinedetail->ItemRef = $itemref; $line->Id = $i; $line->Amount = $charge; $line->DetailType = "SalesItemLineDetail"; $line->SalesItemLineDetail = $salesitemlinedetail; $line->Description = $description; } $parameters->Line = $line; $CustomerRef = new stdClass; $CustomerRef->value = $client_accno; $parameters->CustomerRef = $CustomerRef; $success = $client->CallAPI( 'https://quickbooks.api.intuit.com/v3/company/123145744995499/invoice', 'POST', $parameters, array( 'FailOnAccessError'=>true, 'RequestContentType'=>'application/json' ), $invoice); which produces a string the same as theirs (which does not work when passed as $parameters) except the stdClass does not include the [ ] they have in their string and produces the following with the subsequent error. stdClass Object ( [Line] => stdClass Object ( [Id] => 1 [Amount] => 167.70 [DetailType] => SalesItemLineDetail [SalesItemLineDetail] => stdClass Object ( [ItemRef] => stdClass Object ( [value] => 1 [name] => Services ) ) [Description] => JOB456 - Wrex Tarr - 2.15 hours ) [CustomerRef] => stdClass Object ( [value] => 79 ) ) <script>alert(it was not possible to access the API call: it was returned an unexpected response status 400 Response: {"Fault":{"Error":[{"Message":"Request has invalid or unsupported property","Detail":"Property Name:Can not deserialize instance of java.util.ArrayList out of START_OBJECT token\n specified is unsupported or invalid","code ":"2010"}],"type":"ValidationFault"},&quo t;time":"2017-03-08T08 :37:21.592-08:00"});</script>
Murray Russell - 2017-03-09 07:44:19 - In reply to message 3 from Murray Russell
My php code for this is as follows
$i = 0; $db->query("select * from ".$crndb.".".$table." where selected = 'Y'"); $rows = $db->resultset(); $parameters = new stdClass; $line = new stdClass; $salesitemlinedetail = new stdClass; $itemref = new stdClass; foreach ($rows as $row) { extract($row); $description = $jobno.' - '.trim($operator.' '.$machine).' - '.$hours.' hours'; $i = $i + 1; $itemref->value = 1; $itemref->name = 'Services'; $salesitemlinedetail->ItemRef = $itemref; $line->Id = $i; $line->Amount = $charge; $line->DetailType = "SalesItemLineDetail"; $line->SalesItemLineDetail = $salesitemlinedetail; $line->Description = $description; } $parameters->Line = $line; $CustomerRef = new stdClass; $CustomerRef->value = $client_accno; $parameters->CustomerRef = $CustomerRef; $success = $client->CallAPI( 'https://quickbooks.api.intuit.com/v3/company/123145744995499/invoice', 'POST', $parameters, array( 'FailOnAccessError'=>true, 'RequestContentType'=>'application/json' ), $invoice); At the moment I am only passing one record to this. When I get this working I will try a multi line invoice. Intuit state the get this to work using cUrl <?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://sandbox-quickbooks.api.intuit.com/v3/company/123145812836282/invoice?minorversion=4", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "{\"Line\":[{\"Id\":\"1\",\"Amount\":\"167.70\",\"DetailType\":\"SalesItemLineDetail\",\"SalesItemLineDetail\":{\"ItemRef\":{\"value\":\"1\",\"name\":\"Services\"}},\"Description\":\"JOB456 - Wrex Tarr - 2.15 hours\"}],\"CustomerRef\":{\"value\":\"79\"}}", CURLOPT_HTTPHEADER => array( "accept: application/json", "authorization: OAuth oauth_consumer_key=\"qyprdUSoVpIHrtBp0eDMTHGz8UXuSz\",oauth_token=\"lvprdHb9KupvCa8hGgLYeoKWAs0aZLPkNuRyGCQPINlfCqjP\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"1489032771\",oauth_nonce=\"TqfMZd\",oauth_version=\"1.0\",oauth_signature=\"5GVWTGZ%2F4J4ga7zle7vH3Gxuid0%3D\"", "cache-control: no-cache", "content-type: application/json", "postman-token: a30ecfdb-97e5-6b19-1631-06932d7776d4" ), )); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; } however if I substitute $parameters in my code with the content of the above POSTFIELDS I still get the following error <script>alert(it was not possible to access the API call: it was returned an unexpected response status 400 Response: {"Fault":{"Error":[{"Message":"Request has invalid or unsupported property","Detail":"Property Name:Can not instanti specified is unsupported or invalid","code":"2010"}],"type":"ValidationFault"}, "time":"2017-03-08T23:37:14.235-08:00"});</script> Intuit suggest there is an error in my php code. Do you have any ideas please.
Manuel Lemos - 2017-03-11 02:37:36 - In reply to message 3 from Murray Russell
If they are certain that the JSON string is correct, you can use the string and json_decode to assign the parameters value.
$parameters = json_decode('{"Line":[{"Id":"1","Amount":"167.70","DetailType":"SalesItemLineDetail","SalesItemLineDetail":{"ItemRef":{"value":"1","name":"Services"}},"Description":"JOB456 - Wrex Tarr - 2.15 hours"}],"CustomerRef":{"value":"79"}}'); Still the error messages point to Java things they are running on the server like java.util.ArrayList . So I wonder of they are not having an issue dealing with the parameters you are sending.
Murray Russell - 2017-03-11 09:38:56 - In reply to message 5 from Manuel Lemos
Manuel, you are a star.
At least sending that string as $parameters returned a readable error that QuickBooks Online also insisted on having the TaxCodeRef included. This is something none of the QuickBooks support picked up on. So if it is of any use to anyone else, the following works:- $parameters = json_decode('{"Line":[{"Id":"1","Amount":"167.70","DetailType":"SalesItemLineDetail","SalesItemLineDetail":{"ItemRef":{"value":"1","name":"Services"},"TaxCodeRef":{"value":"3"}},"Description":"JOB456 - Wrex Tarr - 2.15 hours"}],"CustomerRef":{"value":"79"}}'); Thank you very much.
Manuel Lemos - 2017-03-11 10:23:13 - In reply to message 6 from Murray Russell
Yes, you could rebuild object variable by variable, but that way you assure you are not making a mistake mapping the string.
|
info at phpclasses dot org
.