Zapier - 输入数据排序 [英] Zapier - Input data sorting

查看:26
本文介绍了Zapier - 输入数据排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是发生了什么:

我在我的 Shopify 商店中使用了一个非常酷的插件,它允许您按照一系列步骤自定义您的产品.

I am using a very cool plugin in my Shopify store that allows you to customise your product following a sequence of steps.

举例说明

问题是所有这些信息都没有针对 Zapier 进行排序.本质上它显示如下:

Problem is that all of this information is not sorted for Zapier. Essentially it displays as this:

问题

它们是行项目属性值和行项目属性名称"粘贴后,它们以数组形式出现.

They come as " Line Items Properties Values " and "Line Items Properties Names" and when pasted they come as an array.

我需要做的是将这些名称与其值相匹配.如果可能的话,可以在 Zapier 的 GUI 中进行选择.

What I would need to do is to match those Names with their Values. And if possible be able then to select in the GUI of Zapier.

所以不要使用这些字段和值

So instead of having these fields and values

"Line Properties Names" -> "Project Title","Project Description","Ebook Type"....

"Line Items Properties Values" -> "Sherlock Holmes","A story in London..", "Standard Book"...

具有这些字段和值:

"Project Title" -> "Sherlock Holmes"
"Project Description" -> "A story in London.."
"Ebook Type" -> "Standard Ebook"

有可能吗?

感谢您的时间

更新

为了澄清目的

因此,按此顺序有 3 种不同的产品.以 [] 分隔.产品中的值可能会有所不同,例如,如果客户决定不填写项目详细信息",然后项目详细信息键和值不会显示.基本上导致产品具有不同数量的键和值.

So, in this order there are 3 different products. Separated by []. Values within the product can vary, for instance if a customer decides to not fill the field of " Project Details ", then Project Details Keys and Value wont display. Resulting essentially in products with different amount of keys and values.

这是一个示例:(如您所见,第一个产品与第二个产品的值集不同)

Here is an example: (As you can see the first product has a different set of values as the second product)

输入数据

Input data Values: ["1","ebook1524837342394","Ebook~~//www.shappify-cdn.com/images/282516/127828455/001_Ebook Technical 325x325 (1).png~~ebook","Technical Ebook","Technical 15K - $450.00","All Inclusive Package - $149.00","Cookbook Instant Pot"],["ebook1524837342394"],["Detective Story based in London......","Sherlock Holmes","No Addons","No Package","10000 Words - $270.00","Fiction Book","Ebook~~//www.shappify-cdn.com/images/282516/127828453/001_Ebook Standard 325x325.png~~ebook","ebook1524837304725","1","https://cdn.shopify.com/s/files/1/0012/8814/2906/uploads/7ddee14d6e5d6c5e4396981d1702c375.jpg"]

 Input data Keys: ["_master_builder","_builder_id","_builder_info","Ebook Type","Word Count","Upgrade","Project Title"],["_builder_id"],["Project Details","Project Title","Addons","Upgrade","Word Count","Ebook Type","_builder_info","_builder_id","_master_builder","Upload your file here"]

我想做什么

我想将键与它们的值相匹配,并能够在 Zapier GUI 上选择它们.

I want to match the key with their value and be able to select them on the Zapier GUI.

建议代码的当前输出

输出第一部分

输出第二部分

输出第三部分

输出第 4 部分

预期产出

[{"_master_builder":"1","_builder_id":"ebook1524837342394","_builder_info":"Ebook~~//www.shappify-cdn.com/images/282516/127828455/001_Ebook Technical 325x325 (1).png~~ebook"...}]

感谢您的帮助

推荐答案

啊!所以这比最初看起来要棘手一些,但还不错.有两个陷阱:

Ah! So this is a little trickier than it looked at first, but it's not bad. There are two gotchas:

  • 您的数据以字符串形式输入
  • 该字符串由多个数组对象组成,但本身不是有效的数组对象

所以一旦我们正确解析它,它就不会太糟糕.

So once we parse it out correctly, it's not too bad.

// just used for testing outside zapier
// these are comma separated strings
const inputData = {
  keys: '_master_builder,_builder_id,_builder_info,Ebook Type,Word Count,Upgrade,Project Title,_builder_id,Project Details,Project Title,Addons,Upgrade,Word Count,Ebook Type,_builder_info,_builder_id,_master_builder,Upload your file here',
  values: '1,ebook1524837342394,Ebook~~//www.shappify-cdn.com/images/282516/127828455/001_Ebook Technical 325x325 (1).png~~ebook,Technical Ebook,Technical 15K - $450.00,All Inclusive Package - $149.00,Cookbook Instant Pot,ebook1524837342394,Detective Story based in London......,Sherlock Holmes,No Addons,No Package,10000 Words - $270.00,Fiction Book,Ebook~~//www.shappify-cdn.com/images/282516/127828453/001_Ebook Standard 325x325.png~~ebook,ebook1524837304725,1,https://cdn.shopify.com/s/files/1/0012/8814/2906/uploads/7ddee14d6e5d6c5e4396981d1702c375.jpg'
}

// arrays must be the same length
const zipArrays = (a, b) => {
  let res = {}
  a.forEach((val, i) => {
    res[val] = b[i]
  })
  return res
}

// have to convert strings to actual arrays
// this will blow up if any of the data has commas in it
const keys = inputData.keys.split(',')
const vals = inputData.values.split(',')

// now we have real arrays

const result = {}

// copy keys onto the result, overwriting old ones
Object.assign(result, zipArrays(keys, vals))

console.log(result)
/*
  { _master_builder: '1',
    _builder_id: 'ebook1524837304725',
    _builder_info: 'Ebook~~//www.shappify-cdn.com/images/282516/127828453/001_Ebook Standard 325x325.png~~ebook',
    'Ebook Type': 'Fiction Book',
    'Word Count': '10000 Words - $270.00',
    Upgrade: 'No Package',
    'Project Title': 'Sherlock Holmes',
    'Project Details': 'Detective Story based in London......',
    Addons: 'No Addons',
    'Upload your file here': 'https://cdn.shopify.com/s/files/1/0012/8814/2906/uploads/7ddee14d6e5d6c5e4396981d1702c375.jpg' }
*/

// return result

按原样,有很多重复的键,因此输出小于输入.如果您想对输出进行不同的分组,您还可以调整此代码以更好地匹配您的输入.

As is, there's a lot of repeated keys keys so the output is smaller than the input. You can also tweak this code to match your input better if you want to group the output differently.

希望有帮助!

这篇关于Zapier - 输入数据排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆