sync

import requests import base64 # 1. Trendyol Setup SELLER_ID = "1140167" TY_AUTH = base64.b64encode(b"Kc0RVeBcMncjGWrTCWzG:pLU8Ihn7SY0zgrD5hZl3").decode() TY_HEADERS = {"Authorization": f"Basic {TY_AUTH}", "Content-Type": "application/json"} # 2. Shopify Setup (Replace with your actual store details) SHOPIFY_URL = "https://estilofresco.myshopify.com/admin/api/2026-01/orders.json" SHOPIFY_TOKEN = "shpat_xxxxxxxxxxxx" # From Phase 1 def sync_orders(): # Get Trendyol Orders (Gulf Region Endpoint) orders_url = f"https://apigw.trendyol.com/integration/sellers/{SELLER_ID}/orders?status=Created" response = requests.get(orders_url, headers=TY_HEADERS) if response.status_code == 200: ty_orders = response.json().get("content", []) for order in ty_orders: # Map Trendyol order to Shopify Format payload = { "order": { "line_items": [{"sku": item["barcode"], "quantity": item["quantity"]} for item in order["lines"]], "customer": {"first_name": order["customerFirstName"], "last_name": order["customerLastName"]}, "financial_status": "paid", "note": f"Trendyol Order: {order['orderNumber']}", "tags": "Trendyol-Import" } } # Post to Shopify requests.post(SHOPIFY_URL, json=payload, headers={"X-Shopify-Access-Token": SHOPIFY_TOKEN}) print(f"Synced Order: {order['orderNumber']}") sync_orders()