From 782cb1fcec243760ebe2ce0b144ada9eac7223e6 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 1 Jul 2022 12:46:06 -0500 Subject: [PATCH] Fix API call to return all Harvest Projects --- rattail_harvest/harvest/webapi.py | 12 +++++++++++- rattail_harvest/importing/harvest.py | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/rattail_harvest/harvest/webapi.py b/rattail_harvest/harvest/webapi.py index 14c1727..03e57bd 100644 --- a/rattail_harvest/harvest/webapi.py +++ b/rattail_harvest/harvest/webapi.py @@ -122,7 +122,17 @@ class HarvestWebAPI(object): https://help.getharvest.com/api-v2/projects-api/projects/projects/#list-all-projects """ response = self.get('/projects', params=kwargs) - return response.json() + data = response.json() + projects = data['projects'] + while data['next_page']: + + kw = dict(kwargs) + kw['page'] = data['next_page'] + response = self.get('/projects', params=kw) + data = response.json() + projects.extend(data['projects']) + + return projects def get_tasks(self, **kwargs): """ diff --git a/rattail_harvest/importing/harvest.py b/rattail_harvest/importing/harvest.py index a64c88d..6fe466b 100644 --- a/rattail_harvest/importing/harvest.py +++ b/rattail_harvest/importing/harvest.py @@ -151,7 +151,7 @@ class HarvestProjectImporter(FromHarvest, rattail_harvest_importing.model.Harves model.HarvestProject.deleted == None)) def get_host_objects(self): - return self.webapi.get_projects()['projects'] + return self.webapi.get_projects() def normalize_host_object(self, project): data = super(HarvestProjectImporter, self).normalize_host_object(project)