-
Notifications
You must be signed in to change notification settings - Fork 1
PHP example Snippets for API methods #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
3794f07
4642607
fa6ee26
cb45b21
0a6de6b
223e1a4
1f558c6
f2d41af
91a2926
f355a0d
1a9c72e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* This example script gets information on products and on its related articles from the Tradebyte REST API. | ||
* | ||
* @author Marcos Doellerer <marcos.doellerer@fatchip.de> | ||
*/ | ||
|
||
/* | ||
* API-Credentials - modify to your personal access credentials | ||
* | ||
* @see https://tradebyte.io/how-to/generate-rest-api-credentials-in-tb-one/ | ||
*/ | ||
$sApiUser = 'api-user'; // Your API username | ||
$sApiPassword = 'api-password'; // Your API password | ||
$sMerchantId = '1234'; // Your digit merchant ID | ||
$sChannelId = '5678'; // Your digit channel ID | ||
|
||
/* | ||
* Get data from REST API with curl | ||
*/ | ||
|
||
$iDelta = time() - (3600 * 12); //Get the delta for last 12 hours (current time minus 12 hours) | ||
$sUrl = "https://rest.trade-server.net/" . $sMerchantId ."/products/?channel=" . $sChannelId . '&delta=' . $iDelta; | ||
|
||
$oCurl = curl_init(); | ||
curl_setopt($oCurl, CURLOPT_URL, $sUrl); | ||
curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); | ||
curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); | ||
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($oCurl, CURLOPT_HEADER, 0); | ||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); | ||
curl_setopt($oCurl, CURLOPT_TIMEOUT, 3600); | ||
$sResponse = curl_exec($oCurl); | ||
if ($sResponse === false) { | ||
echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); | ||
} | ||
curl_close($oCurl); | ||
|
||
/* | ||
* Process data as you need | ||
*/ | ||
$oXml = simplexml_load_string($sResponse); | ||
if ($oXml && $oXml->PRODUCTDATA) { | ||
|
||
if ($oXml->SUPPLIER){ | ||
echo "Supplier: " . $oXml->SUPPLIER->NAME . PHP_EOL; | ||
} | ||
|
||
foreach ($oXml->PRODUCTDATA->PRODUCT as $oProduct) { | ||
echo "Product n° " . (string)$oProduct->P_NR . " title: " . (string)$oProduct->P_NAME->VALUE . PHP_EOL; | ||
|
||
foreach ($oProduct->ARTICLEDATA->ARTICLE as $oArticle) { | ||
echo "Article n° " . (string)$oArticle->A_NR . " ean: " . (string)$oArticle->A_EAN . PHP_EOL; | ||
} | ||
} | ||
} else { | ||
print_r($sResponse); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
/** | ||
* This example script gets information on products and on its related articles from the Tradebyte REST API. | ||
* | ||
* @author Marcos Doellerer <marcos.doellerer@fatchip.de> | ||
*/ | ||
|
||
/* | ||
* API-Credentials - modify to your personal access credentials | ||
* | ||
* @see https://tradebyte.io/how-to/generate-rest-api-credentials-in-tb-one/ | ||
*/ | ||
$sApiUser = 'api-user'; // Your API username | ||
$sApiPassword = 'api-password'; // Your API password | ||
$sMerchantId = '1234'; // Your digit merchant ID | ||
$sChannelId = '5678'; // Your digit channel ID | ||
|
||
/* | ||
* Get data from REST API with curl | ||
*/ | ||
$sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/products/?channel=" . $sChannelId; | ||
$oCurl = curl_init(); | ||
curl_setopt($oCurl, CURLOPT_URL, $sUrl); | ||
curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); | ||
curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); | ||
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($oCurl, CURLOPT_HEADER, 0); | ||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); | ||
curl_setopt($oCurl, CURLOPT_TIMEOUT, 3600); | ||
$sResponse = curl_exec($oCurl); | ||
if ($sResponse === false) { | ||
echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); | ||
} | ||
curl_close($oCurl); | ||
|
||
/* | ||
* Process data as you need | ||
*/ | ||
$oXml = simplexml_load_string($sResponse); | ||
if ($oXml && $oXml->PRODUCTDATA) { | ||
|
||
if ($oXml->SUPPLIER){ | ||
echo "Supplier: " . $oXml->SUPPLIER->NAME . PHP_EOL; | ||
} | ||
|
||
foreach ($oXml->PRODUCTDATA->PRODUCT as $oProduct) { | ||
echo "Product n° " . (string)$oProduct->P_NR . " title: " . (string)$oProduct->P_NAME->VALUE . PHP_EOL; | ||
|
||
foreach ($oProduct->ARTICLEDATA->ARTICLE as $oArticle) { | ||
echo "Article n° " . (string)$oArticle->A_NR . " ean: " . (string)$oArticle->A_EAN . PHP_EOL; | ||
} | ||
} | ||
} else { | ||
print_r($sResponse); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
/** | ||
* This example script gets information on changed order-status from the Tradebyte REST API. | ||
* Then it marks the messages as processed. | ||
* | ||
* @author Marcos Doellerer <marcos.doellerer@fatchip.de> | ||
*/ | ||
|
||
/* | ||
* API-Credentials - modify to your personal access credentials | ||
* | ||
* @see https://tradebyte.io/how-to/generate-rest-api-credentials-in-tb-one/ | ||
*/ | ||
$sApiUser = 'api-user'; // Your API username | ||
$sApiPassword = 'api-password'; // Your API password | ||
$sMerchantId = '1234'; // Your digit merchant ID | ||
$sChannelId = '5678'; // Your digit channel ID | ||
|
||
|
||
/* | ||
* Get data from REST API with curl | ||
*/ | ||
$sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/messages/?channel=" . $sChannelId; | ||
|
||
$oCurl = curl_init(); | ||
curl_setopt($oCurl, CURLOPT_URL, $sUrl); | ||
curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); | ||
curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); | ||
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($oCurl, CURLOPT_HEADER, 0); | ||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); | ||
curl_setopt($oCurl, CURLOPT_TIMEOUT, 3600); | ||
$sResponse = curl_exec($oCurl); | ||
if ($sResponse === false) { | ||
echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); | ||
} | ||
curl_close($oCurl); | ||
|
||
/** | ||
* Process data as you need | ||
*/ | ||
$oXml = simplexml_load_string($sResponse); | ||
if ($oXml) { | ||
foreach ($oXml->MESSAGE as $oMessage) { | ||
echo "Message Type: " . (string)$oMessage->MESSAGE_TYPE . PHP_EOL; | ||
echo " Order number in Channel : " . (string)$oMessage->CHANNEL_ORDER_ID . PHP_EOL; | ||
|
||
/** | ||
* Sending confirmation to Tradebyte | ||
*/ | ||
$sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/messages/" . (string)$oMessage->TB_ORDER_ID . "/processed?channel=" . $sChannelId; | ||
$oCurl = curl_init(); | ||
curl_setopt($oCurl, CURLOPT_URL, $sUrl); | ||
curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); | ||
curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); | ||
curl_setopt($oCurl, CURLOPT_POST, true); // This is a POST request! | ||
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($oCurl, CURLOPT_HEADER, 0); | ||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); | ||
curl_setopt($oCurl, CURLOPT_TIMEOUT, 30); | ||
$sResponse = curl_exec($oCurl); | ||
if ($sResponse === false) { | ||
echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); | ||
}else{ | ||
echo "'Message received' confirmation for Message id: " . $messageId . " successfully sent." . PHP_EOL; | ||
mdoellerer-fc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
curl_close($oCurl); | ||
} | ||
} else { | ||
print_r($sResponse); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
/** | ||
* This example script gets information on orders not yet exported from the Tradebyte REST API. | ||
* Then marks them as exported | ||
* | ||
* @author Marcos Doellerer<marcos.doellerer@fatchip.de> | ||
*/ | ||
|
||
/* | ||
* API-Credentials - modify to your personal access credentials | ||
* | ||
* @see https://tradebyte.io/how-to/generate-rest-api-credentials-in-tb-one/ | ||
*/ | ||
$sApiUser = 'api-user'; // Your API username | ||
$sApiPassword = 'api-password'; // Your API password | ||
$sMerchantId = '1234'; // Your digit merchant ID | ||
$sChannelId = '5678'; // Your digit channel ID | ||
|
||
/* | ||
* Get data from REST API with curl | ||
*/ | ||
$sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/orders/?channel=" . $sChannelId; | ||
$oCurl = curl_init(); | ||
curl_setopt($oCurl, CURLOPT_URL, $sUrl); | ||
curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); | ||
curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); | ||
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($oCurl, CURLOPT_HEADER, 0); | ||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); | ||
curl_setopt($oCurl, CURLOPT_TIMEOUT, 3600); | ||
$sResponse = curl_exec($oCurl); | ||
if ($sResponse === false) { | ||
echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); | ||
} | ||
curl_close($oCurl); | ||
|
||
/** | ||
* Process data as you need. | ||
*/ | ||
$oXml = simplexml_load_string($sResponse); | ||
|
||
if ($oXml) { | ||
|
||
$ordersImported = []; | ||
|
||
foreach ($oXml->ORDER as $oOrder) { | ||
echo "Order Date " . (string)$oOrder->ORDER_DATA->ORDER_DATE . PHP_EOL; | ||
|
||
$ordersImported[] = (string)$oOrder->ORDER_DATA->TB_ID; | ||
echo "Order ID in Tradebyte " . (string)$oOrder->ORDER_DATA->TB_ID . PHP_EOL; | ||
echo "Order Number (in channel): " . (string)$oOrder->ORDER_DATA->CHANNEL_NO . PHP_EOL; | ||
|
||
/** | ||
* Example of Shipping Information | ||
*/ | ||
if ($oOrder->SELL_TO){ | ||
echo "Payment Address: " . $oXml->ORDER->SELL_TO->STREET_NO . PHP_EOL; | ||
} | ||
/** | ||
* Tag SHIP_TO is mandatory so we don't need to check existence | ||
*/ | ||
echo "Shipping Address: " . $oXml->ORDER->SHIP_TO->STREET_NO . PHP_EOL; | ||
|
||
echo "Order Items: " . PHP_EOL; | ||
/** | ||
* Here we loop through Order's Items | ||
*/ | ||
foreach ($oOrder->ITEMS->ITEM as $oOrderItem) { | ||
echo "Article EAN " . (string)$oOrderItem->EAN . | ||
" Quantity: " . (string)$oOrderItem->QUANTITY . | ||
" Price: " . (string)$oOrderItem->ITEM_PRICE . PHP_EOL; | ||
|
||
} | ||
} | ||
|
||
/** | ||
* Sending confirmation to Tradebyte | ||
*/ | ||
sendExportedFlagToTradebyte($ordersImported, $sMerchantId, $sApiUser, $sApiPassword); | ||
|
||
|
||
} else { | ||
print_r($sResponse); | ||
} | ||
|
||
|
||
|
||
function sendExportedFlagToTradebyte($arrayOfIds, $sMerchantId, $sApiUser, $sApiPassword){ | ||
mdoellerer-fc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
foreach ($arrayOfIds as $orderId){ | ||
|
||
$sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/orders/" . $orderId . "/exported?"; | ||
|
||
$oCurl = curl_init(); | ||
curl_setopt($oCurl, CURLOPT_URL, $sUrl); | ||
curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); | ||
curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); | ||
curl_setopt($oCurl, CURLOPT_POST, true); // This is a POST request! | ||
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($oCurl, CURLOPT_HEADER, 0); | ||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); | ||
curl_setopt($oCurl, CURLOPT_TIMEOUT, 30); | ||
$sResponse = curl_exec($oCurl); | ||
if ($sResponse === false) { | ||
echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); | ||
} | ||
else{ | ||
echo "Export Confirmation for Order: " . $orderId . " successfully sent." . PHP_EOL; | ||
} | ||
curl_close($oCurl); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* This example script gets stocks for all articles from the Tradebyte REST API. | ||
* | ||
* @author Hendrik Bahr <bahr@fatchip.de> | ||
*/ | ||
|
||
/* | ||
* API-Credentials - modify to your personal access credentials | ||
* | ||
* @see https://tradebyte.io/how-to/generate-rest-api-credentials-in-tb-one/ | ||
*/ | ||
$sApiUser = 'api-user'; // Your API username | ||
$sApiPassword = 'api-password'; // Your API password | ||
$sMerchantId = '1234'; // Your digit merchant ID | ||
$sChannelId = '5678'; // Your digit channel ID | ||
|
||
/* | ||
* Get data from REST API with curl | ||
*/ | ||
$sUrl = "https://rest.trade-server.net/" . $sMerchantId ."/stock/?channel=" . $sChannelId; | ||
$oCurl = curl_init(); | ||
curl_setopt($oCurl, CURLOPT_URL, $sUrl); | ||
curl_setopt($oCurl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); | ||
curl_setopt($oCurl, CURLOPT_USERPWD, $sApiUser . ":" . $sApiPassword); | ||
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($oCurl, CURLOPT_HEADER, 0); | ||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); | ||
curl_setopt($oCurl, CURLOPT_TIMEOUT, 3600); | ||
$sResponse = curl_exec($oCurl); | ||
if ($sResponse === false) { | ||
echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); | ||
} | ||
curl_close($oCurl); | ||
|
||
/* | ||
* Process data as you need | ||
*/ | ||
$oXml = simplexml_load_string($sResponse); | ||
if ($oXml && $oXml->ARTICLE) { | ||
foreach ($oXml->ARTICLE as $oProduct) { | ||
echo (string)$oProduct->A_NR . ": " . (string)$oProduct->A_STOCK . PHP_EOL; | ||
} | ||
} else { | ||
print_r($sResponse); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.