Zapier sending Python JSON dict and skipping null values

被刻印的时光 ゝ 提交于 2021-02-10 14:36:42

问题


From Limo anywhere trigger, I am getting the values in my node.js code action. Suppose we are getting following value from the trigger:

null,the four seasons hotel;

Zapier is sending only the four seasons hotel in the code. Is there a way in Zapier to get the rawJSON and parse it in the code?

My code :

    let rows = "";
    const totalRecords = firstNames.length;
    const toLocations = inputData.to_location.split(",");
    const firstNames = inputData.first_name.split(",");
    const lastNames = inputData.last_name.split(",");
    const pickupDates = inputData.pickup_date.split(",");
    const fromLocations = inputData.from_location.split(",");

    for(let i = 0; i < totalRecords; i++){
       rows += `${firstNames[i]} ${lastNames[i]} ${fromLocations[i]} ${toLocations[i]} ${pickupDates[i]}`;
       if(i !== (totalRecords - 1)){
          rows += ",";
       }
    }

    return {
       rows: rows
    };

回答1:


Following is the complex solution of the Above problem :

  1. Make a separate "Catch Raw Webhook" in Zapier.
  2. Use the Webhook URL from #1 above and add it as a webhook action on existing Limo anywhere trigger. This webhook action will send json as post under "raw" parameter. Choose custom request then method will be POST, data pass through will be yes.

  3. Add a code action after webhook trigger to parse the Python Dictionary string in Zapier :

import json, ast
output = {'res': json.dumps(ast.literal_eval(input_data["raw"]))}
  1. This will now give you proper JSON compatible with Javascript and from here on you can deal with the data.

I had to use python in #3 because raw JSON was only compatible with Python and it looked like following :

{u'due_date': u'2019-03-22T00:00:00', u'terms': u'due_upon_receipt'}


来源:https://stackoverflow.com/questions/55469998/zapier-sending-python-json-dict-and-skipping-null-values

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!