Příklady použití
PHP Integrace
<?php
function downloadOrders($exportUrl, $username = null, $password = null) {
$ch = curl_init($exportUrl);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_TIMEOUT => 300, // 5 minut
]);
// HTTP Basic Auth
if ($username && $password) {
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
}
$xml = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200) {
throw new Exception("HTTP Error: $httpCode");
}
return $xml;
}
// Použití
try {
$xml = downloadOrders(
'https://eshop.cz/api/v1/rocketoo/type/orderexports/xyz123',
'api_user',
'7h#mK9$pL2@q'
);
// Zpracování XML
$orders = simplexml_load_string($xml);
foreach ($orders->ORDER as $order) {
echo "Objednávka: " . $order->ORDER_NUMBER . "\n";
echo "Zákazník: " . $order->CUSTOMER->EMAIL . "\n";
echo "Celkem: " . $order->PRICE_TOTAL_CURRENCY_VAT . " " . $order->CURRENCY . "\n\n";
}
} catch (Exception $e) {
echo "Chyba: " . $e->getMessage();
}Python Integrace
import requests
import xml.etree.ElementTree as ET
from datetime import datetime
def download_orders(export_url, username=None, password=None):
"""Stáhne objednávky z Rocketoo"""
auth = (username, password) if username and password else None
response = requests.get(
export_url,
auth=auth,
timeout=300
)
if response.status_code != 200:
raise Exception(f"HTTP Error: {response.status_code}")
return response.text
# Použití
try:
xml_data = download_orders(
'https://eshop.cz/api/v1/rocketoo/type/orderexports/xyz123',
'api_user',
'7h#mK9$pL2@q'
)
# Zpracování XML
root = ET.fromstring(xml_data)
for order in root.findall('ORDER'):
order_number = order.find('ORDER_NUMBER').text
customer_email = order.find('CUSTOMER/EMAIL').text
total = order.find('PRICE_TOTAL_CURRENCY_VAT').text
currency = order.find('CURRENCY').text
print(f"Objednávka: {order_number}")
print(f"Zákazník: {customer_email}")
print(f"Celkem: {total} {currency}\n")
except Exception as e:
print(f"Chyba: {e}")Last updated
Was this helpful?