问题
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 :
- Make a separate "Catch Raw Webhook" in Zapier.
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.
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"]))}
- 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