This is an article documenting how to parse the notification from eBay and using it to create an order in Shopify.
Why?
Previously, we would receive an eBay notification and create an order record in Zoho Creator. We did the same for when Shopify would process an order. You can see my following articles for more information on these:
- Zoho Creator: Receive eBay Order Notifications via Webhook
- Zoho Creator: Receive JSON via a Shopify Webhook
How?
I'm going to show you the code first of how to parse the eBay Transaction data and then the code to create a Shopify Order:
Parse an eBay Transaction Notification (XML)
x_ResponseBody = input.Payload.getJSON("body"); v_MainNodeName = "GetItemTransactionsResponse"; x_MainNode = x_ResponseBody.subString(x_ResponseBody.indexOf("<" + v_MainNodeName),x_ResponseBody.lastIndexOf(v_MainNodeName) + v_MainNodeName.length() + 1); x_Item = x_MainNode.subString(x_MainNode.indexOf("<Item>"),x_MainNode.indexOf("</Item>") + 7); x_Transaction = x_MainNode.subString(x_MainNode.indexOf("<Transaction>"),x_MainNode.indexOf("</Transaction>") + 14); // // item details v_Item_ID = x_Item.executeXPath("/Item/ItemID/text()").replaceAll("[^0-9]",""); v_Item_ID = if(!isnull(v_Item_ID),v_Item_ID.toLong(),null); v_Item_CategoryID = x_Item.executeXPath("/Item/PrimaryCategory/CategoryID/text()").replaceAll("[^0-9]",""); v_Item_Listing_Start = x_Item.executeXPath("/Item/ListingDetails/StartTime/text()"); v_Item_Listing_End = x_Item.executeXPath("/Item/ListingDetails/EndTime/text()"); v_Item_Selling_Price = x_Item.executeXPath("/Item/SellingStatus/CurrentPrice/text()"); v_Item_Selling_Currency = x_Item.executeXPath("/Item/SellingStatus/CurrentPrice/@currencyID").executeXPath("/currencyID/text()"); v_Item_Selling_Currency = ifnull(v_Item_Selling_Currency,"GBP"); v_Item_Selling_Quantity = x_Item.executeXPath("/Item/SellingStatus/QuantitySold/text()"); v_Item_Title = x_Item.executeXPath("/Item/Title/text()"); v_Item_SKU = x_Item.executeXPath("/Item/SKU/text()"); // // transaction details v_Transaction_ID = x_Transaction.executeXPath("/Transaction/TransactionID/text()").replaceAll("[^0-9]",""); v_Transaction_OrderID = x_Transaction.executeXPath("/Transaction/ExtendedOrderID/text()").replaceAll("[^0-9]",""); v_Transaction_OrderRef = x_Transaction.executeXPath("/Transaction/ExtendedOrderID/text()"); v_Transaction_OrderName = x_Transaction.executeXPath("/Transaction/Buyer/UserID/text()") + " " + zoho.currenttime.toString("dd-MMM-yyyy HH:mm"); v_Transaction_LineItem_ID = x_Transaction.executeXPath("/Transaction/OrderLineItemID/text()"); v_Transaction_Amount = x_Transaction.executeXPath("/Transaction/TransactionPrice/text()"); v_Transaction_Paid = x_Transaction.executeXPath("/Transaction/AmountPaid/text()"); v_Transaction_Currency = x_Transaction.executeXPath("/Transaction/AmountPaid/@currencyID").executeXPath("/currencyID/text()"); v_Transaction_Quantity = x_Transaction.executeXPath("/Transaction/QuantityPurchased/text()"); v_Transaction_Status = x_Transaction.executeXPath("/Transaction/Status/CompleteStatus/text()"); v_Transaction_Method = x_Transaction.executeXPath("/Transaction/Status/PaymentInstrument/text()"); v_Transaction_Adjustment = x_Transaction.executeXPath("/Transaction/ConvertedAdjustmentAmount/text()"); v_Transaction_DateCreated = x_Transaction.executeXPath("/Transaction/CreatedDate/text()"); v_Transaction_DateCreated = if(!isnull(v_Transaction_DateCreated),v_Transaction_DateCreated.getPrefix(".").replaceFirst("T"," ",true).toTime(),zoho.currenttime); v_Transaction_DateModified = x_Transaction.executeXPath("/Transaction/Status/LastTimeModified/text()"); v_Transaction_DateModified = if(!isnull(v_Transaction_DateModified),v_Transaction_DateModified.getPrefix(".").replaceFirst("T"," ",true).toTime(),zoho.currenttime); v_Transaction_DatePaid = x_Transaction.executeXPath("/Transaction/PaidTime/text()"); v_Transaction_DatePaid = if(!isnull(v_Transaction_DatePaid),v_Transaction_DatePaid.getPrefix(".").replaceFirst("T"," ",true).toTime(),zoho.currenttime); // // buyer details v_Transaction_UserID = x_Transaction.executeXPath("/Transaction/Buyer/UserID/text()"); v_Transaction_FeedbackScore = x_Transaction.executeXPath("/Transaction/Buyer/FeedbackScore/text()"); v_Transaction_UserID = x_Transaction.executeXPath("/Transaction/Buyer/UserID/text()"); v_Transaction_Buyer_Email = x_Transaction.executeXPath("/Transaction/Buyer/Email/text()"); v_Transaction_Buyer_FName = x_Transaction.executeXPath("/Transaction/Buyer/UserFirstName/text()"); v_Transaction_Buyer_SName = x_Transaction.executeXPath("/Transaction/Buyer/UserLastName/text()"); v_Transaction_Buyer_StaticEmail = x_Transaction.executeXPath("/Transaction/Buyer/StaticAlias/text()"); v_Transaction_Buyer_MemberSince = x_Transaction.executeXPath("/Transaction/Buyer/RegistrationDate/text()"); v_Transaction_Buyer_MemberSince = if(!isnull(v_Transaction_Buyer_MemberSince),v_Transaction_Buyer_MemberSince.getPrefix(".").replaceFirst("T"," ",true).toTime(),zoho.currenttime); // // shipping details x_Transaction_Shipping_Address = x_Transaction.executeXPath("/Transaction/Buyer/BuyerInfo/ShippingAddress"); v_Transaction_Shipping_Name = x_Transaction_Shipping_Address.executeXPath("/ShippingAddress/Name/text()"); v_Transaction_Shipping_Phone = x_Transaction_Shipping_Address.executeXPath("/ShippingAddress/Phone/text()"); v_Transaction_Shipping_Address_Street1 = x_Transaction_Shipping_Address.executeXPath("/ShippingAddress/Street1/text()"); v_Transaction_Shipping_Address_Street2 = x_Transaction_Shipping_Address.executeXPath("/ShippingAddress/Street2/text()"); v_Transaction_Shipping_Address_City = x_Transaction_Shipping_Address.executeXPath("/ShippingAddress/CityName/text()"); v_Transaction_Shipping_Address_State = x_Transaction_Shipping_Address.executeXPath("/ShippingAddress/StateOrProvince/text()"); v_Transaction_Shipping_Address_Country = x_Transaction_Shipping_Address.executeXPath("/ShippingAddress/CountryName/text()"); v_Transaction_Shipping_Address_Zip = x_Transaction_Shipping_Address.executeXPath("/ShippingAddress/PostalCode/text()"); v_Transaction_Shipping_Address_CountryCode = x_Transaction_Shipping_Address.executeXPath("/ShippingAddress/Country/text()"); v_Transaction_Shipping_Tax = x_Transaction.executeXPath("/Transaction/ShippingDetails/SalesTax/SalesTaxAmount/text()"); v_Transaction_Shipping_Service = x_Transaction.executeXPath("/Transaction/ShippingServiceSelected/ShippingService/text()"); v_Transaction_Shipping_ServiceCost = x_Transaction.executeXPath("/Transaction/ShippingServiceSelected/ShippingServiceCost/text()"); v_Transaction_Shipping_ServiceSelected = x_Transaction.executeXPath("/Transaction/ShippingServiceSelected/ShippingService/text()"); v_Transaction_Shipping_ExpectedDeliveryMin = x_Transaction.executeXPath("/Transaction/ShippingServiceSelected/ShippingPackageInfo/EstimatedDeliveryTimeMin/text()"); v_Transaction_Shipping_ExpectedDeliveryMax = x_Transaction.executeXPath("/Transaction/ShippingServiceSelected/ShippingPackageInfo/EstimatedDeliveryTimeMax/text()"); // // payment details v_Transaction_EbayPaymentStatus = x_Transaction.executeXPath("/Transaction/Status/eBayPaymentStatus/text()"); v_Transaction_PaymentStatus = x_Transaction.executeXPath("/Transaction/MonetaryDetails/Payments/Payment/PaymentStatus/text()"); v_Transaction_Status_Payment = x_Transaction.executeXPath("/Transaction/Status/eBayPaymentStatus/text()"); v_Transaction_Status_Checkout = x_Transaction.executeXPath("/Transaction/Status/CheckoutStatus/text()"); v_Transaction_Payments_Status = x_Transaction.executeXPath("/Transaction/MonetaryDetails/Payments/Payment/PaymentStatus/text()"); v_Transaction_Payments_ebayUser = x_Transaction.executeXPath("/Transaction/MonetaryDetails/Payments/Payment/Payer/text()"); v_Transaction_Payments_Amount = x_Transaction.executeXPath("/Transaction/MonetaryDetails/Payments/Payment/PaymentAmount/text()"); // // multi-leg (International Deliveries) v_Transaction_Shipping_Address_IsMultiLeg = x_Transaction.executeXPath("/Transaction/IsMultiLegShipping/text()"); if(v_Transaction_Shipping_Address_IsMultiLeg == "true") { x_Transaction_ShipTo_Address = x_Transaction.executeXPath("/Transaction/MultiLegShippingDetails/SellerShipmentToLogisticsProvider/ShipToAddress"); v_Transaction_Shipping_Name = x_Transaction_ShipTo_Address.executeXPath("/ShipToAddress/Name/text()"); v_Transaction_ShipTo_Address_Street1 = x_Transaction_ShipTo_Address.executeXPath("/ShipToAddress/Street1/text()"); v_Transaction_ShipTo_Address_Street2 = x_Transaction_ShipTo_Address.executeXPath("/ShipToAddress/Street2/text()"); v_Transaction_ShipTo_Address_Street2 = if(v_Transaction_ShipTo_Address_Street2.contains("ebay"),v_Transaction_ShipTo_Address_Street2.getPrefix("ebay").trim(),v_Transaction_ShipTo_Address_Street2); v_Transaction_ShipTo_Address_City = x_Transaction_ShipTo_Address.executeXPath("/ShipToAddress/CityName/text()"); v_Transaction_ShipTo_Address_State = x_Transaction_ShipTo_Address.executeXPath("/ShipToAddress/StateOrProvince/text()"); v_Transaction_ShipTo_Address_Country = x_Transaction_ShipTo_Address.executeXPath("/ShipToAddress/CountryName/text()"); v_Transaction_ShipTo_Address_Zip = x_Transaction_ShipTo_Address.executeXPath("/ShipToAddress/PostalCode/text()"); // // domestic shipping free but international shipping has service cost and import charge (is it possible to add line in Shopify Order? Tax Lines?) v_Transaction_Shipping_ImportCharge = x_Transaction.executeXPath("/Transaction/ShippingServiceSelected/ImportCharge/text()"); if(isNumber(v_Transaction_Shipping_ServiceCost) && isNumber(v_Transaction_Shipping_ImportCharge)) { v_Transaction_Shipping_ServiceCost = v_Transaction_Shipping_ImportCharge.toDecimal() + v_Transaction_Shipping_ServiceCost.toDecimal(); } // // client would like middleman reference in the address v_Transaction_ShipTo_Address_GSPRef = x_Transaction_ShipTo_Address.executeXPath("/ShipToAddress/ReferenceID/text()"); if(v_Transaction_ShipTo_Address_GSPRef != "") { v_Transaction_ShipTo_Address_Street2 = "Ref# " + v_Transaction_ShipTo_Address_GSPRef; } } else { v_Transaction_ShipTo_Address_Street1 = v_Transaction_Shipping_Address_Street1; v_Transaction_Shipping_Address_Street2 = if(v_Transaction_Shipping_Address_Street2.containsIgnoreCase(" eCP:"),v_Transaction_Shipping_Address_Street2.getPrefixIgnoreCase(" eCP:"),v_Transaction_Shipping_Address_Street2); v_Transaction_Shipping_Address_Street2 = if(v_Transaction_Shipping_Address_Street2.containsIgnoreCase("ebay"),v_Transaction_Shipping_Address_Street2.getPrefixIgnoreCase("ebay"),v_Transaction_Shipping_Address_Street2); v_Transaction_ShipTo_Address_Street2 = v_Transaction_Shipping_Address_Street2; v_Transaction_ShipTo_Address_City = v_Transaction_Shipping_Address_City; v_Transaction_ShipTo_Address_State = v_Transaction_Shipping_Address_State; v_Transaction_ShipTo_Address_Country = v_Transaction_Shipping_Address_Country; v_Transaction_ShipTo_Address_Zip = v_Transaction_Shipping_Address_Zip; } // // transforms v_Transaction_Buyer_Email = ifnull(v_Transaction_Buyer_Email,"").toLowerCase(); v_Transaction_Buyer_FName = ifnull(v_Transaction_Buyer_FName,"").proper(); v_Transaction_Buyer_SName = ifnull(v_Transaction_Buyer_SName,"").proper(); v_CreatorFinancialStatus = if(v_Transaction_PaymentStatus.containsIgnoreCase("Succeeded"),"paid",v_Transaction_PaymentStatus.toLowerCase()); v_Transaction_DateCreated = if(!isnull(v_Transaction_DateCreated),v_Transaction_DateCreated.getPrefix(".").replaceFirst("T"," ",true).toTime(),zoho.currenttime); v_Transaction_DateModified = if(!isnull(v_Transaction_DateModified),v_Transaction_DateModified.getPrefix(".").replaceFirst("T"," ",true).toTime(),zoho.currenttime); v_Transaction_DatePaid = if(!isnull(v_Transaction_DatePaid),v_Transaction_DatePaid.getPrefix(".").replaceFirst("T"," ",true).toTime(),zoho.currenttime); v_CreatorFinancialStatus = if(v_Transaction_PaymentStatus.containsIgnoreCase("Succeeded"),"paid",v_Transaction_PaymentStatus.toLowerCase()); v_Transaction_Shipping_ExpectedDelivery = if(!isnull(v_Transaction_Shipping_ExpectedDeliveryMin),v_Transaction_Shipping_ExpectedDeliveryMin.getPrefix("T").toDate(),zoho.currentdate.addBusinessday(1)); v_Transaction_Shipping_ExpectedDelivery = v_Transaction_Shipping_ExpectedDelivery.toString("E, d MMM yyyy");
- x_ResponseBody = input.Payload.getJSON("body");
- v_MainNodeName = "GetItemTransactionsResponse";
- x_MainNode = x_ResponseBody.subString(x_ResponseBody.indexOf("<" + v_MainNodeName),x_ResponseBody.lastIndexOf(v_MainNodeName) + v_MainNodeName.length() + 1);
- x_Item = x_MainNode.subString(x_MainNode.indexOf("<Item>"),x_MainNode.indexOf("</Item>") + 7);
- x_Transaction = x_MainNode.subString(x_MainNode.indexOf("<Transaction>"),x_MainNode.indexOf("</Transaction>") + 14);
- //
- // item details
- v_Item_ID = x_Item.executeXPath("/Item/ItemID/text()").replaceAll("[^0-9]","");
- v_Item_ID = if(!isnull(v_Item_ID),v_Item_ID.toLong(),null);
- v_Item_CategoryID = x_Item.executeXPath("/Item/PrimaryCategory/CategoryID/text()").replaceAll("[^0-9]","");
- v_Item_Listing_Start = x_Item.executeXPath("/Item/ListingDetails/StartTime/text()");
- v_Item_Listing_End = x_Item.executeXPath("/Item/ListingDetails/EndTime/text()");
- v_Item_Selling_Price = x_Item.executeXPath("/Item/SellingStatus/CurrentPrice/text()");
- v_Item_Selling_Currency = x_Item.executeXPath("/Item/SellingStatus/CurrentPrice/@currencyID").executeXPath("/currencyID/text()");
- v_Item_Selling_Currency = ifnull(v_Item_Selling_Currency,"GBP");
- v_Item_Selling_Quantity = x_Item.executeXPath("/Item/SellingStatus/QuantitySold/text()");
- v_Item_Title = x_Item.executeXPath("/Item/Title/text()");
- v_Item_SKU = x_Item.executeXPath("/Item/SKU/text()");
- //
- // transaction details
- v_Transaction_ID = x_Transaction.executeXPath("/Transaction/TransactionID/text()").replaceAll("[^0-9]","");
- v_Transaction_OrderID = x_Transaction.executeXPath("/Transaction/ExtendedOrderID/text()").replaceAll("[^0-9]","");
- v_Transaction_OrderRef = x_Transaction.executeXPath("/Transaction/ExtendedOrderID/text()");
- v_Transaction_OrderName = x_Transaction.executeXPath("/Transaction/Buyer/UserID/text()") + " " + zoho.currenttime.toString("dd-MMM-yyyy HH:mm");
- v_Transaction_LineItem_ID = x_Transaction.executeXPath("/Transaction/OrderLineItemID/text()");
- v_Transaction_Amount = x_Transaction.executeXPath("/Transaction/TransactionPrice/text()");
- v_Transaction_Paid = x_Transaction.executeXPath("/Transaction/AmountPaid/text()");
- v_Transaction_Currency = x_Transaction.executeXPath("/Transaction/AmountPaid/@currencyID").executeXPath("/currencyID/text()");
- v_Transaction_Quantity = x_Transaction.executeXPath("/Transaction/QuantityPurchased/text()");
- v_Transaction_Status = x_Transaction.executeXPath("/Transaction/Status/CompleteStatus/text()");
- v_Transaction_Method = x_Transaction.executeXPath("/Transaction/Status/PaymentInstrument/text()");
- v_Transaction_Adjustment = x_Transaction.executeXPath("/Transaction/ConvertedAdjustmentAmount/text()");
- v_Transaction_DateCreated = x_Transaction.executeXPath("/Transaction/CreatedDate/text()");
- v_Transaction_DateCreated = if(!isnull(v_Transaction_DateCreated),v_Transaction_DateCreated.getPrefix(".").replaceFirst("T"," ",true).toTime(),zoho.currenttime);
- v_Transaction_DateModified = x_Transaction.executeXPath("/Transaction/Status/LastTimeModified/text()");
- v_Transaction_DateModified = if(!isnull(v_Transaction_DateModified),v_Transaction_DateModified.getPrefix(".").replaceFirst("T"," ",true).toTime(),zoho.currenttime);
- v_Transaction_DatePaid = x_Transaction.executeXPath("/Transaction/PaidTime/text()");
- v_Transaction_DatePaid = if(!isnull(v_Transaction_DatePaid),v_Transaction_DatePaid.getPrefix(".").replaceFirst("T"," ",true).toTime(),zoho.currenttime);
- //
- // buyer details
- v_Transaction_UserID = x_Transaction.executeXPath("/Transaction/Buyer/UserID/text()");
- v_Transaction_FeedbackScore = x_Transaction.executeXPath("/Transaction/Buyer/FeedbackScore/text()");
- v_Transaction_UserID = x_Transaction.executeXPath("/Transaction/Buyer/UserID/text()");
- v_Transaction_Buyer_Email = x_Transaction.executeXPath("/Transaction/Buyer/Email/text()");
- v_Transaction_Buyer_FName = x_Transaction.executeXPath("/Transaction/Buyer/UserFirstName/text()");
- v_Transaction_Buyer_SName = x_Transaction.executeXPath("/Transaction/Buyer/UserLastName/text()");
- v_Transaction_Buyer_StaticEmail = x_Transaction.executeXPath("/Transaction/Buyer/StaticAlias/text()");
- v_Transaction_Buyer_MemberSince = x_Transaction.executeXPath("/Transaction/Buyer/RegistrationDate/text()");
- v_Transaction_Buyer_MemberSince = if(!isnull(v_Transaction_Buyer_MemberSince),v_Transaction_Buyer_MemberSince.getPrefix(".").replaceFirst("T"," ",true).toTime(),zoho.currenttime);
- //
- // shipping details
- x_Transaction_Shipping_Address = x_Transaction.executeXPath("/Transaction/Buyer/BuyerInfo/ShippingAddress");
- v_Transaction_Shipping_Name = x_Transaction_Shipping_Address.executeXPath("/ShippingAddress/Name/text()");
- v_Transaction_Shipping_Phone = x_Transaction_Shipping_Address.executeXPath("/ShippingAddress/Phone/text()");
- v_Transaction_Shipping_Address_Street1 = x_Transaction_Shipping_Address.executeXPath("/ShippingAddress/Street1/text()");
- v_Transaction_Shipping_Address_Street2 = x_Transaction_Shipping_Address.executeXPath("/ShippingAddress/Street2/text()");
- v_Transaction_Shipping_Address_City = x_Transaction_Shipping_Address.executeXPath("/ShippingAddress/CityName/text()");
- v_Transaction_Shipping_Address_State = x_Transaction_Shipping_Address.executeXPath("/ShippingAddress/StateOrProvince/text()");
- v_Transaction_Shipping_Address_Country = x_Transaction_Shipping_Address.executeXPath("/ShippingAddress/CountryName/text()");
- v_Transaction_Shipping_Address_Zip = x_Transaction_Shipping_Address.executeXPath("/ShippingAddress/PostalCode/text()");
- v_Transaction_Shipping_Address_CountryCode = x_Transaction_Shipping_Address.executeXPath("/ShippingAddress/Country/text()");
- v_Transaction_Shipping_Tax = x_Transaction.executeXPath("/Transaction/ShippingDetails/SalesTax/SalesTaxAmount/text()");
- v_Transaction_Shipping_Service = x_Transaction.executeXPath("/Transaction/ShippingServiceSelected/ShippingService/text()");
- v_Transaction_Shipping_ServiceCost = x_Transaction.executeXPath("/Transaction/ShippingServiceSelected/ShippingServiceCost/text()");
- v_Transaction_Shipping_ServiceSelected = x_Transaction.executeXPath("/Transaction/ShippingServiceSelected/ShippingService/text()");
- v_Transaction_Shipping_ExpectedDeliveryMin = x_Transaction.executeXPath("/Transaction/ShippingServiceSelected/ShippingPackageInfo/EstimatedDeliveryTimeMin/text()");
- v_Transaction_Shipping_ExpectedDeliveryMax = x_Transaction.executeXPath("/Transaction/ShippingServiceSelected/ShippingPackageInfo/EstimatedDeliveryTimeMax/text()");
- //
- // payment details
- v_Transaction_EbayPaymentStatus = x_Transaction.executeXPath("/Transaction/Status/eBayPaymentStatus/text()");
- v_Transaction_PaymentStatus = x_Transaction.executeXPath("/Transaction/MonetaryDetails/Payments/Payment/PaymentStatus/text()");
- v_Transaction_Status_Payment = x_Transaction.executeXPath("/Transaction/Status/eBayPaymentStatus/text()");
- v_Transaction_Status_Checkout = x_Transaction.executeXPath("/Transaction/Status/CheckoutStatus/text()");
- v_Transaction_Payments_Status = x_Transaction.executeXPath("/Transaction/MonetaryDetails/Payments/Payment/PaymentStatus/text()");
- v_Transaction_Payments_ebayUser = x_Transaction.executeXPath("/Transaction/MonetaryDetails/Payments/Payment/Payer/text()");
- v_Transaction_Payments_Amount = x_Transaction.executeXPath("/Transaction/MonetaryDetails/Payments/Payment/PaymentAmount/text()");
- //
- // multi-leg (International Deliveries)
- v_Transaction_Shipping_Address_IsMultiLeg = x_Transaction.executeXPath("/Transaction/IsMultiLegShipping/text()");
- if(v_Transaction_Shipping_Address_IsMultiLeg == "true")
- {
- x_Transaction_ShipTo_Address = x_Transaction.executeXPath("/Transaction/MultiLegShippingDetails/SellerShipmentToLogisticsProvider/ShipToAddress");
- v_Transaction_Shipping_Name = x_Transaction_ShipTo_Address.executeXPath("/ShipToAddress/Name/text()");
- v_Transaction_ShipTo_Address_Street1 = x_Transaction_ShipTo_Address.executeXPath("/ShipToAddress/Street1/text()");
- v_Transaction_ShipTo_Address_Street2 = x_Transaction_ShipTo_Address.executeXPath("/ShipToAddress/Street2/text()");
- v_Transaction_ShipTo_Address_Street2 = if(v_Transaction_ShipTo_Address_Street2.contains("ebay"),v_Transaction_ShipTo_Address_Street2.getPrefix("ebay").trim(),v_Transaction_ShipTo_Address_Street2);
- v_Transaction_ShipTo_Address_City = x_Transaction_ShipTo_Address.executeXPath("/ShipToAddress/CityName/text()");
- v_Transaction_ShipTo_Address_State = x_Transaction_ShipTo_Address.executeXPath("/ShipToAddress/StateOrProvince/text()");
- v_Transaction_ShipTo_Address_Country = x_Transaction_ShipTo_Address.executeXPath("/ShipToAddress/CountryName/text()");
- v_Transaction_ShipTo_Address_Zip = x_Transaction_ShipTo_Address.executeXPath("/ShipToAddress/PostalCode/text()");
- //
- // domestic shipping free but international shipping has service cost and import charge (is it possible to add line in Shopify Order? Tax Lines?)
- v_Transaction_Shipping_ImportCharge = x_Transaction.executeXPath("/Transaction/ShippingServiceSelected/ImportCharge/text()");
- if(isNumber(v_Transaction_Shipping_ServiceCost) && isNumber(v_Transaction_Shipping_ImportCharge))
- {
- v_Transaction_Shipping_ServiceCost = v_Transaction_Shipping_ImportCharge.toDecimal() + v_Transaction_Shipping_ServiceCost.toDecimal();
- }
- //
- // client would like middleman reference in the address
- v_Transaction_ShipTo_Address_GSPRef = x_Transaction_ShipTo_Address.executeXPath("/ShipToAddress/ReferenceID/text()");
- if(v_Transaction_ShipTo_Address_GSPRef != "")
- {
- v_Transaction_ShipTo_Address_Street2 = "Ref# " + v_Transaction_ShipTo_Address_GSPRef;
- }
- }
- else
- {
- v_Transaction_ShipTo_Address_Street1 = v_Transaction_Shipping_Address_Street1;
- v_Transaction_Shipping_Address_Street2 = if(v_Transaction_Shipping_Address_Street2.containsIgnoreCase(" eCP:"),v_Transaction_Shipping_Address_Street2.getPrefixIgnoreCase(" eCP:"),v_Transaction_Shipping_Address_Street2);
- v_Transaction_Shipping_Address_Street2 = if(v_Transaction_Shipping_Address_Street2.containsIgnoreCase("ebay"),v_Transaction_Shipping_Address_Street2.getPrefixIgnoreCase("ebay"),v_Transaction_Shipping_Address_Street2);
- v_Transaction_ShipTo_Address_Street2 = v_Transaction_Shipping_Address_Street2;
- v_Transaction_ShipTo_Address_City = v_Transaction_Shipping_Address_City;
- v_Transaction_ShipTo_Address_State = v_Transaction_Shipping_Address_State;
- v_Transaction_ShipTo_Address_Country = v_Transaction_Shipping_Address_Country;
- v_Transaction_ShipTo_Address_Zip = v_Transaction_Shipping_Address_Zip;
- }
- //
- // transforms
- v_Transaction_Buyer_Email = ifnull(v_Transaction_Buyer_Email,"").toLowerCase();
- v_Transaction_Buyer_FName = ifnull(v_Transaction_Buyer_FName,"").proper();
- v_Transaction_Buyer_SName = ifnull(v_Transaction_Buyer_SName,"").proper();
- v_CreatorFinancialStatus = if(v_Transaction_PaymentStatus.containsIgnoreCase("Succeeded"),"paid",v_Transaction_PaymentStatus.toLowerCase());
- v_Transaction_DateCreated = if(!isnull(v_Transaction_DateCreated),v_Transaction_DateCreated.getPrefix(".").replaceFirst("T"," ",true).toTime(),zoho.currenttime);
- v_Transaction_DateModified = if(!isnull(v_Transaction_DateModified),v_Transaction_DateModified.getPrefix(".").replaceFirst("T"," ",true).toTime(),zoho.currenttime);
- v_Transaction_DatePaid = if(!isnull(v_Transaction_DatePaid),v_Transaction_DatePaid.getPrefix(".").replaceFirst("T"," ",true).toTime(),zoho.currenttime);
- v_CreatorFinancialStatus = if(v_Transaction_PaymentStatus.containsIgnoreCase("Succeeded"),"paid",v_Transaction_PaymentStatus.toLowerCase());
- v_Transaction_Shipping_ExpectedDelivery = if(!isnull(v_Transaction_Shipping_ExpectedDeliveryMin),v_Transaction_Shipping_ExpectedDeliveryMin.getPrefix("T").toDate(),zoho.currentdate.addBusinessday(1));
- v_Transaction_Shipping_ExpectedDelivery = v_Transaction_Shipping_ExpectedDelivery.toString("E, d MMM yyyy");
Create Shopify Order (JSON)
And here's my code so far for creating an order in Shopify. You will need to amend the connection details and also the value of your Shopify Product ID and Shopify Variant ID. This works so far but it's a little plain and I'm still addressing an issue that the inventory level isn't being automatically updated when an order is processed. I'm told this happens on fulfillment but we need it to remove it from Shopify as soon as the item is sold on eBay:
// // ************************************* // shopify connection // m_Header = Map(); m_Header.put("Content-Type","application/json"); // // app specific r_ShopifyAPI = API_Integration[Connection_Name == "Shopify API"]; v_ClientID = r_ShopifyAPI.Client_ID; v_ClientSecret = r_ShopifyAPI.Client_Secret; v_ShopID = r_ShopifyAPI.Shop_ID; v_ShopifyApiVersion = r_ShopifyAPI.API_Version; v_ShopifyURL = "https://" + v_ClientID + ":" + v_ClientSecret + "@" + v_ShopID; v_ShopifyLocationID = r_ShopifyAPI.Location_ID; v_ShopifyLocationCountryCode = r_ShopifyAPI.Location_Code_Origin; // // set these to the Shopify Product ID and Shopify Variant ID v_ShopifyProductID = 0; v_ShopifyVariantID = 0; // // I have a Creator table/form called Portal Listing storing both the SKU, ebay Item #, Shopify Product ID, Shopify Variant ID, and Shopify Inventory ID // double-check these are stored as 64-bit signed integers having a possible length of 19 digits. // determine Shopify product ID by SKU r_Listing = Portal_Listing[Product_SKU.equalsIgnoreCase(v_Item_SKU)]; if(r_Listing.count() > 0) { v_ShopifyProductID = ifnull(r_Listing.Shopify_Product_ID,0).toLong(); v_ShopifyVariantID = ifnull(r_Listing.Shopify_Product_Variant_ID,0).toLong(); } // // initialize Shopify Order JSON m_CreateShopifyOrder = Map(); m_CreateShopifyOrder.put("fulfillable_quantity",v_Transaction_Quantity.toLong()); m_CreateShopifyOrder.put("financial_status","paid"); m_CreateShopifyOrder.put("currency","GBP"); m_CreateShopifyOrder.put("fulfillment_status",null); m_CreateShopifyOrder.put("send_receipt",false); m_CreateShopifyOrder.put("send_fulfillment_receipt",false); m_CreateShopifyOrder.put("inventory_behaviour","decrement_ignoring_policy"); m_CreateShopifyOrder.put("tags","eBay, Zoho"); m_CreateShopifyOrder.put("gateway","manual"); // // customer m_Customer = Map(); m_Customer.put("email",v_Transaction_Buyer_Email); m_Customer.put("first_name",v_Transaction_Buyer_FName); m_Customer.put("last_name",v_Transaction_Buyer_SName); m_Customer.put("note","ebay User: " + v_Transaction_UserID + " (" + v_Transaction_FeedbackScore + ") Since " + v_Transaction_Buyer_MemberSince.toString("MMM-yyyy")); m_CreateShopifyOrder.put("customer",m_Customer); // // billing address v_BillingName = trim(v_Transaction_Buyer_FName + " " + v_Transaction_Buyer_SName); m_BillingAddress = Map(); m_BillingAddress.put("first_name",v_Transaction_Buyer_FName); m_BillingAddress.put("last_name",v_Transaction_Buyer_SName); m_BillingAddress.put("address1",v_Transaction_Shipping_Address_Street1); m_BillingAddress.put("address2",v_Transaction_Shipping_Address_Street2); m_BillingAddress.put("city",v_Transaction_Shipping_Address_City); m_BillingAddress.put("zip",v_Transaction_Shipping_Address_Zip); m_BillingAddress.put("province",v_Transaction_Shipping_Address_State); m_BillingAddress.put("country",v_Transaction_Shipping_Address_Country); m_CreateShopifyOrder.put("billing_address",m_BillingAddress); // // shipping address v_ShippingName = trim(v_Transaction_Buyer_FName + " " + v_Transaction_Buyer_SName); m_ShippingAddress = Map(); m_ShippingAddress.put("name",v_Transaction_Shipping_Name); m_ShippingAddress.put("phone",v_Transaction_Shipping_Phone); m_ShippingAddress.put("address1",v_Transaction_ShipTo_Address_Street1); m_ShippingAddress.put("address2",v_Transaction_ShipTo_Address_Street2); m_ShippingAddress.put("city",v_Transaction_ShipTo_Address_City); m_ShippingAddress.put("zip",v_Transaction_ShipTo_Address_Zip); m_ShippingAddress.put("province",v_Transaction_ShipTo_Address_State); m_ShippingAddress.put("country",v_Transaction_ShipTo_Address_Country); m_CreateShopifyOrder.put("shipping_address",m_ShippingAddress); // // shipping line l_ShippingLines = List(); m_ShippingLine = Map(); m_ShippingLine.put("price",ifnull(v_Transaction_Shipping_ServiceCost,0)); m_ShippingLine.put("source","eBay"); m_ShippingLine.put("code",v_Transaction_Shipping_ServiceSelected); m_ShippingLine.put("title",v_Transaction_Shipping_ServiceSelected); l_ShippingLines.add(m_ShippingLine); m_CreateShopifyOrder.put("shipping_lines",l_ShippingLines); // // line items l_LineItems = List(); m_LineItem = Map(); m_LineItem.put("name",v_Item_Title); m_LineItem.put("title",v_Item_Title); //m_LineItem.put("variant_title",v_Item_Title); m_LineItem.put("price",v_Item_Selling_Price.toDecimal()); m_LineItem.put("sku",v_Item_SKU); m_LineItem.put("product_id",v_ShopifyProductID); m_LineItem.put("variant_id",v_ShopifyVariantID); m_LineItem.put("quantity",v_Transaction_Quantity.toLong()); l_TaxLines = List(); m_TaxLine = Map(); m_TaxLine.put("rate",0); m_TaxLine.put("price",0); m_TaxLine.put("title","No VAT"); l_TaxLines.add(m_TaxLine); m_LineItem.put("tax_lines",l_TaxLines); l_LineItems.add(m_LineItem); m_CreateShopifyOrder.put("line_items",l_LineItems); // // transactions l_Transactions = List(); m_Transaction = Map(); m_Transaction.put("kind","sale"); m_Transaction.put("status","success"); m_Transaction.put("gateway","manual"); m_Transaction.put("amount",v_Transaction_Paid); m_Transaction.put("currency",v_Transaction_Currency); l_Transactions.add(m_Transaction); m_CreateShopifyOrder.put("transactions",l_Transactions); // // note attributes l_NoteAttributes = List(); m_NoteAttribute = Map(); m_NoteAttribute.put("name","Source"); m_NoteAttribute.put("value","Zoho Creator"); l_NoteAttributes.add(m_NoteAttribute); m_NoteAttribute = Map(); m_NoteAttribute.put("name","eBay Order ID"); m_NoteAttribute.put("value",v_Transaction_OrderRef); l_NoteAttributes.add(m_NoteAttribute); m_NoteAttribute = Map(); m_NoteAttribute.put("name","eBay Item #"); m_NoteAttribute.put("value",v_Item_ID); l_NoteAttributes.add(m_NoteAttribute); m_NoteAttribute = Map(); m_NoteAttribute.put("name","eBay Deliver By Date"); m_NoteAttribute.put("value",v_Transaction_Shipping_ExpectedDelivery); l_NoteAttributes.add(m_NoteAttribute); m_CreateShopifyOrder.put("note_attributes",l_NoteAttributes); // // package for request to Shopify m_ShopifyParams = Map(); // // check if already exists v_ShopifyOrderID = 0; l_eBayOrders = Portal_Listing[eBay_Order_ID == v_Transaction_OrderRef]; if(l_eBayOrders.count() > 0) { for each r_eBayOrder in l_eBayOrders { if(!isnull(r_eBayOrder.Shopify_Order_ID)) { v_ShopifyOrderID = r_eBayOrder.Shopify_Order_ID.toLong(); } } } // if not 0 then update the Shopify Order ID b_ShopifyOrderSuccessful = true; v_ShopifyMode = "created"; if(v_ShopifyOrderID != 0) { m_CreateShopifyOrder.put("id",v_ShopifyOrderID); m_ShopifyParams.put("order",m_CreateShopifyOrder); v_Endpoint = v_ShopifyURL + "/admin/api/" + v_ShopifyApiVersion.toString() + "/orders/" + v_ShopifyOrderID + ".json"; r_CreateOrder = invokeurl [ url :v_Endpoint type :PUT parameters:m_ShopifyParams.toString() headers:m_Header ]; if(r_CreateOrder.get("order") != null) { if(!isnull(r_CreateOrder.get("order").get("id"))) { v_ShopifyOrderID = r_CreateOrder.get("order").get("id"); b_ShopifyOrderSuccessful = true; v_ShopifyMode = "updated"; } } } // else then create the Shopify Order else { m_ShopifyParams.put("order",m_CreateShopifyOrder); v_Endpoint = v_ShopifyURL + "/admin/api/" + v_ShopifyApiVersion.toString() + "/orders.json"; r_CreateOrder = invokeurl [ url :v_Endpoint type :POST parameters:m_ShopifyParams.toString() headers:m_Header ]; if(!isnull(r_CreateOrder.get("order")) != null) { if(!isnull(r_CreateOrder.get("order").get("id"))) { v_ShopifyOrderID = r_CreateOrder.get("order").get("id"); b_ShopifyOrderSuccessful = true; } } } info r_CreateOrder;
- //
- // *************************************
- // shopify connection
- //
- m_Header = Map();
- m_Header.put("Content-Type","application/json");
- //
- // app specific
- r_ShopifyAPI = API_Integration[Connection_Name == "Shopify API"];
- v_ClientID = r_ShopifyAPI.Client_ID;
- v_ClientSecret = r_ShopifyAPI.Client_Secret;
- v_ShopID = r_ShopifyAPI.Shop_ID;
- v_ShopifyApiVersion = r_ShopifyAPI.API_Version;
- v_ShopifyURL = "https://" + v_ClientID + ":" + v_ClientSecret + "@" + v_ShopID;
- v_ShopifyLocationID = r_ShopifyAPI.Location_ID;
- v_ShopifyLocationCountryCode = r_ShopifyAPI.Location_Code_Origin;
- //
- // set these to the Shopify Product ID and Shopify Variant ID
- v_ShopifyProductID = 0;
- v_ShopifyVariantID = 0;
- //
- // I have a Creator table/form called Portal Listing storing both the SKU, ebay Item #, Shopify Product ID, Shopify Variant ID, and Shopify Inventory ID
- // double-check these are stored as 64-bit signed integers having a possible length of 19 digits.
- // determine Shopify product ID by SKU
- r_Listing = Portal_Listing[Product_SKU.equalsIgnoreCase(v_Item_SKU)];
- if(r_Listing.count() > 0)
- {
- v_ShopifyProductID = ifnull(r_Listing.Shopify_Product_ID,0).toLong();
- v_ShopifyVariantID = ifnull(r_Listing.Shopify_Product_Variant_ID,0).toLong();
- }
- //
- // initialize Shopify Order JSON
- m_CreateShopifyOrder = Map();
- m_CreateShopifyOrder.put("fulfillable_quantity",v_Transaction_Quantity.toLong());
- m_CreateShopifyOrder.put("financial_status","paid");
- m_CreateShopifyOrder.put("currency","GBP");
- m_CreateShopifyOrder.put("fulfillment_status",null);
- m_CreateShopifyOrder.put("send_receipt",false);
- m_CreateShopifyOrder.put("send_fulfillment_receipt",false);
- m_CreateShopifyOrder.put("inventory_behaviour","decrement_ignoring_policy");
- m_CreateShopifyOrder.put("tags","eBay, Zoho");
- m_CreateShopifyOrder.put("gateway","manual");
- //
- // customer
- m_Customer = Map();
- m_Customer.put("email",v_Transaction_Buyer_Email);
- m_Customer.put("first_name",v_Transaction_Buyer_FName);
- m_Customer.put("last_name",v_Transaction_Buyer_SName);
- m_Customer.put("note","ebay User: " + v_Transaction_UserID + " (" + v_Transaction_FeedbackScore + ") Since " + v_Transaction_Buyer_MemberSince.toString("MMM-yyyy"));
- m_CreateShopifyOrder.put("customer",m_Customer);
- //
- // billing address
- v_BillingName = trim(v_Transaction_Buyer_FName + " " + v_Transaction_Buyer_SName);
- m_BillingAddress = Map();
- m_BillingAddress.put("first_name",v_Transaction_Buyer_FName);
- m_BillingAddress.put("last_name",v_Transaction_Buyer_SName);
- m_BillingAddress.put("address1",v_Transaction_Shipping_Address_Street1);
- m_BillingAddress.put("address2",v_Transaction_Shipping_Address_Street2);
- m_BillingAddress.put("city",v_Transaction_Shipping_Address_City);
- m_BillingAddress.put("zip",v_Transaction_Shipping_Address_Zip);
- m_BillingAddress.put("province",v_Transaction_Shipping_Address_State);
- m_BillingAddress.put("country",v_Transaction_Shipping_Address_Country);
- m_CreateShopifyOrder.put("billing_address",m_BillingAddress);
- //
- // shipping address
- v_ShippingName = trim(v_Transaction_Buyer_FName + " " + v_Transaction_Buyer_SName);
- m_ShippingAddress = Map();
- m_ShippingAddress.put("name",v_Transaction_Shipping_Name);
- m_ShippingAddress.put("phone",v_Transaction_Shipping_Phone);
- m_ShippingAddress.put("address1",v_Transaction_ShipTo_Address_Street1);
- m_ShippingAddress.put("address2",v_Transaction_ShipTo_Address_Street2);
- m_ShippingAddress.put("city",v_Transaction_ShipTo_Address_City);
- m_ShippingAddress.put("zip",v_Transaction_ShipTo_Address_Zip);
- m_ShippingAddress.put("province",v_Transaction_ShipTo_Address_State);
- m_ShippingAddress.put("country",v_Transaction_ShipTo_Address_Country);
- m_CreateShopifyOrder.put("shipping_address",m_ShippingAddress);
- //
- // shipping line
- l_ShippingLines = List();
- m_ShippingLine = Map();
- m_ShippingLine.put("price",ifnull(v_Transaction_Shipping_ServiceCost,0));
- m_ShippingLine.put("source","eBay");
- m_ShippingLine.put("code",v_Transaction_Shipping_ServiceSelected);
- m_ShippingLine.put("title",v_Transaction_Shipping_ServiceSelected);
- l_ShippingLines.add(m_ShippingLine);
- m_CreateShopifyOrder.put("shipping_lines",l_ShippingLines);
- //
- // line items
- l_LineItems = List();
- m_LineItem = Map();
- m_LineItem.put("name",v_Item_Title);
- m_LineItem.put("title",v_Item_Title);
- //m_LineItem.put("variant_title",v_Item_Title);
- m_LineItem.put("price",v_Item_Selling_Price.toDecimal());
- m_LineItem.put("sku",v_Item_SKU);
- m_LineItem.put("product_id",v_ShopifyProductID);
- m_LineItem.put("variant_id",v_ShopifyVariantID);
- m_LineItem.put("quantity",v_Transaction_Quantity.toLong());
- l_TaxLines = List();
- m_TaxLine = Map();
- m_TaxLine.put("rate",0);
- m_TaxLine.put("price",0);
- m_TaxLine.put("title","No VAT");
- l_TaxLines.add(m_TaxLine);
- m_LineItem.put("tax_lines",l_TaxLines);
- l_LineItems.add(m_LineItem);
- m_CreateShopifyOrder.put("line_items",l_LineItems);
- //
- // transactions
- l_Transactions = List();
- m_Transaction = Map();
- m_Transaction.put("kind","sale");
- m_Transaction.put("status","success");
- m_Transaction.put("gateway","manual");
- m_Transaction.put("amount",v_Transaction_Paid);
- m_Transaction.put("currency",v_Transaction_Currency);
- l_Transactions.add(m_Transaction);
- m_CreateShopifyOrder.put("transactions",l_Transactions);
- //
- // note attributes
- l_NoteAttributes = List();
- m_NoteAttribute = Map();
- m_NoteAttribute.put("name","Source");
- m_NoteAttribute.put("value","Zoho Creator");
- l_NoteAttributes.add(m_NoteAttribute);
- m_NoteAttribute = Map();
- m_NoteAttribute.put("name","eBay Order ID");
- m_NoteAttribute.put("value",v_Transaction_OrderRef);
- l_NoteAttributes.add(m_NoteAttribute);
- m_NoteAttribute = Map();
- m_NoteAttribute.put("name","eBay Item #");
- m_NoteAttribute.put("value",v_Item_ID);
- l_NoteAttributes.add(m_NoteAttribute);
- m_NoteAttribute = Map();
- m_NoteAttribute.put("name","eBay Deliver By Date");
- m_NoteAttribute.put("value",v_Transaction_Shipping_ExpectedDelivery);
- l_NoteAttributes.add(m_NoteAttribute);
- m_CreateShopifyOrder.put("note_attributes",l_NoteAttributes);
- //
- // package for request to Shopify
- m_ShopifyParams = Map();
- //
- // check if already exists
- v_ShopifyOrderID = 0;
- l_eBayOrders = Portal_Listing[eBay_Order_ID == v_Transaction_OrderRef];
- if(l_eBayOrders.count() > 0)
- {
- for each r_eBayOrder in l_eBayOrders
- {
- if(!isnull(r_eBayOrder.Shopify_Order_ID))
- {
- v_ShopifyOrderID = r_eBayOrder.Shopify_Order_ID.toLong();
- }
- }
- }
- // if not 0 then update the Shopify Order ID
- b_ShopifyOrderSuccessful = true;
- v_ShopifyMode = "created";
- if(v_ShopifyOrderID != 0)
- {
- m_CreateShopifyOrder.put("id",v_ShopifyOrderID);
- m_ShopifyParams.put("order",m_CreateShopifyOrder);
- v_Endpoint = v_ShopifyURL + "/admin/api/" + v_ShopifyApiVersion.toString() + "/orders/" + v_ShopifyOrderID + ".json";
- r_CreateOrder = invokeUrl
- [
- url :v_Endpoint
- type :PUT
- parameters:m_ShopifyParams.toString()
- headers:m_Header
- ];
- if(r_CreateOrder.get("order") != null)
- {
- if(!isnull(r_CreateOrder.get("order").get("id")))
- {
- v_ShopifyOrderID = r_CreateOrder.get("order").get("id");
- b_ShopifyOrderSuccessful = true;
- v_ShopifyMode = "updated";
- }
- }
- }
- // else then create the Shopify Order
- else
- {
- m_ShopifyParams.put("order",m_CreateShopifyOrder);
- v_Endpoint = v_ShopifyURL + "/admin/api/" + v_ShopifyApiVersion.toString() + "/orders.json";
- r_CreateOrder = invokeUrl
- [
- url :v_Endpoint
- type :POST
- parameters:m_ShopifyParams.toString()
- headers:m_Header
- ];
- if(!isnull(r_CreateOrder.get("order")) != null)
- {
- if(!isnull(r_CreateOrder.get("order").get("id")))
- {
- v_ShopifyOrderID = r_CreateOrder.get("order").get("id");
- b_ShopifyOrderSuccessful = true;
- }
- }
- }
- info r_CreateOrder;
Additional Note(s):
- ShipTo: Note my variables of Ship To address as opposed to Shipping Address. If the customer was in the UK, the ShipTo address is the same as the eBay Shipping address. If it is an international order, then my client is using a middleman in the UK who then ships it to the overseas destination and so the ShipTo address would be the middleman's address.
- eBay GetItemTransactions vs eBay GetOrderTransactions I'm using GetItemTransactions as these are line item orders. As eBay supports baskets now, I will use and add GetOrderTransactions if there is any information I couldn't get from the line item.
GetItemTransaction
I also changed the code above our first snippet (parsing the eBay transaction) to run a function which gets the line item order from eBay:
string API.fn_eBayQuery_GetItemTransaction(int p_ItemID) { /* Function: fn_eBayQuery_GetItemTransaction() Input: int p_ItemID (ebay number of the item) Purpose: Fetches a line item transaction per item ID Date Created: 2022-01-22 (Joellipman.com - Joel Lipman) - Initial release More Info: - API Explorer Test Tool: https://developer.ebay.com/DevZone/build-test/test-tool/default.aspx?index=0&env=production&api=trading - GetItemTransactions Documentation: https://developer.ebay.com/devzone/xml/docs/Reference/eBay/GetItemTransactions.html */ v_Found = 0; v_Updated = 0; v_Page = 1; v_PerPage = 10; m_Output = Map(); r_ResponseXML = ""; r_Api = API_Integration[Connection_Name == "eBay API (Production)"]; if(r_Api.count() > 0) { v_AccessToken = thisapp.API.fn_eBayConnect_AccessToken(); v_TradingAPIVersion = r_Api.API_Version; v_Endpoint = "https://api.ebay.com/ws/api.dll"; // // build header m_Headers = Map(); m_Headers.put("X-EBAY-API-SITEID",3); m_Headers.put("X-EBAY-API-COMPATIBILITY-LEVEL",v_TradingAPIVersion); v_ApiCall = "GetItemTransactions"; m_Headers.put("X-EBAY-API-CALL-NAME",v_ApiCall); m_Headers.put("X-EBAY-API-IAF-TOKEN",v_AccessToken); // // build params m_Params = Map(); m_Params.put("WarningLevel","High"); m_Params.put("ErrorLanguage","en_GB"); m_Params.put("DetailLevel","ItemReturnCategories"); // // include fixed price items m_Pagination = Map(); m_Pagination.put("PageNumber",v_Page); m_Pagination.put("EntriesPerPage",v_PerPage); m_Params.put("Pagination",m_Pagination); //m_ActiveList.put("Sort","ItemID"); m_Params.put("ItemID",p_ItemID); // // convert to xml and replace root nodes x_Params = m_Params.toXML(); x_Params = x_Params.toString().replaceFirst("<root>","<?xml version=\"1.0\" encoding=\"utf-8\"?><" + v_ApiCall + "Request xmlns=\"urn:ebay:apis:eBLBaseComponents\">"); x_Params = x_Params.toString().replaceFirst("</root>","</" + v_ApiCall + "Request>"); // // send the request XML as a string r_ResponseXML = invokeurl [ url :v_Endpoint type :POST parameters:x_Params headers:m_Headers ]; // // output response info r_ResponseXML; } return r_ResponseXML; }
- string API.fn_eBayQuery_GetItemTransaction(int p_ItemID)
- {
- /*
- Function: fn_eBayQuery_GetItemTransaction()
- Input: int p_ItemID (ebay number of the item)
- Purpose: Fetches a line item transaction per item ID
- Date Created: 2022-01-22 (Joellipman.com - Joel Lipman)
- - Initial release
- More Info:
- - API Explorer Test Tool: https://developer.ebay.com/DevZone/build-test/test-tool/default.aspx?index=0&env=production&api=trading
- - GetItemTransactions Documentation: https://developer.ebay.com/devzone/xml/docs/Reference/eBay/GetItemTransactions.html
- */
- v_Found = 0;
- v_Updated = 0;
- v_Page = 1;
- v_PerPage = 10;
- m_Output = Map();
- r_ResponseXML = "";
- r_Api = API_Integration[Connection_Name == "eBay API (Production)"];
- if(r_Api.count() > 0)
- {
- v_AccessToken = thisapp.API.fn_eBayConnect_AccessToken();
- v_TradingAPIVersion = r_Api.API_Version;
- v_Endpoint = "https://api.ebay.com/ws/api.dll";
- //
- // build header
- m_Headers = Map();
- m_Headers.put("X-EBAY-API-SITEID",3);
- m_Headers.put("X-EBAY-API-COMPATIBILITY-LEVEL",v_TradingAPIVersion);
- v_ApiCall = "GetItemTransactions";
- m_Headers.put("X-EBAY-API-CALL-NAME",v_ApiCall);
- m_Headers.put("X-EBAY-API-IAF-TOKEN",v_AccessToken);
- //
- // build params
- m_Params = Map();
- m_Params.put("WarningLevel","High");
- m_Params.put("ErrorLanguage","en_GB");
- m_Params.put("DetailLevel","ItemReturnCategories");
- //
- // include fixed price items
- m_Pagination = Map();
- m_Pagination.put("PageNumber",v_Page);
- m_Pagination.put("EntriesPerPage",v_PerPage);
- m_Params.put("Pagination",m_Pagination);
- //m_ActiveList.put("Sort","ItemID");
- m_Params.put("ItemID",p_ItemID);
- //
- // convert to xml and replace root nodes
- x_Params = m_Params.toXML();
- x_Params = x_Params.toString().replaceFirst("<root>","<?xml version=\"1.0\" encoding=\"utf-8\"?><" + v_ApiCall + "Request xmlns=\"urn:ebay:apis:eBLBaseComponents\">");
- x_Params = x_Params.toString().replaceFirst("</root>","</" + v_ApiCall + "Request>");
- //
- // send the request XML as a string
- r_ResponseXML = invokeUrl
- [
- url :v_Endpoint
- type :POST
- parameters:x_Params
- headers:m_Headers
- ];
- //
- // output response
- info r_ResponseXML;
- }
- return r_ResponseXML;
- }
Usage:
// expects eBay Item number x_ResponseBody = thisapp.API.fn_eBayQuery_GetItemTransaction(p_ItemID);
- // expects eBay Item number
- x_ResponseBody = thisapp.API.fn_eBayQuery_GetItemTransaction(p_ItemID);
Source(s) / Issue(s):
- Bad Request: This could be a number of things. The obvious one that eluded me for ages however was that when sending the request, I had forgotten to put .toString() to send the JSON. I think the response is mostly due to invalid JSON being sent as a request.
- Product doesn't display photo and is not clickable in Shopify Order: Product ID and Variant ID aren't being correctly populated in the Shopify Order Line Item. The line item order gets created but there was no link to an existing Variant ID. Check that both Creator fields storing these allow 19 digits (64-bit signed integers). I had an inventory field in the process that was limited to 10 digits causing the wrong variant ID to be submitted in the order.
- Paid by Customer is 0.00: Check transactions is being submitted with kind as "sale" instead of "authorization". There will be an event on the timeline saying something like: "myApp manually marked this order as paid".
- Third-Party Courier ID: (reference ID for when a delivery by third-party is made to update the Shopify order). - to be tested.
- Inventory does NOT get updated: inventory_behaviour is defaulted to "bypass". Consider sending this as "decrement_ignoring_policy".
- Enhance Timeline Entry eg. "My App (with icon) manually marked this order as paid": - I think app has to be a registered app and not a private app
Source(s)
- Zoho Creator: Receive eBay Order Notifications via Webhook
- Zoho Creator: Receive JSON via a Shopify Webhook
- Zoho Creator: Push to eBay Listings
- Shopify Developers API - The Order object
- eBay Trading API Version 1235 - GetItemTransactions
- eBay Trading API Version 1235 - GetOrderTransactions