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
15 REPLIES 15

How to subscribe to API notifications?

Nice, 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.

Message 16 of 16
latest reply