cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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.

Message 1 of 16
latest reply
1 BEST ANSWER

Accepted Solutions

Re: How to subscribe to API notifications?

Looks 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..:

Notifications are a great way to get real-time information about events on the eBay site, but you should always use API calls to make sure you are getting the information you need. For example, if you have subscribed to AuctionCheckoutComplete notification, you should also set up periodic polling of GetOrders.

 

View Best Answer in original post

Message 12 of 16
latest reply
15 REPLIES 15

Re: How to subscribe to API notifications?

I 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.

 

 

Message 2 of 16
latest reply

Re: How to subscribe to API notifications?

Additionally, 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

Message 3 of 16
latest reply

Re: How to subscribe to API notifications?

Thanks, will look into that. The response.content is a lot more useful.

Message 4 of 16
latest reply

Re: How to subscribe to API notifications?

I 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.

 

Message 5 of 16
latest reply

Re: How to subscribe to API notifications?

Still 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>

 

Message 6 of 16
latest reply

Re: How to subscribe to API notifications?

Like 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?

 

 

Message 7 of 16
latest reply

Re: How to subscribe to API notifications?

I'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 😞

 

Message 8 of 16
latest reply

Re: How to subscribe to API notifications?

The plot thickens. I found a cached question on eBay forums from a few years ago (No longer there and no replies 😞

 

I can also see in my `GetNotificationsUsage` call that notifications are not being sent out. Since `ItemRevised`is working fine, i can only assume this is a bug 


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. 

Message 9 of 16
latest reply

Re: How to subscribe to API notifications?

Interesting.. 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..

 

			<xs:enumeration value="ReadyToShip">
						This notification is sent to a subscribed seller after the buyer's payment on an order has cleared.

			<xs:enumeration value="AuctionCheckoutComplete">
						This notification is sent to the subscribed seller when the winning bidder
						or buyer has paid for the auction or fixed-price item and completed the checkout process.
						For multiple line item orders, AuctionCheckoutComplete notification is only generated for one of the line items in the order.

and of course.. which should be working
			<xs:enumeration value="ItemSold">
						This notification is sent to a subscribed seller when an eBay listing ends in a sale.

ReadyToShip might not be available to all markets though.

Message 10 of 16
latest reply

Re: How to subscribe to API notifications?

Out 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

This notification is sent to the subscribed seller after a single or multiple-quantity, fixed-price listing ends, and the listing had at least one sale while it was active.

Applies to Sellers. This notification is only applicable for fixed-price listings.

 

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.

 

Message 11 of 16
latest reply

Re: How to subscribe to API notifications?

Looks 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..:

Notifications are a great way to get real-time information about events on the eBay site, but you should always use API calls to make sure you are getting the information you need. For example, if you have subscribed to AuctionCheckoutComplete notification, you should also set up periodic polling of GetOrders.

 

Message 12 of 16
latest reply

Re: How to subscribe to API notifications?

That explains it, all of my listings are multi quantity listing, so the listing never ends. When it's out of stock I just keep adding to it. 

 

It shouldn't be called ItemSold 😁

 

I'll hunt around and look for another suitable API. Maybe ReadyToShip might work. 

 

eBay sure don't make this easy.

Message 13 of 16
latest reply

Re: How to subscribe to API notifications?

No luck there:

 

NotificationEventTypeCodeType.ReadyToShip (added): New Seller Payout notification sent to a German or Austrian seller when the buyer has paid for the order.

 

😫

Message 14 of 16
latest reply

Re: How to subscribe to API notifications?

Finally got it working using FixedPriceTransaction

 

Thanks for the help in pointing me in the right direction.

Message 15 of 16
latest reply