Advertisement
thimo

Spreadshirt API login & fetch designs working code

May 5th, 2018
965
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2. import hashlib
  3. import time
  4. import requests
  5.  
  6. # configuration
  7. apiKey = "XXX" # api key
  8. secret = "XXX" # api secret
  9. email = "XXX" # login email address
  10. password = "XXX" # login password
  11. userId = "XXX" # account user id
  12.  
  13. # code
  14. xml = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  15. <login xmlns:xlink="http://www.w3.org/1999/xlink"      
  16.       xmlns="http://api.spreadshirt.net">  
  17.   <username>"""+email+"""</username>
  18.   <password>"""+password+"""</password>
  19. </login>"""
  20. log_in = requests.post("https://api.spreadshirt.net/api/v1/sessions", data=xml)
  21. session_id = dict(log_in.headers)["Location"][44:]
  22.  
  23.  
  24. time = str(int(time.time())*1000)
  25. method = "GET"
  26. url = "https://api.spreadshirt.net/api/v1/users/" + userId + "/designs"
  27. data = method + ' ' + url + ' ' + time
  28. sig = hashlib.sha1(str(data + ' ' + secret).encode('utf-8'))
  29.  
  30. header = {"Authorization": "SprdAuth apiKey=\"" + apiKey + "\", data=\"" + data + "\", sig=\"" + sig.hexdigest() + "\", sessionId=\"" +
  31.           session_id + "\"", "User-Agent": "Python-test/1.0 (http://www.spreadplugin.de; thimo@grauerholz.de)", "Content-Type": "application/xml"}
  32. r = requests.get(url, headers=header)
  33. print(r.request.headers)
  34. print(r.text)
Advertisement
RAW Paste Data Copied
Advertisement