Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $username = "utente";
- $password = "Password";
- $apiKey = "chiaveApi";
- $url = "https://www.brandsdistribution.com/";
- //$url = "https://idt2015.rewix.zero11.net/"; #SandBox
- $url .= "restful/export/api/products.xml";
- $query = http_build_query([
- 'acceptedlocales' => 'it_IT',
- 'output-file' => 'xml',
- 'since' => date("Y-m-d\TH:i:sO")
- ]);
- $url = "$url?".$query;
- echo $url;
- $header = "Authorization: Basic " . base64_encode($apiKey . ':' . $password);
- $xmlstr = <<<XML
- <?xml version='1.0' standalone='yes'?>
- <operations>
- </operations>
- XML;
- $xml = new SimpleXMLElement($xmlstr);
- $xmlOperation = $xml->addChild('operation');
- $xmlOperation->addAttribute(‘type’, ‘lock’);
- $xmlModel = $xmlOperation->addChild('model');
- $xmlModel->addAttribute(‘stock_id’, 1);
- $xmlModel->addAttribute(‘quantity’, 1);
- $xmlText = $xml->asXML();
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_USERPWD, ($username . ':' . $password));
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml','Accept: application/xml',$header));
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlText);
- $data = curl_exec($ch);
- $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close($ch);
- echo $data;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement