Method: listProducts

This methods makes possible to display the products and their attributes from our server.

Authentication

This method does requires authentication.

HTTP method

This method is called with HTTP method GET.

Arguments

Argument Type Element (array) Valid Values Default Value Detail
token string   authenticated session id (stored in the session $_SESSION['token']) required User Token

Returned Values

Element (path) Name Type Description
/ nb_results int total number of products
/[n]/ id int product unique ID
/[n]/ title string product title (used for title tag)
/[n]/ data array the other data for a product like size, orientation, backside, price, etc.
/ text array
SUCCESS!  or  ERROR: You have to be authentified to use this method!

Example Query

	GET http://testapi.wannaprint.com/Rest/1/[API Key]/api/listProducts/token=[token]

PHP call of method:
	<?php
		session_start();
		$api_items = $apicaller->sendRequest(array(
					'controller' => 'api',
					'action' =>  'listProducts',
					'token' =>  $_SESSION['token']
					)); 
		foreach($api_items->text as $text)
		{
			echo $text;
		}
		if($api_items->nb_results>0)
		{
			echo "
				<strong>Products:</strong>
				<table border='0'>
					<tr>
						<th>ID</th>
						<th>Title</th>
						<th>Data 1</th>
						<th>Data 2</th>
						<th>Data 3</th>
						<th>Data 4</th>
						...
					</tr>
				";
			for($i=1; $i<=$api_items->nb_results; $i++)
			{
			echo '
					<tr>
						<td align="center">'.$api_items->$i->id.'</td>
						<td>'.$api_items->$i->title.'</td>
						<td>'.$api_items->$i->data->data1.'</td>
						<td>'.$api_items->$i->data->data2.'</td>
						<td>'.$api_items->$i->data->data3.'</td>
						<td>'.$api_items->$i->data->data4.'</td>
						...
						lt;/tr>';
			}
			echo "
				</table>";
		}
	?>
   			

Example Response

	{
		"text":["SUCCESS"],
		"1":{
			"id":"1",
			"title":"Business cards",
			"data":{
				size":"8,5 x 5,5 cm \/ 9 x 5 cm",
				"price":"0",
				"quantites":[
					250,
					500,
					1000,
					2000,
					3000,
					4000,
					5000,
					6000,
					7000,
					8000,
					9000,
					10000
				],
				"backsides":[
					"Vierge",
					"\"Imprimé par www.cartevisite.com\"",
					"impression en noir",
					"impression couleur"
				],					
				"orientation":[
					"Paysage",
					"Portrait"
				]
			},
		"nb_results":1
	}

						or

	{
		"text":["ERROR: You have to be authentified to use this method!"]
	}
   			

Error Codes

001: Wrong API Key
The API key is wrong or missing.
002: Failed to parse request
The request could not be parsed.
011: Controller is invalid.
The controller passed is not valid.
031: Invalid Method
This method does not exist in the method list.