OAuth integration with QuickBooks using Scribe

202 views Asked by At

QuickBooks has it's own SDK Libraries which can easily help to communicate between Third party. But their Library file size is around 6MB which is huge for a simple API integration.

After so much of searching and finding the solution using Scribe I decided to publish this so that other developers can use it.

intuit support are not going to help you with this and will not correct their document.

So basically the Concern is how to integrate with Quickbooks using Scribe

1

There are 1 answers

0
Santosh Giri On

LIBRARY : scribe-1.3.5.jar

public class QBOAuthDemo {
    private static String CONSUMER_KEY = "<Consumer_Key>";
    private static String CONSUMER_SECRET ="<Consumer_Secret>";
    private static String TOKEN = "<Token>";
    private static String TOKEN_SECRET = "<Token_Secret>";
    private static String API_END_URL = "https://sandbox-quickbooks.api.intuit.com/v3";

public static void main(String[] args) throws IOException {
        OAuthService qbService = new ServiceBuilder()
                .provider(QuickBooksAPI.class)
                .apiKey(CONSUMER_KEY)
                .apiSecret(CONSUMER_SECRET)
                .debug()     //In order to Debug and view in Console
                .callback("http://localhost:8080")
                .build();
        Token tokenAccess = new Token(TOKEN, TOKEN_SECRET);
        System.out.println("Token Access = "+tokenAccess);

        OAuthRequest request = new OAuthRequest(Verb.GET, API_END_URL+"/company/<YOUR-COMPANYID>/customer/<customerid>");
        qbService.signRequest(tokenAccess, request);
        request.addHeader("Content-Type","application/xml" );
        Response response = request.send();
        System.out.println(response.getBody());
    }
}

This will simply connect and retrieve the Customer's information in the form of XML (Also Supports JSON)

The Response you'll be getting as

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<IntuitResponse
    xmlns="http://schema.intuit.com/finance/v3" time="2015-06-09T06:07:39.787-07:00">
    <Customer domain="QBO" sparse="false">
        <Id>64</Id>
        <SyncToken>1</SyncToken>
        <MetaData>
            <CreateTime>2015-06-09T03:18:00-07:00</CreateTime>
            <LastUpdatedTime>2015-06-09T03:18:15-07:00</LastUpdatedTime>
        </MetaData>
        <Title>Mr</Title>
        <GivenName>DummyIND</GivenName>
        <MiddleName>B</MiddleName>
        <FamilyName>IND</FamilyName>
        <FullyQualifiedName>IND King Crafts</FullyQualifiedName>
        <CompanyName>IND King Crafts</CompanyName>
        <DisplayName>IND King Crafts</DisplayName>
        <PrintOnCheckName>IND King Crafts</PrintOnCheckName>
        <Active>true</Active>
        <PrimaryPhone>
            <FreeFormNumber>(000) 555-5555</FreeFormNumber>
        </PrimaryPhone>
        <Mobile>
            <FreeFormNumber>555-5555-6666</FreeFormNumber>
        </Mobile>
        <PrimaryEmailAddr>
            <Address>[email protected]</Address>
        </PrimaryEmailAddr>
        <DefaultTaxCodeRef>2</DefaultTaxCodeRef>
        <Taxable>true</Taxable>
        <BillAddr>
            <Id>96</Id>
            <Line1>123 Main Street</Line1>
            <City>Mountain View</City>
            <Country>USA</Country>
            <CountrySubDivisionCode>CA</CountrySubDivisionCode>
            <PostalCode>94042</PostalCode>
            <Lat>37.37982969999999</Lat>
            <Long>-122.114632</Long>
        </BillAddr>
        <ShipAddr>
            <Id>97</Id>
            <Line1>123 Main Street</Line1>
            <City>Mountain View</City>
            <Country>IND</Country>
            <CountrySubDivisionCode>CA</CountrySubDivisionCode>
            <PostalCode>94042</PostalCode>
            <Lat>36.168973</Lat>
            <Long>-96.173524</Long>
        </ShipAddr>
        <Notes>Here are other details.</Notes>
        <Job>false</Job>
        <BillWithParent>false</BillWithParent>
        <Balance>0</Balance>
        <BalanceWithJobs>0</BalanceWithJobs>
        <CurrencyRef name="United States Dollar">USD</CurrencyRef>
        <PreferredDeliveryMethod>Print</PreferredDeliveryMethod>
    </Customer>
</IntuitResponse>

The class file for QuickBooksAPI.JAVA

import org.scribe.builder.api.DefaultApi10a;
import org.scribe.model.Token;

public class QuickBooksAPI extends DefaultApi10a{

    @Override
    public String getAccessTokenEndpoint() {
        return "https://oauth.intuit.com/oauth/v1/get_access_token";
    }

    @Override
    public String getAuthorizationUrl(Token requestToken) {
        String str = String.format("https://appcenter.intuit.com/connect/begin?oauth_token=%s",requestToken.getToken());
        return str;
    }

    @Override
    public String getRequestTokenEndpoint() {
        return "https://oauth.intuit.com/oauth/v1/get_request_token";
    }
}

QuickBooks support HMAC-SHA1 Signature which is automatically handled by Scribe. In order to Perform Batch Operation you can refer URL : QUICKBOOKS BATCHOPERATION