Skip to content

Commit d0c7771

Browse files
committed
Add affiliate headers to the Shopping API back-end
1 parent 52975fe commit d0c7771

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

Changes

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Changes for ebaysdk
22

33
0.1.11
4+
- Add affiliate headers to the Shopping API back-end
45
- https://github.com/timotheus/ebaysdk-python/issues/40
56
fix datatype issue with error codes from the shopping API
67

ebay.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ svcs.ebay.com:
2727
open.api.ebay.com:
2828
appid: ENTER_YOUR_APPID_HERE
2929
version: 671
30+
31+
# Optional affiliate tracking
32+
# http://developer.ebay.com/DevZone/shopping/docs/Concepts/ShoppingAPI_FormatOverview.html#StandardURLParameters
33+
trackingid: ENTER_YOUR_TRACKINGID_HERE
34+
trackingpartnercode: ENTER_YOUR_PARTNERCODE_HERE

ebaysdk/__init__.py

+24-4
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ def __init__(self, **kwargs):
461461
config_file -- YAML defaults (default: ebay.yaml)
462462
debug -- debugging enabled (default: False)
463463
warnings -- warnings enabled (default: True)
464-
errors -- errors enabled (default: True)
464+
errors -- errors enabled (default: True)
465465
uri -- API endpoint uri (default: /shopping)
466466
appid -- eBay application id
467467
siteid -- eBay country site id (default: 0 (US))
@@ -471,8 +471,14 @@ def __init__(self, **kwargs):
471471
proxy_port -- proxy port number
472472
timeout -- HTTP request timeout (default: 20)
473473
parallel -- ebaysdk parallel object
474-
response_encoding -- API encoding (default: XML)
475-
request_encoding -- API encoding (default: XML)
474+
trackingid -- ID to identify you to your tracking partner
475+
trackingpartnercode -- third party who is your tracking partner
476+
response_encoding -- API encoding (default: XML)
477+
request_encoding -- API encoding (default: XML)
478+
479+
More affiliate tracking info:
480+
http://developer.ebay.com/DevZone/shopping/docs/Concepts/ShoppingAPI_FormatOverview.html#StandardURLParameters
481+
476482
"""
477483
ebaybase.__init__(self, method='POST', **kwargs)
478484

@@ -500,12 +506,14 @@ def __init__(self, **kwargs):
500506
self.set_config('proxy_port', None)
501507
self.set_config('appid', None)
502508
self.set_config('version', '799')
509+
self.set_config('trackingid', None)
510+
self.set_config('trackingpartnercode', None)
503511

504512
if self.api_config['https'] and self.debug:
505513
print("HTTPS is not supported on the Shopping API.")
506514

507515
def _build_request_headers(self):
508-
return {
516+
headers = {
509517
"X-EBAY-API-VERSION": self.api_config.get('version', ''),
510518
"X-EBAY-API-APP-ID": self.api_config.get('appid', ''),
511519
"X-EBAY-API-SITEID": self.api_config.get('siteid', ''),
@@ -514,6 +522,18 @@ def _build_request_headers(self):
514522
"Content-Type": "text/xml"
515523
}
516524

525+
if self.api_config.get('trackingid', None):
526+
headers.update({
527+
"X-EBAY-API-TRACKING-ID": self.api_config.get('trackingid', '')
528+
})
529+
530+
if self.api_config.get('trackingpartnercode', None):
531+
headers.update({
532+
"X-EBAY-API-TRACKING-PARTNER-CODE": self.api_config.get('trackingpartnercode', '')
533+
})
534+
535+
return headers
536+
517537
def _build_request_xml(self):
518538
xml = "<?xml version='1.0' encoding='utf-8'?>"
519539
xml += "<" + self.verb + "Request xmlns=\"urn:ebay:apis:eBLBaseComponents\">"

samples/shopping.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,20 @@ def categoryInfo(opts):
130130
api = shopping(debug=opts.debug, appid=opts.appid, config_file=opts.yaml,
131131
warnings=True)
132132

133-
api.execute('getCategoryInfo', {"CategoryID": 3410})
133+
api.execute('GetCategoryInfo', {"CategoryID": 3410})
134+
135+
dump(api, full=False)
136+
137+
def with_affiliate_info(opts):
138+
api = shopping(debug=opts.debug, appid=opts.appid, config_file=opts.yaml,
139+
warnings=True, trackingid=1234, trackingpartnercode=9)
140+
141+
mySearch = {
142+
"MaxKeywords": 10,
143+
"QueryKeywords": 'shirt',
144+
}
145+
146+
api.execute('FindPopularSearches', mySearch)
134147

135148
dump(api, full=False)
136149

@@ -139,3 +152,4 @@ def categoryInfo(opts):
139152
run(opts)
140153
popularSearches(opts)
141154
categoryInfo(opts)
155+
with_affiliate_info(opts)

0 commit comments

Comments
 (0)