Quantcast
Channel: Opinion: Shopify Community - Shopify APIs & SDKs
Viewing all articles
Browse latest Browse all 25503

Super Discount Daily commented on Overwrite product in XML API

$
0
0

Hello,

Thanks for the quick turnaround! Yes, I will be moving to json as well, but we just needed to start getting the products in as much as we could.

So, currently using XML, and I am using CURL (code given below) - we cannot overwrite it, even if product with the same handle already exists? Is that correct? Or, is there a way to overwrite in XML?

By the way, all this is being done for bulk uploads / updates, so the only way to automate this (even in json) would be to overwrite if the 'handle' is the same. I cannot use overwrite based on ID, because while creating products - I will not know what the ID is. The only information I have is the handle, and ideally - while creating the product what I want to do is - if handle exists then overwrite, if new handle then create. (similar functionality to the manual csv import function)

What is the best way to go about this? (for now - in xml, but certainly in json as well?)

Thanks again!

------------------------

$xmlsrc = <<<XML
<?xml version='1.0' encoding='UTF-8'?>
<product>
    <title>$str_title</title>
    <handle>$str_title</handle>
    <body-html>$str_body</body-html>
    <product-type>$str_prod_type</product-type>
    <tags>$str_tags</tags>
    <published>TRUE</published>
    <variants type="array">
        <variant>
            <price>$str_variant_price</price>
            <sku>$str_variant_sku</sku>
            <inventory-quantity>$str_variant_inv_qty</inventory-quantity>
            <inventory-management>shopify</inventory-management>
            <inventory-policy>deny</inventory-policy>
        </variant>
    </variants>
    <vendor>$str_vendor</vendor>
    <images type="array">
        <image>
            <src>$str_image_src</src>
            <metafields type="array">
                <metafield>
                    <key>alt</key>
                    <value>$str_title</value>
                    <value-type>string</value-type>
                    <namespace>tags</namespace>
            </metafield>
        </metafields>
    </image>
    </images>
</product>
XML;

        $session = curl_init();
        curl_setopt($session, CURLOPT_URL, $url);
    curl_setopt($session, CURLOPT_POST, 1);
    curl_setopt($session, CURLOPT_POSTFIELDS, $xmlsrc);
    curl_setopt($session, CURLOPT_HEADER, false);
    curl_setopt($session, CURLOPT_HTTPHEADER, array('Accept: application/xml', 'Content-Type: application/xml'));
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

    if(ereg("^(https)",$url)) curl_setopt($session,CURLOPT_SSL_VERIFYPEER,false);

    $result = curl_exec($session);

        curl_close($session);

        echo $result; // this shows exactly what you'd expect to see, as given in API documentation  


------------------------

 


Viewing all articles
Browse latest Browse all 25503

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>