Search code examples
xmlurlebay-api

How to specify ProductID Type in URL request in eBay Shopping API


I am currently trying to make a url request to the ebay shopping api using parameters from a xml string.

When it comes to making the url using properties from basic xml elements i have no problem specifying the url parameters by appending them using the & symbol.

For example:

The following xml:

 <?xml version="1.0" encoding="utf-8"?>
 <FindProductsRequest xmlns="urn:ebay:apis:eBLBaseComponents">
 <QueryKeywords>Harry Potter</QueryKeywords>
 <MaxEntries>2</MaxEntries>
 <AvailableItemsOnly>true</AvailableItemsOnly>
 </FindProductsRequest>

Becomes this url request,I achieve this by simply specifying the & symbol followed by the element name followed by the = sign and the value from the xml. This results in:

   http://open.api.ebay.com/shopping?
   QueryKeywords=harry%20potter&
   AvailableItemsOnly=true&
   MaxEntries=2**

However when the xml becomes more complicated such as when a xml element specifies a attribute such as the following xml element:

 <ProductID type="UPC">73292317238</ProductID>

I can't figure out how to include the type attribute into the url.

What I have tried:

I have tried specifying the type attribute in the url like this

 &type=UPC

However ebays system does not pick up that the type attribute belongs to the ProductID element.

I have also tried inserting the raw xml into the url, however that just messed up the whole request.

In summary I am trying to figure out how to encode a xml element that contain a attribute as well as a value into a url parameter?

If the question is not clear please specify which part to fix up. I have tried following the ask a good question guide and will be happy to fix up any parts that require improvement.


Solution

  • A translation between Xml and URL parameters is not generally defined, but defined by the vendor of the api, in this case eBay.

    AFAIK, this URL should work for the eBay Shopping api:

    http://....&ProductID.Type=UPC­&ProductID.Value=73292317238
    

    A general hint: by adding &responseencoding=NV to the request when searching by keywords, you get the result in URL format and can see what your request would have to look like to find the same product directly.