Appearance
Quick Start
WARNING
The PHP SDK is still under development. You may experience performance or stability issues with the library itself. Please be patient, updates will be released regularly.
Installation
SHELL
npm install @tscommerce/sdk-typescriptSHELL
composer install tscommerce/sdk-phpInitialization
TS
import { SDK, prodConfig } from '@tscommerce/sdk-typescript';
const Client = new SDK(prodConfig);
Client.setTenant('TENANT_ID');
Client.setApiKey('TENANT_API_KEY');
const authorizationCode = Client.API.Auth.getAuthorizationCode();
Client.setAuthorizationCode(authorizationCode);PHP
$config = New \TeamSystem\Commerce\Config::prodConfig();
$client = New \TeamSystem\Commerce\SDK($config);
$client->setTenant('TENANT_ID');
$client->setApiKey('TENANT_API_KEY');
$authorizationCode = $client->API->Auth->getAuthorizationCode();
$client->setAuthorizationCode($authorizationCode);Examples
TS
// Method 1 - Easy to use
const products:Response<Products> = await Client.API.Products.all().resource.data;
const product:Response<Products> = await Client.API.Products.get(1).resource.data;
// Method 2 - Data consistency
Client.API.Products.all().then((response:PaginatedResponse<Products>) => {
if (response.type === ResponseType.SUCCESS) {
const data:Products = response.resource.data;
data.forEach((product:Product) => {
// Your code here... //
});
} else {
// There was an error while retrieving your data
console.log(response);
}
});
Client.API.Products.get(1).then((response:Response<Product>) => {
if (response.type === ResponseType.SUCCESS) {
const data:Product = response.resource.data;
// Your code here... //
} else {
// There was an error while retrieving product data
console.log(response);
}
});PHP
$products = $client->API->Core->Products->all()->resource->data; // Array of Products
$product = $client->API->Core->Products->get(1)->resource->data; // Product Data