Інтеграція інтернет-магазину з eBay (API)
eBay надає кілька API: Trading API (застарілий), Sell API (сучасний REST). Для нових інтеграцій використовуємо Sell API. Актуально для продавців, які працюють на міжнародних ринках: US, UK, DE, AU.
Аутентифікація (OAuth2)
import requests
import base64
def get_access_token(client_id: str, client_secret: str) -> str:
credentials = base64.b64encode(f"{client_id}:{client_secret}".encode()).decode()
resp = requests.post(
'https://api.ebay.com/identity/v1/oauth2/token',
headers={'Authorization': f'Basic {credentials}'},
data={
'grant_type': 'client_credentials',
'scope': 'https://api.ebay.com/oauth/api_scope',
}
)
return resp.json()['access_token']
Створення листингу через Inventory API
def create_inventory_item(sku: str, product: dict, token: str) -> None:
headers = {'Authorization': f'Bearer {token}', 'Content-Language': 'de-DE'}
# Створення inventory item
requests.put(
f'https://api.ebay.com/sell/inventory/v1/inventory_item/{sku}',
headers=headers,
json={
'availability': {'shipToLocationAvailability': {'quantity': product['stock']}},
'condition': 'NEW',
'product': {
'title': product['name'],
'description': product['description'],
'imageUrls': product['images'],
'aspects': {'Brand': [product['brand']]},
'ean': [product['ean']],
},
}
)
# Створення offer (об'яви)
requests.post(
'https://api.ebay.com/sell/inventory/v1/offer',
headers=headers,
json={
'sku': sku,
'marketplaceId': 'EBAY_DE',
'format': 'FIXED_PRICE',
'pricingSummary': {
'price': {'value': str(product['price']), 'currency': 'EUR'}
},
'fulfillmentPolicyId': FULFILLMENT_POLICY_ID,
'paymentPolicyId': PAYMENT_POLICY_ID,
'returnPolicyId': RETURN_POLICY_ID,
'merchantLocationKey': WAREHOUSE_KEY,
'categoryId': product['ebay_category_id'],
}
)
Отримання замовлень
def get_orders(token: str, since: str) -> list:
resp = requests.get(
'https://api.ebay.com/sell/fulfillment/v1/order',
headers={'Authorization': f'Bearer {token}'},
params={'filter': f'creationdate:[{since}..{datetime.utcnow().isoformat()}Z]', 'limit': 50}
)
return resp.json().get('orders', [])
eBay Notifications
// Обробник eBay Platform Notifications
Route::post('/webhooks/ebay', function (Request $request) {
// eBay надсилає XML-повідомлення
$xml = simplexml_load_string($request->getContent());
$eventType = (string) $xml->BuyerUserID; // залежить від типу повідомлення
// ... обробка
return response('');
});
Терміни
Реєстрація в eBay Developer Program: 1–3 дні. Інтеграція (листинги + замовлення): 14–20 робочих днів.







