Created
October 28, 2011 05:33
-
-
Save joneskoo/1321688 to your computer and use it in GitHub Desktop.
Postita API example with requests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
import requests | |
import json | |
import base64 | |
URL_ROOT = "https://postita.fi/api/" | |
PDF_PATH = 'muistutusviesti.pdf' | |
USER = None | |
PASS = None | |
def main(): | |
# Encode the PDF | |
with open(PDF_PATH, 'rb') as pdf: | |
pdf_b64 = base64.urlsafe_b64encode(pdf.read()) | |
# We need to create a POST request from our data. | |
payload = dict(pdf=pdf_b64, job_name='Muistutusviesti') | |
r = requests.post(URL_ROOT + 'send/', data=payload, auth=(USER, PASS)) | |
r.raise_for_status() | |
job_info = json.loads(r.content) | |
print job_info | |
# {u'status': u'CO', u'name': u'Muistutusviesti', u'created': u'23.10.2011 01:39:21', u'total_pages': 1, u'recipient_count': 1, u'is_einvoice': False, u'id': 123456, u'is_massmail': False, u'price': u'0.74', u'vat_price': u'0.91'} | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment