Coder Social home page Coder Social logo

python-harvest's Introduction

Tests Version License Versions

Installation

Python 3 and above:

pip install "python-harvest-redux>=3.0"

For Python 2 or below:

pip install "python-harvest-redux==2.0.2"

Usage

import harvest
client = harvest.Harvest("https://COMPANYNAME.harvestapp.com", "EMAIL", "PASSWORD")
client.who_am_i

How to use OAuth2

Token must look like this:

token = {
  'token_type': 'bearer',
  'access_token': 'your access token',
  'refresh_token': 'your refresh token',
  'expires_in': 64799,
}

For information on how to get initial tokens see: https://github.com/harvesthq/api/blob/master/Authentication/OAuth%202.0.md

import harvest
client = harvest.Harvest("https://COMPANYNAME.harvestapp.com", client_id=client_id, token=token)
client.who_am_i

Contributions

Contributions are welcome. Please submit a pull request and make sure you adhere to PEP-8 coding guidelines. I'll review your patch and will accept if it looks good.

TODOs

  • Tests
  • Full OAuth workflow
  • More documentation

License

python-harvest is licensed under Apache 2.0. See LICENSE for more details.

Authors

See AUTHORS.

python-harvest's People

Contributors

bendavis78 avatar benkonrath avatar bwghughes avatar casdr avatar dlo avatar jhosmer avatar joseph-levine-fjorge avatar maartenkling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-harvest's Issues

PyPi Releases are outdated

It looks like this project was being pushed to PyPi at one time, but the releases there are no longer up to date.

harvest.Harvest() error

I get this error when I try to use harvest.Harvest

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Lunchbox\Desktop\Dev\PCTEST\EMC-Automation-master\lib\site-packages\harvest\harvest.py", line 55, in __init__
    self.__headers['Authorization'] = 'Basic {0}'.format(enc64('{self.email}:{self.password}'.format(self=self)))
  File "C:\Users\Lunchbox\Desktop\Dev\PCTEST\EMC-Automation-master\lib\base64.py", line 58, in b64encode
    encoded = binascii.b2a_base64(s, newline=False)

pip?

Sorry I'm still kind of new to Python. Is there a pip install command available for this module? I tried Harvest-Time-Tracking-API-Client, which is what shows up upon "pip search harvest", but it didn't work.

Thanks!

Supporting Harvest API v2 and OAuth2

Hi Everyone,

I am new to OAuth2 but would like to support it in the move to Harvest API v2 (if that's worthwhile). To do this I need to know about the use cases of python-harvest and where it would be used in conjunction with OAuth2. I am guessing it is in a web app or mobile app context...?

Is there a need to support Cross-Origin Resource Sharing to get python-harvest to work with OAuth2? (eg; authenticate elsewhere and pass authority to an instance of python-harvest)

I have found a tutorial and sample code which steps through the various flows of OAuth2 (link below). Through this I have made a client that uses the Authorization Code flow with Harvest. from what I have seen going through this tutorial, the best approach might be to make a flask-harvest client and leave the plain-old-python integration use cases to the Personal Access Token.

https://medium.com/@ratrosy/building-a-basic-authorization-server-using-authorization-code-flow-c06866859fb1

Be warned, if you go down the above path you will need to support HTTPS to use Harvest. Be prepared to make self-signed certificates and register your own authority.

As things stand I am confused as to how the current support for OAuth2 works. It doesn't seem to align with any of the flows I have seen.

Harvest API v2 support

Hi everyone,

I've been working on supporting the Harvest API v2. I have chosen to re-package the ordered dict response objects as dataclasses. This was working well enough until I found two objects with fields named "from". The trouble: "from" is a Python key word and so I'm having trouble instantiating a dataclass object where one argument is "from" (I'm surprised the dataclass didn't complain).

@DataClass
class TimeImport:
summary_type: str
from: str = None
to: str = None

The problematic syntax:
my_time_import = harvest.TimeImport(summary_type='task', from='2017-03-01', to='2017-03-31')

Current approach is to not support the "from" attribute on those two objects. Obviously this isn't a solution.

I expect a petition to have those fields re-named or aliased may not get far.

Any advice on how to work around this would be appreciated.

To find the fields in the doco: In the invoices section, under "Create an invoice based on tracked time and expenses" on the line_items_import object there are two children objects, time import and expense import. Each of these children have date fields called "from". Everywhere else in the API there's a descriptor as to what it is from eg; sent_from.

https://help.getharvest.com/api-v2/invoices-api/invoices/invoices/

I'm yet to identify any other situations where "from" has been used as a field name without qualification.

Currently I have introduced support for:

HTTP PUSH
dataclasses

get, create, update, delete;

  • Client Contacts
  • Clients
  • Invoice Messages
  • Invoice Payments

get;

  • Company
  • Invoice
  • Invoice Item Categories
  • Estimate Messages
  • Estimates
  • Estimate Item Categories
  • Expenses
  • Expense Categories
  • Tasks
  • Time Estimates
  • Project User Assignments
  • Project Task Assignments
  • Projects
  • Roles
  • User Cost Rates
  • User Project Assignments
  • Users

Cheers.

harvest.harvest.HarvestError: No JSON object could be decoded

I get this error:

harvest.harvest.HarvestError: No JSON object could be decoded

on a successful delete request. I am not asking for a decodable JSON object, necessarily, but the code is attempting to return one.

My current 'solution' is to throw this in a try: except block and put the confirmation in the except block, but that's obviously suboptimal.

What's going on here, and what can I do to utilize this functionality correctly?

Excel toolkit / example code

Assuming that Excel is a common enough element in people's experience of integrating accounting systems...

Is there an appetite to include a set of toolkits or some-other-how example code to help people use the python-harvest library in some of the more common Excel+Python situations?

For example:

  • methods which can be used in xlwings
    -- the fundamental objects can turn up in a worksheet
    -- the reports (as found in Harvest) can turn up in a worksheet

  • methods which can be used in openpyxl
    -- the fundamental objects can turn up in a worksheet
    -- the reports (as found in Harvest) can turn up in a worksheet

  • methods which can be used on Excel using win32com
    -- the fundamental objects can turn up in a worksheet
    -- the reports (as found in Harvest) can turn up in a worksheet

The expression between them is really similar. And there's a heap of really annoying boilerplate to get the columns out of the ordered dict (through dataclasses?) and into Excel rows.

Is this too much maintenance for no real gain?

demo code should be updated

The code of demo should be :

token = harv.fetch_token("https://id.getharvest.com/api/v2/oauth2/token", client_secret="CLIENT SECRET", authorization_response=response_uri, include_client_id=True, state=state)

otherwise you will got exception says:

(invalid_request) 'client_id', 'client_secret' required

version: v2_dev

Rate limiting and pagination

Hi,

I was taking a look through the code, but could not find anything pertaining to rate limiting and pagination. Does the code address either for the API?

Thanks.

I installed module OK, example does not work

Collecting python-harvest
  Downloading python-harvest-1.0.4.tar.gz
Requirement already satisfied (use --upgrade to upgrade): requests in /Users/peter/.rvm/lib/python2.7/site-packages (from python-harvest)
Installing collected packages: python-harvest
  Running setup.py install for python-harvest
Successfully installed python-harvest-1.0.4
Python 2.7.9 (default, Jan 18 2015, 08:53:24) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Harvest
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named Harvest

tasks() error (400)

>>> import harvest
>>> client = harvest.Harvest(...)
>>> client.tasks()
<Response [400]>
>>> res = client.tasks()
>>> res.text
'HTTP GET requests with a body are not accepted.'

Python 3.8.9 on linux
python-harvest-redux 4.0.0

Refreshed tokens?

How does one use the updates from #19 to request a new token? It seems that OAuth2 isn't fully supported if token refresh isn't working. There's no mention of refreshing token in the Readme.

Harvest API v1 to Harvest API v2

Hi,

I'm writing an accounting integration between Harvest and elsewhere. Thanks to @benkonrath for the invoice support and @joseph-levine-fjorge for the personal token work I can do most of what I need.

I have found, however, invoice statuses (Harvest API v1) are now called state (HArvest API v2) and have a different collection of possible values. There are other changes which appear to use a profoundly different model between the two API versions.

I am expecting to work predominantly in Harvest API v2.

At the moment, by way of invoice support and personal access tokens, there is an amount of code which is crossing over. My changes will require a break in backwards compatibility or, more accurately, direct support for API v2.

Is there a considered pathway to support API v2 in python-harvest?

readme is incorrect

  1. Must import Harvest: >>> from harvest import Harvest
  2. harvest.HarvestStatus.get() does not work: HarvestStatus is not a module.
  3. The call client.get_today() is wrong: you can however call with just 'client.today'

OAuth2?

Hi. The token shows refresh_token and access_token. Via the Authorized OAuth2 API Clients in harvest I only see client_id and client_secret. Where do I find/create refresh/access tokens to use with this library?

Thanks!

Tests and Alpha

Hi @dlo,
I have been able to write a handful of tests as per the Harvest API v2 doco.

Not necessarily comprehensive but a reasonable start.

What are the requirements in terms of moving toward an alpha release?

Cheers

When using basic auth the authorization header is wrong in Python 3

The authorization header is set in line 55 like this:

self.__headers['Authorization'] = 'Basic {0}'.format(enc64("{self.email}:{self.password}".format(self=self).encode("utf8")))

This produces a string like:
'Basic b\'some_base_64\''

Instead of:
'Basic some_base_64'

This can be simply fixed by calling .decode() on the Base64 encoded bytes.

Missing access token error

I've got an OAuth setup going, but whenever I try to do anything on the Harvest client object I get an error...

----> 1 h.who_am_i

/vagrant/venv/local/lib/python2.7/site-packages/harvest/harvest.pyc in who_am_i(self)
     73     @property
     74     def who_am_i(self):
---> 75         return self._get('/account/who_am_i')
     76
     77     ## Client Contacts

/vagrant/venv/local/lib/python2.7/site-packages/harvest/harvest.pyc in _get(self, path, data)
    308
    309     def _get(self, path='/', data=None):
--> 310         return self._request('GET', path, data)
    311
    312     def _post(self, path='/', data=None):

/vagrant/venv/local/lib/python2.7/site-packages/harvest/harvest.pyc in _request(self, method, path, data)
    354             return resp
    355         except Exception, e:
--> 356             raise HarvestError(e)
    357
    358
HarvestError: Missing access token.

The token is in place correctly, and it's still valid (only just created).

In [12]: h.token
Out[12]: u'[A VALID TOKEN HERE]'

In [13]: h.uri
Out[13]: 'https://api.harvestapp.com'

In [14]: h.client_id
Out[14]: '[CORRECT CLIENT ID HERE]'

The client is created with h = harvest.Harvest(url, client_id=client_id, token=token)

Any ideas?

Beta release of Harvest API v2 support

Hi @dlo, is there potential to arrange a beta release of the Harvest API v2 python-harvest?

v2_dev currently supports all actions on all entities, the modern authentication paradigm (eg; OAuth2, including refresh tokens in some circumstances), rate limiting and uploading receipts to expenses.

I am using much of the library for an integration but would like to start opening it up to others.

Cheers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.