Commit working version of fetching Harvest projects from their API
... not saving it anywhere, yet.
This commit is contained in:
parent
df4dfba188
commit
e1a2b0cd8b
1 changed files with 27 additions and 0 deletions
27
fetch_clients_projects.py
Normal file
27
fetch_clients_projects.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import urllib.request
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
url = "https://api.harvestapp.com/v2/projects?updated_since=2021-05-01"
|
||||||
|
headers = {
|
||||||
|
"User-Agent": "Python Harvest API",
|
||||||
|
"Authorization": "Bearer " + os.environ.get("HARVEST_ACCESS_TOKEN"),
|
||||||
|
"Harvest-Account-ID": os.environ.get("HARVEST_ACCOUNT_ID")
|
||||||
|
}
|
||||||
|
|
||||||
|
request = urllib.request.Request(url=url, headers=headers)
|
||||||
|
response = urllib.request.urlopen(request, timeout=5)
|
||||||
|
responseBody = response.read().decode("utf-8")
|
||||||
|
api_projects = json.loads(responseBody)
|
||||||
|
|
||||||
|
if (len(api_projects["projects"]) == 100):
|
||||||
|
print("You retrieved exactly 100 projects, the API limit. Harvest probably has more. Adjust this script to get additional pages of results or archive some projects!")
|
||||||
|
|
||||||
|
projects = {}
|
||||||
|
for project in api_projects["projects"]:
|
||||||
|
projects[project["name"]] = project["client"]["name"]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue