This is an article to document a function used in Zoho Creator to retrieve the Product IDs of all the active products in a client's eBay store.
Why?
The use-case was that I wanted to retrieve a list of all the listed active products in a fixed price item listing. The example below is a function which, if given the page number and the number of entries per page, returns these in JSON as a Zoho Map datatype.
How?
I'm not going to go into detail on how I create an access token to query the eBay Trading API as you can read this in my article: Joellipman: Zoho Creator: Push to eBay Listings. You will note that I use the access token function (one that regenerates an access token or reuses if not expired). Thereafter, I use the GetMyeBaySelling API Call with specific criteria to only return the active listings as well as specific fields so my function doesn't get overwhelmed with the amount of data in the response:
copyraw
	
If I give it the parameter values of page 1 and 5 entries per page, the first info will display to me the XML response:
map API.fn_eBayQuery_GetActiveProducts(int p_Page, int p_PerPage)
{
	/*
    Function: fn_eBayQuery_GetActiveProducts()
    Purpose: Fetches current listings / active products
    Date Created:   2021-10-13 (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
    - GetMyeBaySelling Documentation: https://developer.ebay.com/devzone/xml/docs/reference/ebay/getmyebayselling.html
    */
	v_Page = ifnull(p_Page,1);
	v_PerPage = ifnull(p_PerPage,200);
	m_Output = Map();
	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 = "GetMyeBaySelling";
		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_ActiveList = Map();
		m_ActiveList.put("Include","true");
		m_ActiveList.put("ListingType","FixedPriceItem");
		m_Pagination = Map();
		m_Pagination.put("PageNumber",v_Page);
		m_Pagination.put("EntriesPerPage",v_PerPage);
		m_ActiveList.put("Pagination",m_Pagination);
		// uncomment this when all products retrieved and to run this to just get latest products
		// m_ActiveList.put("Sort","ItemIDDescending");
		m_ActiveList.put("Sort","ItemID");
		m_Params.put("ActiveList",m_ActiveList);
		//
		// exclude sold items
		m_SoldList = Map();
		m_SoldList.put("Include","false");
		m_Params.put("SoldList",m_SoldList);
		//
		// exclude unsold items (ended before purchase)
		m_UnsoldList = Map();
		m_UnsoldList.put("Include","false");
		m_Params.put("UnsoldList",m_UnsoldList);
		//
		// exclude variations
		m_Params.put("HideVariations","true");
		//
		// restrict what fields to return
		l_OutputFields = List();
		l_OutputFields.add("BuyItNowPrice");
		l_OutputFields.add("ItemID");
		l_OutputFields.add("SKU");
		l_OutputFields.add("StartTime");
		l_OutputFields.add("TotalNumberOfPages");
		l_OutputFields.add("TotalNumberOfEntries");
		m_Params.put("OutputSelector",l_OutputFields);
		//
		// 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;
		//
		// if successful then read the response
		if(r_ResponseXML.contains("<Ack>Success</Ack>"))
		{
			// 
			// init
			l_JSONItems = List();
			//
			// parse the data
			v_MainNode = "ActiveList";
			x_MainNode = r_ResponseXML.subString(r_ResponseXML.indexOf("<" + v_MainNode),r_ResponseXML.lastIndexOf("</" + v_MainNode) + v_MainNode.length() + 3);
			l_Items = x_MainNode.executeXPath("//ItemArray/*").toXmlList();
			for each x_Item in l_Items
            {
				m_Item = Map();
				m_Item.put("ID", x_Item.executeXPath("//ItemID/text()").toLong());
				m_Item.put("Currency", x_Item.executeXPath("//BuyItNowPrice/@currencyID").executeXPath("/currencyID/text()"));
				m_Item.put("Price", x_Item.executeXPath("//BuyItNowPrice/text()").toDecimal());
				m_Item.put("SKU", x_Item.executeXPath("//SKU/text()"));
				m_Item.put("StartTime", x_Item.executeXPath("//ListingDetails/StartTime/text()").getPrefix(".").replaceFirst("T", " ", true));
				l_JSONItems.add(m_Item);
            } 
			m_Output.put("Items", l_JSONItems);
			v_PageNode = "PaginationResult";
			x_PageNode = r_ResponseXML.subString(r_ResponseXML.indexOf("<" + v_PageNode),r_ResponseXML.lastIndexOf("</" + v_PageNode) + v_PageNode.length() + 3);
			m_Output.put("TotalEntries", x_PageNode.executeXPath("//TotalNumberOfPages/text()").toLong());
			m_Output.put("TotalPages", x_PageNode.executeXPath("//TotalNumberOfEntries/text()").toLong());
		}
	}
	return m_Output;
}
	- map API.fn_eBayQuery_GetActiveProducts(int p_Page, int p_PerPage)
- {
- /*
- Function: fn_eBayQuery_GetActiveProducts()
- Purpose: Fetches current listings / active products
- Date Created: 2021-10-13 (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
- - GetMyeBaySelling Documentation: https://developer.ebay.com/devzone/xml/docs/reference/ebay/getmyebayselling.html
- */
- v_Page = ifnull(p_Page,1);
- v_PerPage = ifnull(p_PerPage,200);
- m_Output = Map();
- 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 = "GetMyeBaySelling";
- 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_ActiveList = Map();
- m_ActiveList.put("Include","true");
- m_ActiveList.put("ListingType","FixedPriceItem");
- m_Pagination = Map();
- m_Pagination.put("PageNumber",v_Page);
- m_Pagination.put("EntriesPerPage",v_PerPage);
- m_ActiveList.put("Pagination",m_Pagination);
- // uncomment this when all products retrieved and to run this to just get latest products
- // m_ActiveList.put("Sort","ItemIDDescending");
- m_ActiveList.put("Sort","ItemID");
- m_Params.put("ActiveList",m_ActiveList);
- //
- // exclude sold items
- m_SoldList = Map();
- m_SoldList.put("Include","false");
- m_Params.put("SoldList",m_SoldList);
- //
- // exclude unsold items (ended before purchase)
- m_UnsoldList = Map();
- m_UnsoldList.put("Include","false");
- m_Params.put("UnsoldList",m_UnsoldList);
- //
- // exclude variations
- m_Params.put("HideVariations","true");
- //
- // restrict what fields to return
- l_OutputFields = List();
- l_OutputFields.add("BuyItNowPrice");
- l_OutputFields.add("ItemID");
- l_OutputFields.add("SKU");
- l_OutputFields.add("StartTime");
- l_OutputFields.add("TotalNumberOfPages");
- l_OutputFields.add("TotalNumberOfEntries");
- m_Params.put("OutputSelector",l_OutputFields);
- //
- // 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;
- //
- // if successful then read the response
- if(r_ResponseXML.contains("<Ack>Success</Ack>"))
- {
- //
- // init
- l_JSONItems = List();
- //
- // parse the data
- v_MainNode = "ActiveList";
- x_MainNode = r_ResponseXML.subString(r_ResponseXML.indexOf("<" + v_MainNode),r_ResponseXML.lastIndexOf("</" + v_MainNode) + v_MainNode.length() + 3);
- l_Items = x_MainNode.executeXPath("//ItemArray/*").toXmlList();
- for each x_Item in l_Items
- {
- m_Item = Map();
- m_Item.put("ID", x_Item.executeXPath("//ItemID/text()").toLong());
- m_Item.put("Currency", x_Item.executeXPath("//BuyItNowPrice/@currencyID").executeXPath("/currencyID/text()"));
- m_Item.put("Price", x_Item.executeXPath("//BuyItNowPrice/text()").toDecimal());
- m_Item.put("SKU", x_Item.executeXPath("//SKU/text()"));
- m_Item.put("StartTime", x_Item.executeXPath("//ListingDetails/StartTime/text()").getPrefix(".").replaceFirst("T", " ", true));
- l_JSONItems.add(m_Item);
- }
- m_Output.put("Items", l_JSONItems);
- v_PageNode = "PaginationResult";
- x_PageNode = r_ResponseXML.subString(r_ResponseXML.indexOf("<" + v_PageNode),r_ResponseXML.lastIndexOf("</" + v_PageNode) + v_PageNode.length() + 3);
- m_Output.put("TotalEntries", x_PageNode.executeXPath("//TotalNumberOfPages/text()").toLong());
- m_Output.put("TotalPages", x_PageNode.executeXPath("//TotalNumberOfEntries/text()").toLong());
- }
- }
- return m_Output;
- }
copyraw
	
and the output gives me a JSON Map that looks similar to the following:
<?xml version="1.0" encoding="UTF-8"?> <GetMyeBaySellingResponse xmlns="urn:ebay:apis:eBLBaseComponents"> <Timestamp>2021-10-13T19:29:49.314Z</Timestamp> <Ack>Success</Ack> <Version>1173</Version> <Build>E1173_CORE_APISELLING_19187371_R1</Build> <ActiveList> <ItemArray> <Item> <BuyItNowPrice currencyID="GBP">39.95</BuyItNowPrice> <ItemID>1234567890</ItemID> <ListingDetails> <StartTime>2019-11-06T16:56:14.000Z</StartTime> </ListingDetails> <SellingStatus/> <ShippingDetails/> <SKU>TEST-001</SKU> </Item> <Item> <BuyItNowPrice currencyID="GBP">42.95</BuyItNowPrice> <ItemID>2345678901</ItemID> <ListingDetails> <StartTime>2020-01-15T16:39:36.000Z</StartTime> </ListingDetails> <SellingStatus/> <ShippingDetails/> <SKU>TEST-002</SKU> </Item> <Item> <BuyItNowPrice currencyID="GBP">151.95</BuyItNowPrice> <ItemID>3456789012</ItemID> <ListingDetails> <StartTime>2020-03-07T11:22:09.000Z</StartTime> </ListingDetails> <SellingStatus/> <ShippingDetails/> <SKU>TEST-003</SKU> </Item> <Item> <BuyItNowPrice currencyID="GBP">37.95</BuyItNowPrice> <ItemID>4567890123</ItemID> <ListingDetails> <StartTime>2020-03-23T15:17:30.000Z</StartTime> </ListingDetails> <SellingStatus/> <ShippingDetails/> <SKU>TEST-004</SKU> </Item> <Item> <BuyItNowPrice currencyID="GBP">47.95</BuyItNowPrice> <ItemID>5678901234</ItemID> <ListingDetails> <StartTime>2020-03-23T15:17:32.000Z</StartTime> </ListingDetails> <SellingStatus/> <ShippingDetails/> <SKU>TEST-005</SKU> </Item> </ItemArray> <PaginationResult> <TotalNumberOfPages>105</TotalNumberOfPages> <TotalNumberOfEntries>522</TotalNumberOfEntries> </PaginationResult> </ActiveList> </GetMyeBaySellingResponse>
- <?xml version="1.0" encoding="UTF-8"?>
- <GetMyeBaySellingResponse
- xmlns="urn:ebay:apis:eBLBaseComponents">
- <Timestamp>2021-10-13T19:29:49.314Z</Timestamp>
- <Ack>Success</Ack>
- <Version>1173</Version>
- <Build>E1173_CORE_APISELLING_19187371_R1</Build>
- <ActiveList>
- <ItemArray>
- <Item>
- <BuyItNowPrice currencyID="GBP">39.95</BuyItNowPrice>
- <ItemID>1234567890</ItemID>
- <ListingDetails>
- <StartTime>2019-11-06T16:56:14.000Z</StartTime>
- </ListingDetails>
- <SellingStatus/>
- <ShippingDetails/>
- <SKU>TEST-001</SKU>
- </Item>
- <Item>
- <BuyItNowPrice currencyID="GBP">42.95</BuyItNowPrice>
- <ItemID>2345678901</ItemID>
- <ListingDetails>
- <StartTime>2020-01-15T16:39:36.000Z</StartTime>
- </ListingDetails>
- <SellingStatus/>
- <ShippingDetails/>
- <SKU>TEST-002</SKU>
- </Item>
- <Item>
- <BuyItNowPrice currencyID="GBP">151.95</BuyItNowPrice>
- <ItemID>3456789012</ItemID>
- <ListingDetails>
- <StartTime>2020-03-07T11:22:09.000Z</StartTime>
- </ListingDetails>
- <SellingStatus/>
- <ShippingDetails/>
- <SKU>TEST-003</SKU>
- </Item>
- <Item>
- <BuyItNowPrice currencyID="GBP">37.95</BuyItNowPrice>
- <ItemID>4567890123</ItemID>
- <ListingDetails>
- <StartTime>2020-03-23T15:17:30.000Z</StartTime>
- </ListingDetails>
- <SellingStatus/>
- <ShippingDetails/>
- <SKU>TEST-004</SKU>
- </Item>
- <Item>
- <BuyItNowPrice currencyID="GBP">47.95</BuyItNowPrice>
- <ItemID>5678901234</ItemID>
- <ListingDetails>
- <StartTime>2020-03-23T15:17:32.000Z</StartTime>
- </ListingDetails>
- <SellingStatus/>
- <ShippingDetails/>
- <SKU>TEST-005</SKU>
- </Item>
- </ItemArray>
- <PaginationResult>
- <TotalNumberOfPages>105</TotalNumberOfPages>
- <TotalNumberOfEntries>522</TotalNumberOfEntries>
- </PaginationResult>
- </ActiveList>
- </GetMyeBaySellingResponse>
copyraw
	
{
  "Items": [
    {
      "ID": 1234567890,
      "Currency": "GBP",
      "Price": 39.95,
      "SKU": "TEST-001",
      "StartTime": "2019-11-06 16:56:14"
    },
    {
      "ID": 2345678901,
      "Currency": "GBP",
      "Price": 42.95,
      "SKU": "TEST-002",
      "StartTime": "2020-01-15 16:39:36"
    },
    {
      "ID": 3456789012,
      "Currency": "GBP",
      "Price": 151.95,
      "SKU": "TEST-003",
      "StartTime": "2020-03-07 11:22:09"
    },
    {
      "ID": 4567890123,
      "Currency": "GBP",
      "Price": 37.95,
      "SKU": "TEST-004",
      "StartTime": "2020-03-23 15:17:30"
    },
    {
      "ID": 5678901234,
      "Currency": "GBP",
      "Price": 47.95,
      "SKU": "TEST-005",
      "StartTime": "2020-03-23 15:17:32"
    }
  ],
  "TotalEntries": "105",
  "TotalPages": "522"
}
	- {
- "Items": [
- {
- "ID": 1234567890,
- "Currency": "GBP",
- "Price": 39.95,
- "SKU": "TEST-001",
- "StartTime": "2019-11-06 16:56:14"
- },
- {
- "ID": 2345678901,
- "Currency": "GBP",
- "Price": 42.95,
- "SKU": "TEST-002",
- "StartTime": "2020-01-15 16:39:36"
- },
- {
- "ID": 3456789012,
- "Currency": "GBP",
- "Price": 151.95,
- "SKU": "TEST-003",
- "StartTime": "2020-03-07 11:22:09"
- },
- {
- "ID": 4567890123,
- "Currency": "GBP",
- "Price": 37.95,
- "SKU": "TEST-004",
- "StartTime": "2020-03-23 15:17:30"
- },
- {
- "ID": 5678901234,
- "Currency": "GBP",
- "Price": 47.95,
- "SKU": "TEST-005",
- "StartTime": "2020-03-23 15:17:32"
- }
- ],
- "TotalEntries": "105",
- "TotalPages": "522"
- }
Additional:
See my other articles for integrating eBay API with Zoho Creator:
Category: Zoho :: Article: 778
	

 
			      
						  
                 
						  
                 
						  
                 
						  
                 
						  
                 
 
 

 
 
Add comment