+ def fetch_fortnox(self, customer_id=None):
+ """ Fetch all active customers from Fortnox API. Return as dict keyed on email."""
+ res = None
+ customers = {}
+ headers = {"Access-Token":settings.FORTNOX_ACCESS_TOKEN,
+ "Client-Secret":settings.FORTNOX_CLIENT_SECRET,
+ "Content-Type":"application/json",
+ "Accept":"application/json" }
+ if customer_id: #We already have id, use that to update info in local db
+ res = requests.get(f"https://api.fortnox.se/3/customers/{customer_id}?filter=active", headers=headers)
+ res = res.json()
+ res['Customer'] = [res['Customer']]
+ else:
+ res = requests.get("https://api.fortnox.se/3/customers?filter=active", headers=headers)
+
+ for customer in res['Customer']:
+ customers[customer['Email']] = customer
+ return customers
+