How to subscribe to API notifications?
New to API programming and am trying to setup eBay to call my website php script when a item is sold.
The more I read up about this on eBay dev site, the more confused I get.
I have setup my account and credentials and have that all working with a phython script to read stock levels, so I know all the dev_id, app_id, cert_id is all working.
If I understand correctly I need to to a API call to eBay to subscribe to notificationswhich I've done with:
!/usr/bin/env python3
import requests
import xml.etree.ElementTree as ET
# Set your eBay API credentials
dev_id = "MY_DEVKEY"
app_id = "MY_APPKEY"
cert_id = "MY_CERTID"
auth_token = "TOKEN"
# Set up the Trading API credentials
api_endpoint = 'https://api.ebay.com/ws/api.dll'
# Set up the request headers
headers = {
'X-EBAY-API-COMPATIBILITY-LEVEL': '1085',
'X-EBAY-API-DEV-NAME': dev_id,
'X-EBAY-API-APP-NAME': app_id,
'X-EBAY-API-CERT-NAME': cert_id,
'X-EBAY-API-CALL-NAME': 'GetItem',
'X-EBAY-API-SITEID': '3',
'Content-Type': 'text/xml'
}
# Set up the request payload
payload = f"""
<?xml version="1.0" encoding="utf-8"?>
<GetNotificationPreferencesRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<ApplicationDeliveryPreferences>
<AlertEnable>Enable</AlertEnable>
<ApplicationEnable>Enable</ApplicationEnable>
<ApplicationURL>http://api.mywebsite.co.uk/ebay.php</ApplicationURL>
<DeviceType>Platform</DeviceType>
</ApplicationDeliveryPreferences>
<UserDeliveryPreferenceArray>
<NotificationEnable>
<EventType>ItemSold</EventType>
<EventEnable>Enable</EventEnable>
</NotificationEnable>
</UserDeliveryPreferenceArray>
</GetNotificationPreferencesRequest>
"""
# Send the request to the Trading API
response = requests.post(api_endpoint, headers=headers, data=payload)
print (response)When I run this I get a 200 response back - so am I correct in assuming the subscription went in ok?
I've just sold a item and have been monitoring my web logs and not seeing any connects.
Any tips on what I'm missing, or any decent beginner guide on how to set this up.
15 comments
myretrostore-uk
OP3 years agoFinally got it working using FixedPriceTransaction
Thanks for the help in pointing me in the right direction.
five_notch_trading_post
·3 years agoNice, I must have scrolled too quickly over the schema when I did the quick visual scan, can't believe I missed that one. Should prove useful down the road for me as well.
Thanks.
myretrostore-uk
OP3 years ago · EditedNo luck there:
NotificationEventTypeCodeType.ReadyToShip (added): New Seller Payout notification sent to a German or Austrian seller when the buyer has paid for the order.
😫
myretrostore-uk
OP3 years agoStill no luck - not seeing any requests being sent to my website.
When I run a a request to GetNotificationPreferencesRequest I get:
<Ack>Success</Ack>
<ApplicationURL>https://api.mywebsite.com/ebay-api.php</ApplicationURL>
<ApplicationEnable>Enable</ApplicationEnable>
<AlertEmail>mailto:my@email.com</AlertEmail>
<AlertEnable>Enable</AlertEnable>
<NotificationPayloadType>eBLSchemaSOAP</NotificationPayloadType>
<DeviceType>Platform</DeviceType>
<PayloadEncodingType>SOAP</PayloadEncodingType>
<PayloadVersion>1201</PayloadVersion>
five_notch_trading_post
·3 years agoLike I said, I haven't set this up myself, so I am unsure the end result, but just to check a couple things:
did you set up a UserDeliveryPreferenceArray with the Set?
such as something like:
<UserDeliveryPreferenceArray>
<NotificationEnable>
<EventType>BidReceived</EventType>
<EventEnable>Enable</EventEnable>
</NotificationEnable>
<NotificationEnable>
<EventType>Feedback</EventType>
<EventEnable>Enable</EventEnable>
</NotificationEnable>
for the alerts you want.
And if you change <PreferenceLevel> from Application to User on the Get, is the Array reflected in the response?
myretrostore-uk
OP3 years ago · EditedI've specified the following:
<UserDeliveryPreferenceArray>
<NotificationEnable>
<EventType>ItemSold</EventType>
<EventEnable>Enable</EventEnable>
</NotificationEnable>
</UserDeliveryPreferenceArray>
I've set the PreferenceLevel to User and get a match, so it's definately being set.
<Ack>Success</Ack>
<Version>1173</Version>
<Build>E1173_CORE_APINOTIFY_19146596_R1</Build>
<UserDeliveryPreferenceArray><NotificationEnable><EventType>ItemSold</EventType><EventEnable>Enable</EventEnable></NotificationEnable></UserDeliveryPreferenceArray>
Looks like it seems it's all setup correctly but something must be missing 😞
myretrostore-uk
OP3 years ago · EditedThe plot thickens. I found a cached question on eBay forums from a few years ago (No longer there and no replies 😞
I've tested with ItemRevised and it's working, but not with ItemSold. It can't still be a bug after all these years?!
Will have to keep Googling.
five_notch_trading_post
·3 years agoInteresting.. Good to know at least, I don't have server space so I wont be attempting it's use for a while..
I was just looking through the schema and did a quick look at the enum, I am not sure if either of these other 2 event types might be of partial help..
ReadyToShip might not be available to all markets though.
five_notch_trading_post
·3 years agoOut of curiosity, on your account under Account Settings > Selling Preferences.
Do you have
Multi-quantity listings>
Listings stay active when you're out of stock
Set / turned on? (it is by default for many these days).
As in, when an item sells, does it go to quantity zero, and still show up in your Active listings dashboard rather than going directly to ended items?
This would explain the behavior if so
You would have to turn that setting off if it is on to get it to trigger an alert. And for multi-quantity listings, you won't receive an alert until all items are gone and the listing goes in to an ended state.
five_notch_trading_post
·3 years agoLooks like that is likely it, looks like most of your listings are multi-quantity, so the listing doesn't end with a sale, so you would have to try AuctionCheckoutComplete / ReadyToShip to get an alert per-sale.
Docs also suggest not to rely 100% on that notification..:
myretrostore-uk
OP3 years agoI think I might have fixed it - will see if I get a notification on the next sale.
A few things were wrong - using the reponse.content make it a lot easier to see what was wrong.
X-EBAY-API-CALL-NAME was set to incorrect type
RequesterCredentials was also missing.
I"ve done a SetNotificationPreferencesRequest and can see success ACK
Then on a GetNotificationPreferencesRequest I can see what I set.
five_notch_trading_post
·3 years agoAdditionally, make sure X-EBAY-API-CALL-NAME matches the xml portion before "Request", i.e. GetItem for GetItemRequest xml, GetNotificationPreferences for GetNotificationPreferencesRequest xml etc.
You also need to have a "X-EBAY-API-IAF-TOKEN" header set for your token if that isn't being included.
You will get response 200 even if lacking all of that, which just means the server responded with some content. The indicators of what actually went right or wrong will be in the content/text
five_notch_trading_post
·3 years agoI have not done this myself so I can't speak for the end result.
But to just note a couple things,
"GetNotificationPreferencesRequest" is for getting the preferences, you should use "SetNotificationPreferencesRequest".
You should also look at the response.content / response.text variables of that response object, they will have the detailed results of your call. I don't see any specific fields of interest returned for "SetNotificationPreferencesResponse", but it will at least show you <Ack>Success</Ack>. Subsequently using the Get and looking at those same variables should show some information on things you've set.
myretrostore-uk
OP3 years agoThanks, will look into that. The response.content is a lot more useful.