PHP中的Shopify XML Post
我无法使用PHP和Curl将XML数据发布到Shopify。我有:PHP中的Shopify XML Post,shopify,Shopify,我无法使用PHP和Curl将XML数据发布到Shopify。我有: $xml = '<?xml version="1.0" encoding="UTF-8"?><variant><id type="integer">260293006</id><fulfillment-service>manual</fulfillment-service><inventory-management>shopify</inv
$xml = '<?xml version="1.0" encoding="UTF-8"?><variant><id type="integer">260293006</id><fulfillment-service>manual</fulfillment-service><inventory-management>shopify</inventory-management><inventory-policy>deny</inventory-policy><sku>s136</sku><inventory-quantity type="integer">48</inventory-quantity><price>17.95</price></variant>';
$url = 'https://' . $API_KEY . ':' . $PASSWORD . '@' . $STORE_URL . '/admin/variants/#260293006.xml';
具有此标题的Shopify页面返回的内容:
<title>Shopify » Please Log In</title>
Shopify»;请登录
我想我可能遗漏了一些明显的东西。一旦我让这个函数起作用,其他一切都应该很容易构建。非常感谢。我认为#
中不需要$url
,应该是这样的
$url = 'https://' . $API_KEY . ':' . $PASSWORD . '@' . $STORE_URL . '/admin/variants/260293006.xml';
谢谢大家。基于这个反馈,我能够解决这个问题。主要问题:
$fp = tmpfile();
fwrite($fp, $xml);
fseek($fp, 0);
$session = curl_init();
curl_setopt($session, CURLOPT_URL, $url);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_PUT, true);
curl_setopt($session, CURLOPT_BINARYTRANSFER, true);
curl_setopt($session, CURLOPT_INFILE, $fp); // file pointer
curl_setopt($session, CURLOPT_INFILESIZE, strlen($xml));
curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
$response = curl_exec($session);
fclose($fp);
curl_close($session);
我认为这是一些进步。现在Shopify返回:未找到确保您的变体id正确。顺便问一下,您希望对“变体”执行什么操作?这是一个很好的文档
$fp = tmpfile();
fwrite($fp, $xml);
fseek($fp, 0);
$session = curl_init();
curl_setopt($session, CURLOPT_URL, $url);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_PUT, true);
curl_setopt($session, CURLOPT_BINARYTRANSFER, true);
curl_setopt($session, CURLOPT_INFILE, $fp); // file pointer
curl_setopt($session, CURLOPT_INFILESIZE, strlen($xml));
curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
$response = curl_exec($session);
fclose($fp);
curl_close($session);