Search code examples
phpcakephpcurlintuit-partner-platformquickbooks-online

Update quickbooks invoice with php


We need to update a single invoice in quickbooks online using PHP (CakePHP 1.3). I've looked around and the only thing I've been able to find is the "keith palmer php api" which seems a bit over kill for the simple nature of what we are trying to accomplish.

Has anyone accomplished this? I don't imagine it would take more than a simple curl execution to quickbooks to update an invoice? Please advise.


Solution

  • Has anyone accomplished this?

    Yes! Many people!

    I don't imagine it would take more than a simple curl execution to quickbooks to update an invoice?

    Unfortunately, it does require a bit more than this.

    It requires a bit more than this for 3 main reasons:

    1. Intuit requires you to authenticate to QuickBooks Online (just once) via OAuth. Curl doesn't have built-in OAuth support, so you'll need to use some sort of library or code to sign your OAuth requests. OAuth is not a trivial protocol/signing mechanism.

    2. To update objects in QuickBooks Online, you have to send Intuit the latest SyncToken value. The latest SyncToken value can only be fetched by first querying for the invoice in QuickBooks via the API. i.e. to make an update, you also have to first be able to query.

    3. Intuit requires you to register an "app" to connect to QuickBooks Online. This provides setup steps and requires info for the OAuth flow.

    With that said, using this library:

    Really isn't very difficult.

    Just follow the quick-start guide:

    And check out the example of doing an invoice update:

    It looks something like this:

        $InvoiceService = new QuickBooks_IPP_Service_Invoice();
    
        // Get the existing invoice first (you need the latest SyncToken value)
        $invoices = $InvoiceService->query($Context, $realm, "SELECT * FROM Invoice WHERE Id = '34' ");
        $Invoice = $invoices[0];
    
        print_r($Invoice);
    
        $Invoice->setTxnDate(date('Y-m-d'));  // Update the invoice date to today's date 
    
        if ($resp = $InvoiceService->update($Context, $realm, $Invoice->getId(), $Invoice))
        {
            print('&nbsp; Updated!<br>');
        }