intuit / QuickBooks-V3-PHP-SDK

Official PHP SDK for QuickBooks REST API v3.0: https://developer.intuit.com/
Apache License 2.0
245 stars 246 forks source link

Creating TaxAgency throws errror #387

Open shawncrigger opened 3 years ago

shawncrigger commented 3 years ago

Hello, I am having constant issues when adding TaxAgencies, I got around it the first time by inserting them in Batches but I am at a point where I have to be able to create a single agency when creating a TaxCode, when I attempt to add the agency using code like

  $taxAgency = TaxAgency::create(array(
      'DisplayName' => 'RacineSportTest (5.1%)'
  ));
  $result = $this->dataService->Add($taxAgency);

I get the following error, which is strange because according to the API Explorer for TaxAgency XML is not supported, and according to the request log a JSON object was sent but the response is looking for a XML response. Is there another way to do this besides insert them in batch that hasn't been documented?

Operation org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog. is not supported.

Here are the log files for the request and the response

Request Log File

REQUEST URI FOR SEQUENCE ID 00519
==================================
https://sandbox-quickbooks.api.intuit.com/v3/company/4620816365157867000/taxagency?minorversion=55

REQUEST HEADERS
================
Authorization: Bearer (removed)
host: sandbox-quickbooks.api.intuit.com
user-agent: V3PHPSDK5.3.8
accept: application/xml
connection: close
content-type: application/xml
content-length: 40

REQUEST BODY
=============
{"DisplayName":"RacineSportTest (5.1%)"}

Response Log File

RESPONSE URI FOR SEQUENCE ID 00520
==================================
https://sandbox-quickbooks.api.intuit.com/v3/company/4620816365157867000/taxagency?minorversion=55

RESPONSE HEADERS
================
date: Wed, 20 Jan 2021 07:12:00 GMT
content-type: application/xml
content-length: 414
connection: close
server: nginx
strict-transport-security: max-age=15552000
intuit_tid: 1-6007d7bf-6f0828d141b119af57c3940e
x-spanid: f4011792-8125-4277-a28e-cd97f6e4e1ae
x-amzn-trace-id: Root=1-6007d7bf-6f0828d141b119af57c3940e

RESPONSE BODY
=============
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2021-01-19T23:12:00.131-08:00">
  <Fault type="ValidationFault">
    <Error code="500">
      <Message>Unsupported Operation</Message>
      <Detail>Operation org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog. is not supported.</Detail>
    </Error>
  </Fault>
</IntuitResponse>
shawncrigger commented 3 years ago

Since no one has any clue, I found the SDK is not stable in any fashion. However, you can get around this lovely undocumented feature by inserting TaxAgency in batch, but not TaxRate/TaxCode those only work in a single entry. You can send a batch, and it won't error out, but it won't generate anything either. Quality code

What I did to get around adding 1 TaxAgency was send a freaking batch with just one entry, and it worked. The below code is some of my prototype code. I'm sure you can sort out how to make it work in your application.

Also, I am using QBO SDK 5.4.4 when I upgraded to the latest stable, the log file stopped working along with a host of other bugs.


<?php
// Agency does not exist
if (!is_numeric($AgencyID)) {
   // Create new batch service
   $batch = $this->dataService->CreateNewBatch();
   // My agent name
   $agent = $obj['taxable_agency'];
   $taxAgency = TaxAgency::create(array(
       'DisplayName' => $agent,
   ));
   // Add to the batch
   $batch->AddEntity($taxAgency, "agency-1", "create");
   // Execute batch API request
   $batch->ExecuteWithRequestID("batch-number-1");
   // Fetch API response
   $temp = $batch->intuitBatchItemResponses["agency-1"];
   if ($temp->isSuccess()) {
      UTIL::out("Create TaxAgency {$agent} success!:");
      // Get the results
      $result = $temp->getResult();
      // Set the Agent Id
      $AgencyID = $result->Id;
      // Insert it into my database.
      $this->insertTaxAgency($obj, $result->Id);
   }
}

If you need help with your QBO API, I don't have time to help right now, maybe in the future.

abisalehalliprasan commented 3 years ago

The logging issue is now fixed with the release v5.4.7. We will look into the taxAgency endpoint and update the documentation/sample accordingly.

shawncrigger commented 3 years ago

Can you explain to me why when I send tax information it doesn't show up in the sandbox but does in the JSON request/response?