...

View Full Version : Help with Product API



ROYW1000
01-15-2012, 04:35 PM
Hi

I want to learn how to build a XML API Server and have read up on Rest etc but really stuck where to even start and how the query would work.

I have read a lot of stuff online and for simple API queries like sum to numbers I can find but nothing as complex as this using things like Count=3 and ShortDescription=Y.

The bit I am most stuck on taking the URL and making that into the query. Actually getting the data out into the XML should not be so hard.

I dont suppose anyone has done anything like this before and can share some code or examples or seen anything like this in a book or online.

I want to make something like the following:-

http://www.website.com/productxml?dep=1&count=3&Name=Y&ShortDescription=Y

Depending on what people request the output could be different and could contain any of the following:

The following are acceptable field requests:

BrandName
Manufacturer
ManufacturerPartNumber
ModelNumber
Name
Origin
Price
Quality
Stock
ShortDescription
SKU
ThumbnailURL
UPC
Warranty
ProductURL


Many thanks in advance.
Roy

BluePanther
01-15-2012, 04:39 PM
PHP populates URL query strings inside the $_GET array. So, index.php?id=1 will have $_GET['id'] as '1' (note, all values will be string datatype) in index.php. So, the XML API you're making will accept GET queries, and return XML output based on those :).

ROYW1000
01-15-2012, 04:45 PM
Hi

How would the query part work for example.

Say I want a default of a maximum 100 results unless Count=250 etc and the customer Posts the following URL

/productxml?dep=1&count=3&Name=Y&ShortDescription=Y

How do you formulate the PHP and MySQL to accept Name=Y so it queries out the Name and if ShortDescription=Y how would this be coded in to pull out it in the results.

Thanks
Roy

BluePanther
01-15-2012, 04:57 PM
Hi

How would the query part work for example.

Say I want a default of a maximum 100 results unless Count=250 etc and the customer Posts the following URL

/productxml.php?dep=1&count=3&Name=Y&ShortDescription=Y

How do you formulate the PHP and MySQL to accept Name=Y so it queries out the Name and if ShortDescription=Y how would this be coded in to pull out it in the results.

Thanks
Roy

Just using your example, that would populate the $_GET array with:


$_GET['dep'] = '1';
$_GET['count'] = '3';
$_GET['name'] = 'Y';
$_GET['shortdescription'] = 'Y';

All accessible inside productxml.php using $_GET['index']. If you're using them in mysql queries, remember to use mysql_real_escape_string() to stop SQL injection.

ROYW1000
01-15-2012, 08:29 PM
Hi

How would I go about setting the default Count to say 100 unless the URL contains Count=1000 etc.

Thanks
Roy

BluePanther
01-15-2012, 09:48 PM
Hi

How would I go about setting the default Count to say 100 unless the URL contains Count=1000 etc.

Thanks
Roy

You would check each one isset(), and if isset() returns false, you would produce and error or the default value.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum