Topic: IPP V3 List all Invoices for a Customer

Hi All,

I downloaded and installed QuickBooks PHP DevKit yesterday. I am brand new to Quickbooks (online). All examples are working fine (thanks Keith!), but I think I am missing something fundimental....

I can find a Customers Unique ID with

$id = $CustomerService->findByName($Context, $realm, 'Reimers ');

Which gives me an array containing "{QBO-8}". I now want to use that ID to obtain a list of Invoices. I have been trying:

$invoices = $InvoiceService->query($Context, $realm, "SELECT * FROM Invoice WHERE CustomerRef=8");

But that does not work. Can someone take a moment to explain how I go about listing all Customer Invoices?

Many thanks!

Tom

Re: IPP V3 List all Invoices for a Customer

Hi Tom,

If you grab the latest code from GitHub:
* https://github.com/consolibyte/quickbooks-php

There's a good example of doing exactly what you're trying to do:
* https://github.com/consolibyte/quickboo … _query.php

You will need the latest code from GitHub, so make sure you grab that first.

(it looks like you may be mixing v2 API calls with v3 API calls, which is likely your problem - hard to tell without seeing the rest of the code though)

Re: IPP V3 List all Invoices for a Customer

Hi keith.
I am trying to get a vendor by display name. according to docs DisplayName supports filter. but i am geting this error.

Response [HTTP/1.1 401 Unauthorized
Date: Tue, 17 Dec 2013 13:20:05 GMT
Server: Apache/2.2.22 (Unix)
WWW-Authenticate: OAuth oauth_problem="signature_invalid"
Content-Length: 353
Connection: close
Content-Type: application/xml;charset=ISO-8859-1



    
        
            message=Exception authenticating OAuth; errorCode=003200; statusCode=401
        
    

]

and this is the request being generated with ipp->lastrequest()

Request [GET https://quickbooks.api.intuit.com/v3/company/1016365050/query?query=SELECT+*+FROM+Vendor+WHERE+DisplayName+%3D+'Waseem'+ HTTP/1.1
Content-Type: text/plain
Authorization: OAuth realm="", oauth_signature_method="HMAC-SHA1", oauth_signature="T8JN2ZEN%2FLAy6hiGC845fjrl5vE%3D",  oauth_nonce="YvOkf", oauth_timestamp="1387286404", oauth_token="*************************", oauth_consumer_key="**********************", oauth_version="1.0"

]

Re: IPP V3 List all Invoices for a Customer

I am unable to reproduce this. Make sure you have the latest code, and try again.

Here's an example that works fine for me:
* https://github.com/consolibyte/quickboo … _query.php

Re: IPP V3 List all Invoices for a Customer

I just downloaded new one and working on it but i am still getting same error.
is there any thing to do with quickbooks online company account ?
and also i am using mysql if there may be something with that ?

it is running here if you like to have a look on it.

http://technologyelement.com/waseem/qui … pp_ipp_v3/

Last edited by WAS33M (2013-12-18 01:42:34)

Re: IPP V3 List all Invoices for a Customer

Are you *positive* you updated *all* of the very latest code from GitHub?

This has NOTHING to do with MySQL or any settings in QuickBooks Online.

Re: IPP V3 List all Invoices for a Customer

yes i did. before i didn't had that vendor filter by name file. but it is in there and i also overwrited all files.
and only made changes to config.php for credentials.

Re: IPP V3 List all Invoices for a Customer

OK, the options are:

1. Send us FTP access via email so we can troubleshoot

OR

2. Zip up all the code and email it to us, along with the output of phpinfo() from your server, so that we can troubleshoot

Re: IPP V3 List all Invoices for a Customer

ok i have added you on skype.  i will provide FTP details to you there.

and there is one more thing most likely a bug i think. that i also want to discuss but first you must check the code to make sure it is correct one.

Re: IPP V3 List all Invoices for a Customer

It is working fine on WAMP on my computer.
so what could be the error online ?
Any idea ?

I think there has to be something with server settings.
Also mysqli does not work there.

Last edited by WAS33M (2013-12-18 03:15:44)

Re: IPP V3 List all Invoices for a Customer

Good talking to you on Skype.

The problem was that you have magic quotes (http://www.php.net/magic_quotes) enabled in PHP. You should turn these off - they are a terrible, deprecated feature of PHP.

In the meantime, we have checked in a work-around on GitHub.

Re: IPP V3 List all Invoices for a Customer

Yes and thanks for all the help.
Api is now working perfect and is made very easy that i can tweek it in what ever way i want smile

Re: IPP V3 List all Invoices for a Customer

Hi Keith, Was33m,

I had a "you're moved to another project episode", but I am back on this now. Great to see that you both resolved it. I downloaded version 2 of the devkit, connected and all appears well... until I try to add a customer:

[Previously as in 4 months ago this worked]...

if ($resp = $CustomerService->add($Context, $realm, $Customer)) {
  // I don't get here
}
else {
      print($CustomerService->lastError($Context));
     print($CustomerService->lastRequest());
     print($CustomerService->lastResponse());
}

The "print" gives me:

-1092: [XML parser said: 6: No XML content to parse., ]

POST /customer/v3/468610095 HTTP/1.1
Authorization: OAuth realm="", oauth_signature_method="HMAC-SHA1", oauth_signature="RQeIrueTY4NpAsI9x0TDOY8YQlM%3D", oauth_nonce="3kvGQ", oauth_timestamp="1403869836", oauth_token="qyprdsu1XJsIhH59jDdJfeYtYwnSN2Y9zvj36XHzPammEimx", oauth_consumer_key="qyprdaC27BXHXtnkWmMWoBidXww2oO", oauth_version="1.0"
Content-Length: 198

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Object xsi:type="Customer">
    <TypeOf>Person</TypeOf>
    <GivenName>Jones</GivenName>
    <DisplayName>TWE1100-1 Jones</DisplayName>
</Object>

I can buy into the idea that the XML is wrong/not produced because it's a long time since I looked at the code, but the thing that confuses me is that      print($CustomerService->lastResponse());  gives me the XML that I was expecting to get.

Any ideas?

Could this also be connected to magic quotes (which I have not turned off).

Many thanks in advance!

Tom

Re: IPP V3 List all Invoices for a Customer

Post your code. Do you have this in there?

// Set the IPP version to v3 
$IPP->version(QuickBooks_IPP_IDS::VERSION_3);

Re: IPP V3 List all Invoices for a Customer

Also look at the output of print($Service->lastResponse());

Re: IPP V3 List all Invoices for a Customer

Hi Keith. Yes I do,... Here you go...


if (!QuickBooks_Utilities::initialized($dsn)) {
    // Initialize creates the neccessary database schema for queueing up requests and logging
    QuickBooks_Utilities::initialize($dsn);
}
 
  // Set up the IPP instance                                                                                                                                                                                                   
$IPP = new QuickBooks_IPP($dsn);

// Set up our IntuitAnywhere instance                                                                                                                                                                                         
$IntuitAnywhere = new QuickBooks_IPP_IntuitAnywhere($dsn, $encryption_key, $oauth_consumer_key, $oauth_consumer_secret);

// Get our OAuth credentials from the database                                                                                                                                                                               
$creds = $IntuitAnywhere->load($the_username, $the_tenant);

// Tell the framework to load some data from the OAuth store                                                                                                                                                                 
$IPP->authMode(QuickBooks_IPP::AUTHMODE_OAUTH, $the_username, $creds);

// This is our current realm                                                                                                                                                                                                 
$realm = $creds['qb_realm'];


if ($Context = $IPP->context()) {
    // Set the IPP version to v3
    $IPP->version(QuickBooks_IPP_IDS::VERSION_3);

    $CustomerService = new QuickBooks_IPP_Service_Customer();
   
   
    $customers = $CustomerService->findByName($Context, $realm, $_POST['quickbooks_customer_name']);
   
   
    //$customers = $CustomerService->query($Context, $realm, "select * from Customer WHERE FullyQualifiedName='" . $_POST['quickbooks_customer_name'] . "'");
   
    if (count($customers) > 0)
    {
        foreach ($customers as $Customer)
        {
            $duplicate_customer_name = $Customer->getFullyQualifiedName();
        }
    }
   
    if (isset($duplicate_customer_name)) {
        echo "The name '" . $duplicate_customer_name . "' is already in use.";
    }
    else { // we add the customers
        $Customer = new QuickBooks_IPP_Object_Customer();
       
        $Customer->setDisplayName($_POST['quickbooks_customer_name']);
       
        $customer_parts = explode(" ", $_POST['quickbooks_customer_name']);
       
        if (!empty($customer_parts[1])) {
            $Customer->setGivenName($customer_parts[1]); // Surname of contract holder
        }

        if ($resp = $CustomerService->add($Context, $realm, $Customer)) {
            print('Our new customer ID is: [' . $resp . ']');
            exit;
            $InvoiceService = new QuickBooks_IPP_Service_Invoice();
   
   
   
            // ADD INVOICES
            if (isset($twe_ledger_payments)) {
                foreach ($twe_ledger_payments as $key => $i):
                   
                    $Invoice = new QuickBooks_IPP_Object_Invoice();
           
                    //$Invoice->setDocNumber('WEB123');
                    $Invoice->setTxnDate($i['due_date']);
                   
                    $Line = new QuickBooks_IPP_Object_Line();
                    $Line->setDetailType('SalesItemLineDetail');
                    $Line->setAmount($i['amount']);
                    //$Line->setDesc('hello world');

                    $SalesItemLineDetail = new QuickBooks_IPP_Object_SalesItemLineDetail();
                    $SalesItemLineDetail->setItemRef('1');
                    $SalesItemLineDetail->setUnitPrice($i['amount']);
                    $SalesItemLineDetail->setQty(1);
                    //$SalesItemLineDetail->setDesc('hello world');

                    $Line->addSalesItemLineDetail($SalesItemLineDetail);

                    $Invoice->addLine($Line);

                    $Invoice->setCustomerRef($resp);
                   

                    if ($respa = $InvoiceService->add($Context, $realm, $Invoice))
                    {
                        //print('Our new Invoice ID is: [' . $respa . ']');
                    }
                    else
                    {
                        //print($InvoiceService->lastError());
                       
                        //print($InvoiceService->lastRequest());

                        //print($InvoiceService->lastResponse());
                    }
                endforeach;
            }
           
            if (isset($twcc_ledger)) {
                foreach ($twcc_ledger as $key => $i):
               
                    //unset($Invoice, $Line, $SalesItemLineDetail);
               
                   
                    $Invoice = new QuickBooks_IPP_Object_Invoice();
           
                    //$Invoice->setDocNumber('WEB123');
                    $Invoice->setTxnDate($i['mas_due_date']);
                   
                    $Line = new QuickBooks_IPP_Object_Line();
                    $Line->setDetailType('SalesItemLineDetail');
                    $Line->setAmount($i['mas_item_net']);

                    $SalesItemLineDetail = new QuickBooks_IPP_Object_SalesItemLineDetail();
                    $SalesItemLineDetail->setItemRef('1');
                    $SalesItemLineDetail->setUnitPrice($i['mas_item_net']);
                    $SalesItemLineDetail->setQty(1);
                    //$SalesItemLineDetail->setDesc('hello world');

                    $Line->addSalesItemLineDetail($SalesItemLineDetail);

                    $Invoice->addLine($Line);

                    $Invoice->setCustomerRef($resp);
                   

                    if ($respa = $InvoiceService->add($Context, $realm, $Invoice))
                    {
                        //print('Our new Invoice ID is: [' . $respa . ']');
                    }
                    else
                    {
                        //print($InvoiceService->lastError());
                    }
                endforeach;
            }
           
           
            $query = "
                UPDATE b1696_tw.contract
                SET
                quickbooks_customer_name=" . $db->qstr($_POST['quickbooks_customer_name']) . "
                WHERE
                contract_id=" . $contract['contract_id']
            ;
           
            $db->Execute($query);
           
            header('Location: /membership2/' . $uri_routing[1] . '/' . $uri_routing[2] . '/#quickbooks');
            exit;
        }
        else {
            print($CustomerService->lastError($Context));
           
            print($CustomerService->lastRequest());
           
            print($CustomerService->lastResponse());
           
        }
    }
}

Re: IPP V3 List all Invoices for a Customer

Last responce (to me) looks right:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Object xsi:type="Customer">
    <TypeOf>Person</TypeOf>
    <GivenName>Jones</GivenName>
    <DisplayName>TWE1100-1 Jones</DisplayName>
</Object>

Any help would be gratefully appreciated.

Tom

Re: IPP V3 List all Invoices for a Customer

This won't work, because v3 doesn't support a findByName operation:

$customers = $CustomerService->findByName($Context, $realm, $_POST['quickbooks_customer_name']);

This is what you should be doing, not sure why it's commented out:

   
    //$customers = $CustomerService->query($Context, $realm, "select * from Customer WHERE FullyQualifiedName='" . $_POST['quickbooks_customer_name'] . "'");

Are you positive that you're using ALL of the latest code from GitHub?

It looks like you might be using some old code... the requests you're generating are v2 requests, not v3. Can you make sure you have the latest code from GitHub?

Re: IPP V3 List all Invoices for a Customer

I'll go and download from GitHub and update the code.

Many thanks Keith!! I apreciate it.

Tom