PHP Classes

File: examples/product.md

Recommend this page to a friend!
  Classes of PHPLicengine   PHPLicengine API   examples/product.md   Download  
File: examples/product.md
Role: Auxiliary data
Content type: text/markdown
Description: Auxiliary data
Class: PHPLicengine API
Send HTTP requests to call REST Web service APIs
Author: By
Last change:
Date: 6 years ago
Size: 1,231 bytes
 

Contents

Class file image Download

All API URLs listed here must be prefixed by the root API URL, such as http://www.mysite.com/phplicengine/api

Service class:

$base_url = "http://www.mysite.com/phplicengine"; // no trailing slash!
$api = new \PHPLicengine\Service\Product($base_url, $api_key);

GET /product/{product_id} - Get Product Info by id (v2.2.1)

e.g. http://www.mysite.com/phplicengine/api/product/1

Service method:

$response = $api->getProductById(1);

Sample:

use PHPLicengine\Service\Product;
$base_url = "http://www.mysite.com/phplicengine"; // no trailing slash!
$api_key = "API key goes here";
try {
     $api = new Product ($base_url, $api_key);
     $response = $api->getProductById(1);
     if ($response->isError()) { // if response of api has error
         print($response->getErrorMessage());
     } else {
         // $dataAsObject = $response->getDecodedJson();
         // echo $dataAsObject->productName;
         // echo $response->getReference();
         print_r($response->getJsonAsArray());
     }
} catch (\Exception $e) {
     echo $e->getMessage();
}

GET /product/name/{name} - Get Product Info by name (v2.2.1)

Service method:

$response = $api->getProductByName($name);