<commit_before>python-quickbooks
=================

|Build Status| |Coverage Status|


A Python library for accessing the Quickbooks API. Complete rework of
`quickbooks-python`_.

These instructions were written for a Django application. Make sure to
change it to whatever framework/method you’re using.
You can find additional examples of usage in `Integration tests folder`_.

QuickBooks OAuth
------------------------------------------------

As of July 17, 2017, all new applications connecting to QuickBook Online must use OAuth 2.0.
Existing applications can continue to use OAuth 1.0 (See `OAuth 1.0 vs. OAuth 2.0`_ for details)


Connecting your application with quickbooks-cli
-------------------

From the command line, call quickbooks-cli tool passing in either your consumer_key and consumer_secret (OAuth 1.0)
or your client_id and client_secret (OAuth 2.0), plus the OAuth version number:

.. code-block:: console

    quickbooks-cli [-h] [-s] [-p PORT] consumer_key consumer_secret oauth_version


Manually connecting with OAuth version 1.0
--------

1. Create the Authorization URL for your application:

.. code-block:: python

       from quickbooks import Oauth1SessionManager

       session_manager = Oauth1SessionManager(
           sandbox=True,
           consumer_key=QUICKBOOKS_CLIENT_KEY,
           consumer_secret=QUICKBOOKS_CLIENT_SECRET,
       )

       callback_url = 'http://localhost:8000'  # Quickbooks will send the response to this url
       authorize_url = session_manager.get_authorize_url(callback_url)
       request_token = session_manager.request_token
       request_token_secret = session_manager.request_token_secret

Store the ``authorize_url``, ``request_token``, and ``request_token_secret``
for use in the Callback method.

2. Redirect to the ``authorize_url``. Quickbooks will redirect back to your callback_url.
3. Handle the callback:

.. code-block:: python

       session_manager = Oauth1SessionManager(
           sandbox=True,
           consumer_key=QUICKBOOKS_CLIENT_KEY,
           consumer_secret=QUICKBOOKS_CLIENT_SECRET
       )

       session_manager.authorize_url = authorize_url
       session_manager.request_token = request_token
       session_manager.request_token_secret = request_token_secret

       session_manager.get_access_tokens(request.GET['oauth_verifier'])

       realm_id = request.GET['realmId']
       access_token = session_manager.access_token
       access_token_secret = session_manager.access_token_secret

Store ``realm_id``, ``access_token``, and ``access_token_secret`` for later use.


Manually connecting with OAuth version 2.0
--------

1. Create the Authorization URL for your application:

.. code-block:: python

       from quickbooks import Oauth2SessionManager

       session_manager = Oauth2SessionManager(
           sandbox=True,
           client_id=QUICKBOOKS_CLIENT_ID,
           client_secret=QUICKBOOKS_CLIENT_SECRET,
           base_url='http://localhost:8000',
       )

       callback_url = 'http://localhost:8000'  # Quickbooks will send the response to this url
       authorize_url = session_manager.get_authorize_url(callback_url)


2. Redirect to the ``authorize_url``. Quickbooks will redirect back to your callback_url.
3. Handle the callback:

.. code-block:: python

       session_manager = Oauth2SessionManager(
           sandbox=True,
           client_id=QUICKBOOKS_CLIENT_ID,
           client_secret=QUICKBOOKS_CLIENT_SECRET,
           base_url='http://localhost:8000',
       )

       session_manager.get_access_tokens(request.GET['code'])
       access_token = client.access_token

Store ``access_token`` for later use.

Accessing the API
-----------------

Set up an OAuth session manager to pass to the QuickBooks client.
OAuth version 1.0 - Setup the session manager using the stored ``access_token`` and the
``access_token_secret`` and ``realm_id``:

.. code-block:: python

        session_manager = Oauth1SessionManager(
            sandbox=True,
            consumer_key=CONSUMER_KEY,
            consumer_secret=CONSUMER_SECRET,<commit_msg>Fixed another mistake in the readme.<commit_after>python-quickbooks
=================

|Build Status| |Coverage Status|


A Python library for accessing the Quickbooks API. Complete rework of
`quickbooks-python`_.

These instructions were written for a Django application. Make sure to
change it to whatever framework/method you’re using.
You can find additional examples of usage in `Integration tests folder`_.

QuickBooks OAuth
------------------------------------------------

As of July 17, 2017, all new applications connecting to QuickBook Online must use OAuth 2.0.
Existing applications can continue to use OAuth 1.0 (See `OAuth 1.0 vs. OAuth 2.0`_ for details)


Connecting your application with quickbooks-cli
-------------------

From the command line, call quickbooks-cli tool passing in either your consumer_key and consumer_secret (OAuth 1.0)
or your client_id and client_secret (OAuth 2.0), plus the OAuth version number:

.. code-block:: console

    quickbooks-cli [-h] [-s] [-p PORT] consumer_key consumer_secret oauth_version


Manually connecting with OAuth version 1.0
--------

1. Create the Authorization URL for your application:

.. code-block:: python

       from quickbooks import Oauth1SessionManager

       session_manager = Oauth1SessionManager(
           sandbox=True,
           consumer_key=QUICKBOOKS_CLIENT_KEY,
           consumer_secret=QUICKBOOKS_CLIENT_SECRET,
       )

       callback_url = 'http://localhost:8000'  # Quickbooks will send the response to this url
       authorize_url = session_manager.get_authorize_url(callback_url)
       request_token = session_manager.request_token
       request_token_secret = session_manager.request_token_secret

Store the ``authorize_url``, ``request_token``, and ``request_token_secret``
for use in the Callback method.

2. Redirect to the ``authorize_url``. Quickbooks will redirect back to your callback_url.
3. Handle the callback:

.. code-block:: python

       session_manager = Oauth1SessionManager(
           sandbox=True,
           consumer_key=QUICKBOOKS_CLIENT_KEY,
           consumer_secret=QUICKBOOKS_CLIENT_SECRET
       )

       session_manager.authorize_url = authorize_url
       session_manager.request_token = request_token
       session_manager.request_token_secret = request_token_secret

       session_manager.get_access_tokens(request.GET['oauth_verifier'])

       realm_id = request.GET['realmId']
       access_token = session_manager.access_token
       access_token_secret = session_manager.access_token_secret

Store ``realm_id``, ``access_token``, and ``access_token_secret`` for later use.


Manually connecting with OAuth version 2.0
--------

1. Create the Authorization URL for your application:

.. code-block:: python

       from quickbooks import Oauth2SessionManager

       session_manager = Oauth2SessionManager(
           sandbox=True,
           client_id=QUICKBOOKS_CLIENT_ID,
           client_secret=QUICKBOOKS_CLIENT_SECRET,
           base_url='http://localhost:8000',
       )

       callback_url = 'http://localhost:8000'  # Quickbooks will send the response to this url
       authorize_url = session_manager.get_authorize_url(callback_url)


2. Redirect to the ``authorize_url``. Quickbooks will redirect back to your callback_url.
3. Handle the callback:

.. code-block:: python

       session_manager = Oauth2SessionManager(
           sandbox=True,
           client_id=QUICKBOOKS_CLIENT_ID,
           client_secret=QUICKBOOKS_CLIENT_SECRET,
           base_url='http://localhost:8000',
       )

       session_manager.get_access_tokens(request.GET['code'])
       access_token = session_manager.access_token

Store ``access_token`` for later use.

Accessing the API
-----------------

Set up an OAuth session manager to pass to the QuickBooks client.
OAuth version 1.0 - Setup the session manager using the stored ``access_token`` and the
``access_token_secret`` and ``realm_id``:

.. code-block:: python

        session_manager = Oauth1SessionManager(
            sandbox=True,
            consumer_key=CONSUMER_KEY,
            consumer_secret=CONSUMER_SECRET,
{'fraction_non_alphanumeric': 0.0966130604288499, 'fraction_numerical': 0.012914230019493177, 'mean_word_length': 3.2292632663575476, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6660689', 'n_tokens_mistral': 2383, 'n_tokens_neox': 2290, 'n_words': 660}