You are here:  » shopping.com api


shopping.com api

Submitted by bdl on Wed, 2007-04-11 19:43 in

Hi
Can MagicParser be used with the shopping.com api?

Submitted by support on Mon, 2007-04-16 08:46

Hi,

If the shopping.com API returns a record based XML response to a simple URL (sometimes called "REST") then you should be able to use Magic Parser directly as you just provide the URL as the filename.

If the API requires SOAP to access it then you will need to use a separate SOAP library (or use PHP 5's built in SOAP library) to obtain the XML and then use Magic Parser to process the response.

If in doubt, don't forget that you can upload a sample of the response XML to the demo tool and check compatability.

Cheers,
David.

Submitted by bdl on Mon, 2007-04-16 20:35

Hi David,
I have two questions before deciding to purchase MagicParser.

1. Could you please tell me if the following is REST or SOAP? {xml saved}

2. I'm planning on using MagicParser inside patTemplate. Would this work?

<patTemplate:php>
  require("MagicParser.php");
  function myRecordHandler($record)
  {
    print_r($record);
  }
  MagicParser_parse("{PATHTODATA}","myRecordHandler");
</patTemplate:php>

where {PATHTODATA} is the xml url field.

Thanks in advance.

B.

Submitted by support on Tue, 2007-04-17 11:52

Hi,

To answer your first question; it is not possible to tell from the response what method has been used obtain the data - it could have been REST or SOAP. Having said that, I have searched back through my support scripts and I do have examples of using Magic Parser with the response from the shopping.com API. The method used is REST; and in fact this can also be identified from your second question where you state that {PATHTODATA} is the xml url field.

I'm not sure about using patTemplate; however there should be no reason why the sample you posted would not work if the PHP code is executed normally; and you are able to include() files in this way. You might want to run a test script to confirm that this is ok.

Finally, having studied your response XML, and compared this against previous examples I would recommend providing a format string as the optional 3rd parameter to MagicParser_parse(). This is because the auto-detection opens the source XML file twice; which as you are using a URL means that the request will be made twice which is not desirable. The format string for accessing the product records in the sample XML you posted is:

xml|DSP/RESULT/DOMAIN/DOMAIN-LISTING/PRODUCTS/PRODUCT/

This would make your PHP snippet something like this:

<patTemplate:php>
  require("MagicParser.php");
  function myRecordHandler($record)
  {
    print_r($record);
  }
  MagicParser_parse("{PATHTODATA}","myRecordHandler","xml|DSP/RESULT/DOMAIN/DOMAIN-LISTING/PRODUCTS/PRODUCT/");
</patTemplate:php>

Hope this helps!
Cheers,
David.