Skip to content

Instantly share code, notes, and snippets.

@emihir0
Created August 27, 2016 11:02
Show Gist options
  • Save emihir0/f697978faf6a4fcbc5f3c6879414e920 to your computer and use it in GitHub Desktop.
Save emihir0/f697978faf6a4fcbc5f3c6879414e920 to your computer and use it in GitHub Desktop.
import requests
import json
from urlparse import urlparse
app_id = 'some_app_id'
app_secret = 'some_app_secret'
token = 'some_token'
class Linnworks(object):
def __init__(self, app_id, app_secret, token):
header = {
'Host': 'api.linnworks.net',
'Connection': 'keep-alive',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Origin': 'https://www.linnworks.net',
'Accept-Language': 'en',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Referer': 'https://www.linnworks.net/',
'Accept-Encoding': 'gzip, deflate',
}
payload = {
'applicationId': app_id,
'applicationSecret': app_secret,
'token': token,
}
r = requests.post('https://api.linnworks.net//api/Auth/AuthorizeByApplication', data=payload, headers=header)
r.raise_for_status()
self.session_token = r.json()['Token']
self.session_server = r.json()['Server']
self.ebay1_view_id = 'some_view_id' #I use just one view and so I got the id from browser inspector
self.ebay1_location_id = '00000000-0000-0000-0000-000000000000' #I use just one location and so I got the id from browser inspector
#works fine
print self.session_token
print self.session_server
def get_inventory_items(self):
header = {
'Host': urlparse(self.session_server).hostname,
'Connection': 'keep-alive',
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Origin': 'https://www.linnworks.net',
'Accept-Language': 'en',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Referer': 'https://www.linnworks.net/',
'Accept-Encoding': 'gzip, deflate',
'Authorization': self.session_token,
}
payload = {
'view': {
"Id": self.ebay1_view_id,
"Name": "EBAY",
"Mode": "All",
"Source": "All",
"SubSource": "Show all",
"CountryCode": "All",
"CountryName": "All",
"Listing": "All",
"ShowOnlyChanged": False,
"IncludeProducts": "All",
"Filters": [{
"FilterName": "General",
"DisplayName": "SKU / Title / Barcode",
"Field": "String",
"Condition": "Contains",
"Value": None}],
"Columns": [{
"ColumnName": "SKU",
"DisplayName": "SKU",
"Group":"General",
"Field": "String",
"SortDirection": 0,
"Width": 150,
"IsEditable": False}],
"Channels": [{"Source": "EBAY","SubSource": "EBAY1"}],
"IsSearchRequired": True,
},
'stockLocationIds': [self.ebay1_location_id],
'startIndex': 1,
'itemsCount': 100,
'preloadChilds': False,
}
r = requests.post(self.session_server + '/api/Inventory/GetInventoryItems',
headers=header,
data=json.dumps(payload) #This SHOULD correct the python Boolean and None into acceptable format
)
print r.text
# prints this: {"Message":"The request is invalid."}
# TODO: fetch item ids
if __name__ == '__main__':
lin = Linnworks(app_id, app_secret, token)
lin.get_inventory_items()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment