For Zoho Services only:


I'm actually part of a bigger team at Ascent Business Solutions where we have support technicians and project consultants. Support is for smaller technical fixes but this can include developments, reports or integrations; depending on the size of the task. Projects are for more time-consuming developments such as revamps of the Zoho Suite of apps or on-site training. The advantage of a team is that if I am out-of-office for a day or so, there is always someone at Ascent Business Solutions who can deal with any queries/issues you may have.

Our support rates can be found and purchased at http://ascentbusiness.co.uk/zoho-support-2. A support bundle doesn't have an expiry date. So whether we can do what you want within the bundle and a year later need further support, if there are minutes left on the bundle then there is no additional charge.

Our project rates for bigger developments can be found at http://ascentbusiness.co.uk/crm-solutions/zoho-crm-packages-prices and will involve a dedicated project consultant along with developers who will hold your hand through the development process.

If you want help building a solution for one of the Zoho Apps in the Zoho Suite, contact us on 0121 293 8140 (UK) or by email at info@ascentbusiness.co.uk. You can also visit our website at http://ascentbusiness.co.uk.

I regularly build and specialize in 2-way API integrations for Xero, Shopify and eBay.

Zoho Creator: Public URL of an Image field / Upload to Shopify API

What?
This is an article to document how I downloaded an image held in a Zoho Creator form, and sent it to an API wanting the publicly accessible link or URL of the image.

Why?
I've got some other articles on handling images in Zoho Creator (see "Sources" below), the most relevant one being my article Zoho Deluge: Get Image Uploaded in Creator Form which has one method of getting a public link.

My use-case scenario here is that while I could upload the link from Creator to eBay's Picture Services successfully, Shopify would not accept any links I gave it. Why not use the links that eBay returns? Well eBay returns URLs to images that have been resized to 400x400 (even with tweak to return 800x800). I wanted a way to upload my image directly to Shopify in 3024x3024 resolution (or the size that the client wants: iPhone res). I then found that Shopify does accept a Base64Encoded version of the image and the below is how I achieved this.

How?
First-off, let me list the various formats that Zoho Creator says that public link exists. Let's say I have a field called Main_Photo and this is in a form called Portal_Listing with a report/view called Portal_Listing_Report and I have a publish key held in v_ListingPublishKey and lastly, my datacenter is .COM:

URL Syntax #1
copyraw
// works in eBay
v_ImageSrc = "https://creator.zoho.com/file" + zoho.appuri + "Portal_Listing_Report/" + input.ID + "/Main_Photo/image-download/" + v_ListingPublishKey + "?filepath=/" + v_Filename;
  1.  // works in eBay 
  2.  v_ImageSrc = "https://creator.zoho.com/file" + zoho.appuri + "Portal_Listing_Report/" + input.ID + "/Main_Photo/image-download/" + v_ListingPublishKey + "?filepath=/" + v_Filename; 

URL Syntax #2
copyraw
// works in eBay
v_ImageSrc = "https://creator.zohopublic.com" + zoho.appuri + "Portal_Listing_Report/" + input.ID + "/Main_Photo/image-download/" + v_ListingPublishKey + "/" + v_Filename;
  1.  // works in eBay 
  2.  v_ImageSrc = "https://creator.zohopublic.com" + zoho.appuri + "Portal_Listing_Report/" + input.ID + "/Main_Photo/image-download/" + v_ListingPublishKey + "/" + v_Filename; 

URL Syntax #3
copyraw
// Works in eBay
v_ImageSrc = "https://creatorexport.zoho.com" + zoho.appuri + "Portal_Listing_Report/" + input.ID + "/Main_Photo/image-download/" + v_ListingPublishKey + "/" + v_Filename;
  1.  // Works in eBay 
  2.  v_ImageSrc = "https://creatorexport.zoho.com" + zoho.appuri + "Portal_Listing_Report/" + input.ID + "/Main_Photo/image-download/" + v_ListingPublishKey + "/" + v_Filename; 

URL Syntax #4
The following obviously doesn't work as it doesn't have the publish/public key:
copyraw
// DOESN'T WORK FOR ME!!!
v_ImageSrc = "https://creatorexport.zoho.com/DownloadFile.do?filepath=/"+v_Filename+"&sharedBy="+zoho.adminuser+"&appLinkName="+zoho.appname+"&viewLinkName=Portal_Listing_Report";
  1.  // DOESN'T WORK FOR ME!!! 
  2.  v_ImageSrc = "https://creatorexport.zoho.com/DownloadFile.do?filepath=/"+v_Filename+"&sharedBy="+zoho.adminuser+"&appLinkName="+zoho.appname+"&viewLinkName=Portal_Listing_Report"

The API Solution
The following solution requires that your target API accepts base64encoded images or that you can send these in a cURL request (same thing really):
copyraw
string API.fn_ShopifyQuery_UploadPhoto(int p_Position, int p_ProductID)
{
	v_Output = "";
	m_Header = Map();
	m_Header.put("Content-Type","application/json");
	// 
	// your shopify details 
	v_ClientID = "<YOUR_CLIENT_ID>"; 
	v_ClientSecret = "<YOUR_CLIENT_SECRET>"; 
	v_ShopID = "example.myshopify.com"; 
	v_ShopifyURL = "https://" + v_ClientID + ":" + v_ClientSecret + "@" + v_ShopID; 
	v_ShopifyApiVersion = "2020-01"; 
	//
	// your creator details
	v_ListingPublishKey = "AAAAABBBBBCCCCDDDDEEEFFFGGGGHHHIIIJJJKKLLLMMMNNOOOPPPQQWRRRSSTTUUVVWWXXYYZZ122345567890"; 
	v_Position = ifnull(p_Position, 1);
	v_ShopifyProductID = ifnull(p_ProductID, 123456789012);
	r_PortalListing = Portal_Listing[Shopify_Product_ID == v_ShopifyProductID];
	if(r_PortalListing.count()>0)
	{
		v_Filename = r_PortalListing.Main_Photo.getSuffix("/image/").getPrefix("\"");
		v_ImageSrc = "https://creator.zoho.com/file" + zoho.appuri + "Portal_Listing_Report/";
		v_ImageSrc = v_ImageSrc + r_PortalListing.ID + "/Main_Photo/image-download/" + v_ListingPublishKey;
		v_ImageSrc = v_ImageSrc + "?filepath=/" + v_Filename;
		r_DownloadPhoto = invokeUrl
        [
        	url: v_ImageSrc
        	type: GET
        ];
		r_DownloadPhoto.setParamName("file");
		v_EncodedImg = zoho.encryption.base64Encode(r_DownloadPhoto);
		m_Params = Map();
		m_SubParams = Map();
		m_SubParams.put("position", 1);
		m_SubParams.put("attachment", v_EncodedImg);
		m_SubParams.put("filename", v_Filename);
		m_Params.put("image", m_SubParams);
		//
		v_Endpoint = v_ShopifyURL + "/admin/api/" + v_ShopifyApiVersion.toString() + "/products/" + v_ShopifyProductID + "/images.json";
		r_UploadPhoto = invokeurl
		[
			url :v_Endpoint
			type :POST
			headers:m_Header
			parameters: m_Params.toString()
		];	
		v_Output = r_UploadPhoto;
		
	}
	return v_Output;
}
  1.  string API.fn_ShopifyQuery_UploadPhoto(int p_Position, int p_ProductID) 
  2.  { 
  3.      v_Output = ""
  4.      m_Header = Map()
  5.      m_Header.put("Content-Type","application/json")
  6.      // 
  7.      // your shopify details 
  8.      v_ClientID = "<YOUR_CLIENT_ID>"
  9.      v_ClientSecret = "<YOUR_CLIENT_SECRET>"
  10.      v_ShopID = "example.myshopify.com"
  11.      v_ShopifyURL = "https://" + v_ClientID + ":" + v_ClientSecret + "@" + v_ShopID; 
  12.      v_ShopifyApiVersion = "2020-01"
  13.      // 
  14.      // your creator details 
  15.      v_ListingPublishKey = "AAAAABBBBBCCCCDDDDEEEFFFGGGGHHHIIIJJJKKLLLMMMNNOOOPPPQQWRRRSSTTUUVVWWXXYYZZ122345567890"
  16.      v_Position = ifnull(p_Position, 1)
  17.      v_ShopifyProductID = ifnull(p_ProductID, 123456789012)
  18.      r_PortalListing = Portal_Listing[Shopify_Product_ID == v_ShopifyProductID]
  19.      if(r_PortalListing.count()>0) 
  20.      { 
  21.          v_Filename = r_PortalListing.Main_Photo.getSuffix("/image/").getPrefix("\"")
  22.          v_ImageSrc = "https://creator.zoho.com/file" + zoho.appuri + "Portal_Listing_Report/"
  23.          v_ImageSrc = v_ImageSrc + r_PortalListing.ID + "/Main_Photo/image-download/" + v_ListingPublishKey; 
  24.          v_ImageSrc = v_ImageSrc + "?filepath=/" + v_Filename; 
  25.          r_DownloadPhoto = invokeUrl 
  26.          [ 
  27.              url: v_ImageSrc 
  28.              type: GET 
  29.          ]
  30.          r_DownloadPhoto.setParamName("file")
  31.          v_EncodedImg = zoho.encryption.base64Encode(r_DownloadPhoto)
  32.          m_Params = Map()
  33.          m_SubParams = Map()
  34.          m_SubParams.put("position", 1)
  35.          m_SubParams.put("attachment", v_EncodedImg)
  36.          m_SubParams.put("filename", v_Filename)
  37.          m_Params.put("image", m_SubParams)
  38.          // 
  39.          v_Endpoint = v_ShopifyURL + "/admin/api/" + v_ShopifyApiVersion.toString() + "/products/" + v_ShopifyProductID + "/images.json"
  40.          r_UploadPhoto = invokeUrl 
  41.          [ 
  42.              url :v_Endpoint 
  43.              type :POST 
  44.              headers:m_Header 
  45.              parameters: m_Params.toString() 
  46.          ]
  47.          v_Output = r_UploadPhoto; 
  48.   
  49.      } 
  50.      return v_Output; 
  51.  } 
Sends something like the following request (sent using Zoho Deluge but the cURL breakdown as follows):
copyraw
curl -d '{"image":{"position":1,"attachment":"/9/R0lGODlhbgCMAPf ... ... ... Q7PCAAOw==\n","filename":"my_test_photo.jpg"}}'
-X POST "https://your-development-store.myshopify.com/admin/api/2021-10/products/9876543210987/images.json" \
-H "X-Shopify-Access-Token: {access_token}"
  1.  curl -d '{"image":{"position":1,"attachment":"/9/R0lGODlhbgCMAPf ... ... ... Q7PCAAOw==\n","filename":"my_test_photo.jpg"}}' 
  2.  -X POST "https://your-development-store.myshopify.com/admin/api/2021-10/products/9876543210987/images.json" \ 
  3.  -H "X-Shopify-Access-Token: {access_token}" 
Yields something like the following response:
copyraw
{
  "image": {
    "position": 1,
    "width": 3024,
    "height": 3024,
    "alt": null,
    "id": 12345678901234,
    "product_id": 9876543210987,
    "created_at": "2021-10-17T21:45:56+01:00",
    "updated_at": "2021-10-17T21:45:56+01:00",
    "src": "https://cdn.shopify.com/s/files/1/2345/6789/1234/products/aaaabbbbccccddddeeeeffff11112222.jpg?v=1234567890",
    "variant_ids": [],
    "admin_graphql_api_id": "gid://shopify/ProductImage/23456789012345"
  }
}
  1.  { 
  2.    "image": { 
  3.      "position": 1, 
  4.      "width": 3024, 
  5.      "height": 3024, 
  6.      "alt": null, 
  7.      "id": 12345678901234, 
  8.      "product_id": 9876543210987, 
  9.      "created_at": "2021-10-17T21:45:56+01:00", 
  10.      "updated_at": "2021-10-17T21:45:56+01:00", 
  11.      "src": "https://cdn.shopify.com/s/files/1/2345/6789/1234/products/aaaabbbbccccddddeeeeffff11112222.jpg?v=1234567890", 
  12.      "variant_ids": [], 
  13.      "admin_graphql_api_id": "gid://shopify/ProductImage/23456789012345" 
  14.    } 
  15.  } 

This next version is a more generic form of the above function uploading the photo to Shopify:
copyraw
void API.fn_ShopifyQuery_UploadPhoto(int p_ProductID, int p_Position, string p_ImageSrc)
{
	m_Header = Map();
	m_Header.put("Content-Type","application/json");
	//
	// app specific
	v_ClientID = "<YOUR_CLIENT_ID>"; 
	v_ClientSecret = "<YOUR_CLIENT_SECRET>"; 
	v_ShopID = "example.myshopify.com"; 
	v_ShopifyURL = "https://" + v_ClientID + ":" + v_ClientSecret + "@" + v_ShopID; 
	v_ShopifyApiVersion = "2020-01"; 
	//
	// your creator details
	v_Position = ifnull(p_Position,1);
	v_ShopifyProductID = ifnull(p_ProductID,0);
	v_ImageSrc = ifnull(p_ImageSrc,"");
	if(v_ImageSrc != "" && v_ShopifyProductID != 0)
	{
		r_DownloadPhoto = invokeurl
		[
			url :v_ImageSrc
			type :GET
		];
		r_DownloadPhoto.setParamName("file");
		v_EncodedImg = zoho.encryption.base64Encode(r_DownloadPhoto);
		//
		// build shopify request
		m_Params = Map();
		m_SubParams = Map();
		m_SubParams.put("position",v_Position);
		m_SubParams.put("attachment",v_EncodedImg);
		m_Params.put("image",m_SubParams);
		//
		v_Endpoint = v_ShopifyURL + "/admin/api/" + v_ShopifyApiVersion.toString() + "/products/" + v_ShopifyProductID + "/images.json";
		r_UploadPhoto = invokeurl
		[
			url :v_Endpoint
			type :POST
			parameters:m_Params.toString()
			headers:m_Header
		];
	}
}
  1.  void API.fn_ShopifyQuery_UploadPhoto(int p_ProductID, int p_Position, string p_ImageSrc) 
  2.  { 
  3.      m_Header = Map()
  4.      m_Header.put("Content-Type","application/json")
  5.      // 
  6.      // app specific 
  7.      v_ClientID = "<YOUR_CLIENT_ID>"
  8.      v_ClientSecret = "<YOUR_CLIENT_SECRET>"
  9.      v_ShopID = "example.myshopify.com"
  10.      v_ShopifyURL = "https://" + v_ClientID + ":" + v_ClientSecret + "@" + v_ShopID; 
  11.      v_ShopifyApiVersion = "2020-01"
  12.      // 
  13.      // your creator details 
  14.      v_Position = ifnull(p_Position,1)
  15.      v_ShopifyProductID = ifnull(p_ProductID,0)
  16.      v_ImageSrc = ifnull(p_ImageSrc,"")
  17.      if(v_ImageSrc != "" && v_ShopifyProductID != 0) 
  18.      { 
  19.          r_DownloadPhoto = invokeUrl 
  20.          [ 
  21.              url :v_ImageSrc 
  22.              type :GET 
  23.          ]
  24.          r_DownloadPhoto.setParamName("file")
  25.          v_EncodedImg = zoho.encryption.base64Encode(r_DownloadPhoto)
  26.          // 
  27.          // build shopify request 
  28.          m_Params = Map()
  29.          m_SubParams = Map()
  30.          m_SubParams.put("position",v_Position)
  31.          m_SubParams.put("attachment",v_EncodedImg)
  32.          m_Params.put("image",m_SubParams)
  33.          // 
  34.          v_Endpoint = v_ShopifyURL + "/admin/api/" + v_ShopifyApiVersion.toString() + "/products/" + v_ShopifyProductID + "/images.json"
  35.          r_UploadPhoto = invokeUrl 
  36.          [ 
  37.              url :v_Endpoint 
  38.              type :POST 
  39.              parameters:m_Params.toString() 
  40.              headers:m_Header 
  41.          ]
  42.      } 
  43.  } 
And it's usage:
copyraw
// somewhere in the beginning
l_ShopifyPictures = List();
v_ListingPublishKey = "AAAAABBBBBCCCCDDDDEEEFFFGGGGHHHIIIJJJKKLLLMMMNNOOOPPPQQWRRRSSTTUUVVWWXXYYZZ122345567890";
if(!isnull(input.Main_Photo))
{
	v_Filename = input.Main_Photo.getSuffix("/image/").getPrefix("\"");
	v_ImageSrc = "https://creator.zoho.com/file" + zoho.appuri + "Portal_Listing_Report/";
	v_ImageSrc = v_ImageSrc + input.ID + "/Main_Photo/image-download/" + v_ListingPublishKey;
	v_ImageSrc = v_ImageSrc + "?filepath=/" + v_Filename;
	l_ShopifyPictures.add(v_ImageSrc);
}
// after I've pushed the product to Shopify and it returned to me a Product ID:
if(v_ShopifyProductID != 0)
{
	// do photos
	if(input.Photos_Changed)
	{
		v_PositionIndex = 1;
		for each  v_ShopifyImageSrc in l_ShopifyPictures
		{
			if(v_ShopifyImageSrc!="")
			{
				thisapp.API.fn_ShopifyQuery_UploadPhoto(v_ShopifyProductID, v_PositionIndex, v_ShopifyImageSrc);
			}
			v_PositionIndex = v_PositionIndex + 1;
		}		
		info "Re-uploaded Photos to Shopify";
	}
}
  1.  // somewhere in the beginning 
  2.  l_ShopifyPictures = List()
  3.  v_ListingPublishKey = "AAAAABBBBBCCCCDDDDEEEFFFGGGGHHHIIIJJJKKLLLMMMNNOOOPPPQQWRRRSSTTUUVVWWXXYYZZ122345567890"
  4.  if(!isnull(input.Main_Photo)) 
  5.  { 
  6.      v_Filename = input.Main_Photo.getSuffix("/image/").getPrefix("\"")
  7.      v_ImageSrc = "https://creator.zoho.com/file" + zoho.appuri + "Portal_Listing_Report/"
  8.      v_ImageSrc = v_ImageSrc + input.ID + "/Main_Photo/image-download/" + v_ListingPublishKey; 
  9.      v_ImageSrc = v_ImageSrc + "?filepath=/" + v_Filename; 
  10.      l_ShopifyPictures.add(v_ImageSrc)
  11.  } 
  12.  // after I've pushed the product to Shopify and it returned to me a Product ID: 
  13.  if(v_ShopifyProductID != 0) 
  14.  { 
  15.      // do photos 
  16.      if(input.Photos_Changed) 
  17.      { 
  18.          v_PositionIndex = 1
  19.          for each  v_ShopifyImageSrc in l_ShopifyPictures 
  20.          { 
  21.              if(v_ShopifyImageSrc!="") 
  22.              { 
  23.                  thisapp.API.fn_ShopifyQuery_UploadPhoto(v_ShopifyProductID, v_PositionIndex, v_ShopifyImageSrc)
  24.              } 
  25.              v_PositionIndex = v_PositionIndex + 1
  26.          } 
  27.          info "Re-uploaded Photos to Shopify"
  28.      } 
  29.  } 

Correction / Additional
The above solution means that for every photo uploaded, an API call is used up. If you have low limits, even 2000, this means you can only upload 100 products a day if they each have 20 photos (even less products then that as the upload of a product costs 1 API call). But I have found you can submit all photos in one go as well:
copyraw
// build up list of photos from Creator fields
l_CreatorPhotos = List();
v_ListingPublishKey = "AAAAABBBBBCCCCDDDDEEEFFFGGGGHHHIIIJJJKKLLLMMMNNOOOPPPQQWRRRSSTTUUVVWWXXYYZZ122345567890";
if(!isnull(input.Main_Photo))
{
	v_Filename = input.Main_Photo.getSuffix("/image/").getPrefix("\"");
	v_ImageSrc = "https://creator.zoho.com/file" + zoho.appuri + "Portal_Listing_Report/";
	v_ImageSrc = v_ImageSrc + input.ID + "/Main_Photo/image-download/" + v_ListingPublishKey;
	v_ImageSrc = v_ImageSrc + "?filepath=/" + v_Filename;
	l_CreatorPhotos.add(v_ImageSrc);
}
//
// then upload
l_ShopifyUploadImages = List();
v_PositionIndex = 0;
for each  v_CreatorImageSrc in l_CreatorPhotos
{
    if(v_CreatorImageSrc != "")
    {
        v_PositionIndex = v_PositionIndex + 1;
        r_DownloadPhoto = invokeurl
        [
            url : v_CreatorImageSrc
            type : GET
        ];
        r_DownloadPhoto.setParamName("file");
        v_EncodedImg = zoho.encryption.base64Encode(r_DownloadPhoto);
        //
        // build shopify request
        m_Image = Map();
        m_SubParams = Map();
        m_SubParams.put("position",v_PositionIndex);
        m_SubParams.put("attachment",v_EncodedImg);
        m_Image.put("image",m_SubParams);
        l_ShopifyUploadImages.add(m_Image);
    }
}
//
v_Endpoint = v_ShopifyURL + "/admin/api/" + v_ShopifyAPIVersion + "/products/" + v_ShopifyProductID + "/images.json";
r_UploadPhoto = invokeurl
[
    url : v_Endpoint
    type : POST
    parameters: l_ShopifyUploadImages.toString()
    headers: m_Header
];
  1.  // build up list of photos from Creator fields 
  2.  l_CreatorPhotos = List()
  3.  v_ListingPublishKey = "AAAAABBBBBCCCCDDDDEEEFFFGGGGHHHIIIJJJKKLLLMMMNNOOOPPPQQWRRRSSTTUUVVWWXXYYZZ122345567890"
  4.  if(!isnull(input.Main_Photo)) 
  5.  { 
  6.      v_Filename = input.Main_Photo.getSuffix("/image/").getPrefix("\"")
  7.      v_ImageSrc = "https://creator.zoho.com/file" + zoho.appuri + "Portal_Listing_Report/"
  8.      v_ImageSrc = v_ImageSrc + input.ID + "/Main_Photo/image-download/" + v_ListingPublishKey; 
  9.      v_ImageSrc = v_ImageSrc + "?filepath=/" + v_Filename; 
  10.      l_CreatorPhotos.add(v_ImageSrc)
  11.  } 
  12.  // 
  13.  // then upload 
  14.  l_ShopifyUploadImages = List()
  15.  v_PositionIndex = 0
  16.  for each  v_CreatorImageSrc in l_CreatorPhotos 
  17.  { 
  18.      if(v_CreatorImageSrc != "") 
  19.      { 
  20.          v_PositionIndex = v_PositionIndex + 1
  21.          r_DownloadPhoto = invokeUrl 
  22.          [ 
  23.              url : v_CreatorImageSrc 
  24.              type : GET 
  25.          ]
  26.          r_DownloadPhoto.setParamName("file")
  27.          v_EncodedImg = zoho.encryption.base64Encode(r_DownloadPhoto)
  28.          // 
  29.          // build shopify request 
  30.          m_Image = Map()
  31.          m_SubParams = Map()
  32.          m_SubParams.put("position",v_PositionIndex)
  33.          m_SubParams.put("attachment",v_EncodedImg)
  34.          m_Image.put("image",m_SubParams)
  35.          l_ShopifyUploadImages.add(m_Image)
  36.      } 
  37.  } 
  38.  // 
  39.  v_Endpoint = v_ShopifyURL + "/admin/api/" + v_ShopifyAPIVersion + "/products/" + v_ShopifyProductID + "/images.json"
  40.  r_UploadPhoto = invokeUrl 
  41.  [ 
  42.      url : v_Endpoint 
  43.      type : POST 
  44.      parameters: l_ShopifyUploadImages.toString() 
  45.      headers: m_Header 
  46.  ]

Correction / Additional version 2.0
Playing around with this for a client, I found an even better solution! When creating or updating a product, you can instead of giving it Image URLs, give it the Image as attachment a base64 encoded string. Note the above says that 10 photos produced 10 webhooks but actually I'd overlooked the webhook used to invokeUrl download a Creator file so it was using 20 webhooks; the following reduces that back down to 10 webhooks (1 to download each photo and base64 encode it but no extras to upload it in addition to the product update):
copyraw
// initialize
m_Product = Map();
b_CreateProduct = true;  
//
// I have a field called Shopify Product ID which stores the... um... shopify product id...
if(!isNull(input.Shopify_Product_ID))
{
    m_Product.put("id",input.Shopify_Product_ID);
    b_CreateProduct = false;
}
//
// title and HTML
m_Product.put("title",input.Listing_Title);
if(!isNull(input.Full_Shopify_HTML_Code))
{
    m_Product.put("body_html",input.Full_Shopify_HTML_Code);
}
m_Product.put("vendor",input.Brand);
m_Product.put("product_type",input.Item_Type);
//
// listings / channels
m_Product.put("published_scope","global");
m_Product.put("published",true);  // set to true when comfortable with it publishing correctly
m_Product.put("status",ifnull(input.Publish_Status.toLowerCase(),"draft"));
//
// build up variant list under this product
l_Variants = List();
m_Variant = Map();
m_Variant.put("weight",0.0);
m_Variant.put("title",input.Listing_Title);
m_Variant.put("sku",input.Product_SKU);
m_Variant.put("price",input.Shopify_Unit_Sell_Price);
m_Variant.put("taxable",input.Taxable);
m_Variant.put("inventory_quantity",input.Quantity.round(0));  // deprecated // use inventory_levels
m_Variant.put("inventory_policy","deny");
m_Variant.put("inventory_management","shopify");
m_Variant.put("inventoryItem",{"cost":ifnull(input.Shopify_Unit_Cost_Price,0).toDecimal().round(2).toString()}); // not working // use inventory_items
l_Variants.add(m_Variant);
m_Product.put("variants",l_Variants);
//
// do photos
if(input.Photos_Changed)
{
    l_AllImages = List();
    v_PositionIndex = 0;
    for each  v_ShopifyImageSrc in l_ShopifyPictures
    {
        if(v_ShopifyImageSrc != "")
        {
            v_PositionIndex = v_PositionIndex + 1;
            r_DownloadPhoto = invokeurl
            [
                url :v_ShopifyImageSrc
                type :GET
            ];
            r_DownloadPhoto.setParamName("file");
            v_EncodedImg = zoho.encryption.base64Encode(r_DownloadPhoto);
            //
            // build photos request
            m_Image = Map();
            m_Image.put("position",v_PositionIndex);
            m_Image.put("attachment",v_EncodedImg);
            l_AllImages.add(m_Image);
        }
    }
    m_Product.put("images",l_AllImages);
}
//
// shopify tags
l_Tags = input.Tags;
m_Product.put("tags",l_Tags);
//
// JSON product request
m_CreateRecord = Map();
m_CreateRecord.put("product",m_Product);
//
// send request to Shopify API
r_ShopifyConfig = API_Integration[Connection_Name == "Shopify API"];
if(r_ShopifyConfig.count() > 0)
{
    v_ShopifyAPIVersion = r_ShopifyConfig.API_Version.toString();
    v_ShopifyURL = "https://" + r_ShopifyConfig.Client_ID + ":" + r_ShopifyConfig.Client_Secret + "@" + r_ShopifyConfig.Shop_ID;
    //
    // if creating the product
    if(b_CreateProduct)
    {
        v_Endpoint = v_ShopifyURL + "/admin/api/" + r_ShopifyConfig.API_Version + "/products.json";
        r_NewProduct = invokeurl
        [
            url :v_Endpoint
            type :POST
            parameters:m_CreateRecord.toString()
            headers:m_Header
        ];
        r_Response = r_NewProduct.toMap();
        if(!isnull(r_Response.get("product").get("id")))
        {
            v_ShopifyProductID = r_Response.get("product").get("id").toLong();
            v_ShopifyHandle = r_Response.get("product").get("handle");
            // here I'm just getting the first variant in the list under this product
            v_ShopifyInventoryID = r_Response.get("product").get("variants").get(0).get("inventory_item_id").toLong();
            v_ShopifyVariantID = r_Response.get("product").get("variants").get(0).get("id").toLong();
        }
    }
}
  1.  // initialize 
  2.  m_Product = Map()
  3.  b_CreateProduct = true
  4.  // 
  5.  // I have a field called Shopify Product ID which stores the... um... shopify product id... 
  6.  if(!isNull(input.Shopify_Product_ID)) 
  7.  { 
  8.      m_Product.put("id",input.Shopify_Product_ID)
  9.      b_CreateProduct = false
  10.  } 
  11.  // 
  12.  // title and HTML 
  13.  m_Product.put("title",input.Listing_Title)
  14.  if(!isNull(input.Full_Shopify_HTML_Code)) 
  15.  { 
  16.      m_Product.put("body_html",input.Full_Shopify_HTML_Code)
  17.  } 
  18.  m_Product.put("vendor",input.Brand)
  19.  m_Product.put("product_type",input.Item_Type)
  20.  // 
  21.  // listings / channels 
  22.  m_Product.put("published_scope","global")
  23.  m_Product.put("published",true);  // set to true when comfortable with it publishing correctly 
  24.  m_Product.put("status",ifnull(input.Publish_Status.toLowerCase(),"draft"))
  25.  // 
  26.  // build up variant list under this product 
  27.  l_Variants = List()
  28.  m_Variant = Map()
  29.  m_Variant.put("weight",0.0)
  30.  m_Variant.put("title",input.Listing_Title)
  31.  m_Variant.put("sku",input.Product_SKU)
  32.  m_Variant.put("price",input.Shopify_Unit_Sell_Price)
  33.  m_Variant.put("taxable",input.Taxable)
  34.  m_Variant.put("inventory_quantity",input.Quantity.round(0));  // deprecated // use inventory_levels 
  35.  m_Variant.put("inventory_policy","deny")
  36.  m_Variant.put("inventory_management","shopify")
  37.  m_Variant.put("inventoryItem",{"cost":ifnull(input.Shopify_Unit_Cost_Price,0).toDecimal().round(2).toString()})// not working // use inventory_items 
  38.  l_Variants.add(m_Variant)
  39.  m_Product.put("variants",l_Variants)
  40.  // 
  41.  // do photos 
  42.  if(input.Photos_Changed) 
  43.  { 
  44.      l_AllImages = List()
  45.      v_PositionIndex = 0
  46.      for each  v_ShopifyImageSrc in l_ShopifyPictures 
  47.      { 
  48.          if(v_ShopifyImageSrc != "") 
  49.          { 
  50.              v_PositionIndex = v_PositionIndex + 1
  51.              r_DownloadPhoto = invokeUrl 
  52.              [ 
  53.                  url :v_ShopifyImageSrc 
  54.                  type :GET 
  55.              ]
  56.              r_DownloadPhoto.setParamName("file")
  57.              v_EncodedImg = zoho.encryption.base64Encode(r_DownloadPhoto)
  58.              // 
  59.              // build photos request 
  60.              m_Image = Map()
  61.              m_Image.put("position",v_PositionIndex)
  62.              m_Image.put("attachment",v_EncodedImg)
  63.              l_AllImages.add(m_Image)
  64.          } 
  65.      } 
  66.      m_Product.put("images",l_AllImages)
  67.  } 
  68.  // 
  69.  // shopify tags 
  70.  l_Tags = input.Tags; 
  71.  m_Product.put("tags",l_Tags)
  72.  // 
  73.  // JSON product request 
  74.  m_CreateRecord = Map()
  75.  m_CreateRecord.put("product",m_Product)
  76.  // 
  77.  // send request to Shopify API 
  78.  r_ShopifyConfig = API_Integration[Connection_Name == "Shopify API"]
  79.  if(r_ShopifyConfig.count() > 0) 
  80.  { 
  81.      v_ShopifyAPIVersion = r_ShopifyConfig.API_Version.toString()
  82.      v_ShopifyURL = "https://" + r_ShopifyConfig.Client_ID + ":" + r_ShopifyConfig.Client_Secret + "@" + r_ShopifyConfig.Shop_ID; 
  83.      // 
  84.      // if creating the product 
  85.      if(b_CreateProduct) 
  86.      { 
  87.          v_Endpoint = v_ShopifyURL + "/admin/api/" + r_ShopifyConfig.API_Version + "/products.json"
  88.          r_NewProduct = invokeUrl 
  89.          [ 
  90.              url :v_Endpoint 
  91.              type :POST 
  92.              parameters:m_CreateRecord.toString() 
  93.              headers:m_Header 
  94.          ]
  95.          r_Response = r_NewProduct.toMap()
  96.          if(!isnull(r_Response.get("product").get("id"))) 
  97.          { 
  98.              v_ShopifyProductID = r_Response.get("product").get("id").toLong()
  99.              v_ShopifyHandle = r_Response.get("product").get("handle")
  100.              // here I'm just getting the first variant in the list under this product 
  101.              v_ShopifyInventoryID = r_Response.get("product").get("variants").get(0).get("inventory_item_id").toLong()
  102.              v_ShopifyVariantID = r_Response.get("product").get("variants").get(0).get("id").toLong()
  103.          } 
  104.      } 
  105.  } 

Source(s)
Category: Zoho :: Article: 779

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: The information on this website is provided without warranty and any content is merely the opinion of the author. Please try to test in development environments prior to adapting them to your production environments. The articles are written in good faith and, at the time of print, are working examples used in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com

Related Articles

Joes Revolver Map

Accreditation

Badge - Certified Zoho Creator Associate
Badge - Certified Zoho Creator Associate

Donate & Support

If you like my content, and would like to support this sharing site, feel free to donate using a method below:

Paypal:
Donate to Joel Lipman via PayPal

Bitcoin:
Donate to Joel Lipman with Bitcoin - Valid till 8 May 2022 3QnhmaBX7LQSRsC9hh6Je9rGQKEGNQNfPb
© 2021 Joel Lipman .com. All Rights Reserved.