Skip to content

Instantly share code, notes, and snippets.

@michidk
Last active April 17, 2019 08:18
Show Gist options
  • Select an option

  • Save michidk/1640ddf60e9ba19a0cfcc32a8162a7ee to your computer and use it in GitHub Desktop.

Select an option

Save michidk/1640ddf60e9ba19a0cfcc32a8162a7ee to your computer and use it in GitHub Desktop.
Medium: sevDesk API
# we use the requests and json package
import requests
import json
# define request headers
headers = {'Authorization': '<your API-token here>',
'Content-Type': 'application/x-www-form-urlencoded'}
# we got the url from the swagger documentation.
# it's also possible to pass parameters as '?limit=10&embed=contact' to the url, to limit the response array or to embed referenced objects
url = "https://my.sevdesk.de/api/v1/Invoice"
# create the request, for sake of simplicity error handling is omitted here
response = requests.get(url, headers = headers)
# parse the json
json = json.loads(response.content)
# get the invoice data from the root object
invoices = json["objects"]
# now we finally can access the response data
# filter all unpaid invoices using lamdas
# an unpaid invoice, won't have a payment date so return all objects without a payment date
unpaid = list(filter(lambda l: not l["payDate"], invoices))
# now you can use the 'unpaid'-object to do what ever you want, e.g. send all contacts a friendly reminder to pay their invoices.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment