diff --git a/php/getArticlesDelta.php b/php/getArticlesDelta.php new file mode 100644 index 0000000..15a8745 --- /dev/null +++ b/php/getArticlesDelta.php @@ -0,0 +1,58 @@ + + */ + +/* + * 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); +} diff --git a/php/getArticlesFull.php b/php/getArticlesFull.php new file mode 100644 index 0000000..7cd7bfe --- /dev/null +++ b/php/getArticlesFull.php @@ -0,0 +1,55 @@ + + */ + +/* + * 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); +} diff --git a/php/getOrderMessages.php b/php/getOrderMessages.php new file mode 100644 index 0000000..8c64d1d --- /dev/null +++ b/php/getOrderMessages.php @@ -0,0 +1,72 @@ + + */ + +/* + * 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/" . (int)$oMessage->MESSAGE_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: " . $oMessage->MESSAGE_ID . " successfully sent." . PHP_EOL; + } + curl_close($oCurl); + } +} else { + print_r($sResponse); +} diff --git a/php/getOrders.php b/php/getOrders.php new file mode 100644 index 0000000..29e0b9c --- /dev/null +++ b/php/getOrders.php @@ -0,0 +1,105 @@ + + */ + +/* + * 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; + + $orderId = (string)$oOrder->ORDER_DATA->TB_ID; + echo "Order ID in Tradebyte " . $orderId . 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($orderId, $sMerchantId, $sApiUser, $sApiPassword); + } +} else { + print_r($sResponse); +} + + + +function sendExportedFlagToTradebyte($orderId, $sMerchantId, $sApiUser, $sApiPassword) +{ + + $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); +} diff --git a/php/getStocks.php b/php/getStocks.php new file mode 100644 index 0000000..ddd285c --- /dev/null +++ b/php/getStocks.php @@ -0,0 +1,47 @@ + + */ + +/* + * 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); +} diff --git a/php/sendArticle.php b/php/sendArticle.php new file mode 100644 index 0000000..03e41bd --- /dev/null +++ b/php/sendArticle.php @@ -0,0 +1,89 @@ + + */ + +/* + * 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 + +/* + * Product XML + */ +$sNewLine = "\n"; +$sXml = '' . $sNewLine; +$sXml .= '' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' 1777' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' 1' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' Product Test Name' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' Long Description of product and all details' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= '
' . $sNewLine; +$sXml .= ' 1777-1' . $sNewLine; +$sXml .= ' 1' . $sNewLine; +$sXml .= ' 2515911601760' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' 058de82247787f5fd54d523f0c823e0' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' 79.00' . $sNewLine; +$sXml .= ' 99.00' . $sNewLine; +$sXml .= ' 99.00' . $sNewLine; +$sXml .= ' 3' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' https://i.picsum.photos/id/1000/1000/1000.jpg?hmac=YU8XuX62UAwEXXFELdXRqFZDQJfD9JDwDv13xTWCvL8' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' 48' . $sNewLine; +$sXml .= '
' . $sNewLine; +$sXml .= '
' . $sNewLine; +$sXml .= '
' . $sNewLine; +$sXml .= '
' . $sNewLine; +$sXml .= '
' . $sNewLine; + +/** + * Name the file according to specifications + */ +$fileName = "TBCAT_" . date("YmdHis") . ".xml"; + + +/* + * Send data to REST API with curl + */ +$sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/sync/in/" . $fileName; + +$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); +curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); +curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($oCurl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml')); +curl_setopt($oCurl, CURLOPT_POSTFIELDS, $sXml); + +$sResponse = curl_exec($oCurl); +if ($sResponse === false) { + echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); +} else { + print_r($sResponse); +} +curl_close($oCurl); diff --git a/php/sendOrder.php b/php/sendOrder.php new file mode 100644 index 0000000..88e6e6f --- /dev/null +++ b/php/sendOrder.php @@ -0,0 +1,89 @@ + + */ + +/* + * 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 + +/* + * Example order XML + */ +$sNewLine = "\n"; +$sXml = '' . $sNewLine; +$sXml .= '' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' 2020-10-14' . $sNewLine; +$sXml .= ' 5555' . $sNewLine; +$sXml .= ' 1' . $sNewLine; +$sXml .= ' 1' . $sNewLine; +$sXml .= ' 297.00' . $sNewLine; +$sXml .= ' 2020-10-14T10:47:07' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' 55' . $sNewLine; +$sXml .= ' Max' . $sNewLine; +$sXml .= ' Mustermann' . $sNewLine; +$sXml .= ' Max Mustermann' . $sNewLine; +$sXml .= ' Bahnhofsplatz 8' . $sNewLine; +$sXml .= ' 91522' . $sNewLine; +$sXml .= ' Ansbach' . $sNewLine; +$sXml .= ' DE' . $sNewLine; +$sXml .= ' example@tradebyte.com' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' 55' . $sNewLine; +$sXml .= ' Max' . $sNewLine; +$sXml .= ' Mustermann' . $sNewLine; +$sXml .= ' Max Mustermann' . $sNewLine; +$sXml .= ' Bahnhofsplatz 8' . $sNewLine; +$sXml .= ' 91522' . $sNewLine; +$sXml .= ' Ansbach' . $sNewLine; +$sXml .= ' DE' . $sNewLine; +$sXml .= ' example@tradebyte.com' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' 675443254657' . $sNewLine; +$sXml .= ' 555-85-853-6-5' . $sNewLine; +$sXml .= ' 3' . $sNewLine; +$sXml .= ' Example Product' . $sNewLine; +$sXml .= ' 99.000' . $sNewLine; +$sXml .= ' 99.000' . $sNewLine; +$sXml .= ' 2020-10-14T10:47:07' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= ' ' . $sNewLine; +$sXml .= '' . $sNewLine; + +/* + * Send data to 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_POST, true); +curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); +curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($oCurl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml')); +curl_setopt($oCurl, CURLOPT_POSTFIELDS, $sXml); + +$sResponse = curl_exec($oCurl); +if ($sResponse === false) { + echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); +} else { + print_r($sResponse); +} +curl_close($oCurl); diff --git a/php/sendOrderMessages.php b/php/sendOrderMessages.php new file mode 100644 index 0000000..74d27c2 --- /dev/null +++ b/php/sendOrderMessages.php @@ -0,0 +1,60 @@ + + */ + +/* + * 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 + +/* + * Example message + */ +$sNewLine = "\n"; +$sXml = '' . $sNewLine; +$sXml .= '' . $sNewLine; +$sXml .= '' . $sNewLine; +$sXml .= ' SHIP' . $sNewLine; +$sXml .= ' 42' . $sNewLine; +$sXml .= ' 52' . $sNewLine; +$sXml .= ' 1302' . $sNewLine; +$sXml .= ' test' . $sNewLine; +$sXml .= ' test858555' . $sNewLine; +$sXml .= ' kjgded-555' . $sNewLine; +$sXml .= ' 1' . $sNewLine; +$sXml .= ' DE57373542354235BR' . $sNewLine; +$sXml .= ' 2020-10-15T14:45:32' . $sNewLine; +$sXml .= '' . $sNewLine; +$sXml .= '' . $sNewLine; + +/* + * Send data to REST API with curl + */ +$sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/messages/?"; + +$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); +curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); +curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($oCurl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml')); +curl_setopt($oCurl, CURLOPT_POSTFIELDS, $sXml); + +$sResponse = curl_exec($oCurl); +if ($sResponse === false) { + echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); +} else { + print_r($sResponse); +} +curl_close($oCurl); diff --git a/php/sendStocks.php b/php/sendStocks.php new file mode 100644 index 0000000..3d9a1f4 --- /dev/null +++ b/php/sendStocks.php @@ -0,0 +1,60 @@ + + */ + +/* + * 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 + + +/* + * Example status data + */ +$sNewLine = "\n"; +// Values obtained in the shop, for example, to be sent to Tradebyte +$aStockInfo['article_number'] = "5552-55-853-6-2"; //Article Number +$aStockInfo['stock_value'] = 42; //updated stock +/** + * Preparing Xml structure according to Tradebyte specs + */ +$sXml = '' . $sNewLine; +$sXml .= "" . $sNewLine; +$sXml .= " " . $sNewLine; +$sXml .= "
" . $sNewLine; +$sXml .= " {$aStockInfo['article_number']}" . $sNewLine; +$sXml .= " {$aStockInfo['stock_value']}" . $sNewLine; +$sXml .= "
" . $sNewLine; +$sXml .= "
" . $sNewLine; +$sXml .= "
" . $sNewLine; + +/** + * Send data to REST API with curl + */ +$sUrl = "https://rest.trade-server.net/" . $sMerchantId . "/articles/stock"; + +$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); +curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); +curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($oCurl, CURLOPT_HTTPHEADER, array('Content-Type: application/xml')); +curl_setopt($oCurl, CURLOPT_POSTFIELDS, $sXml); + +$sResponse = curl_exec($oCurl); +if ($sResponse === false) { + echo 'Error: ' . curl_error($oCurl) . ' ErrorNr: ' . curl_errno($oCurl); +} else { + echo "Stock sent successfully"; +}