1

I was wondering how I can change the key of an action field through scripting in Zapier. I know I need to use KEY_pre_write to change an element before I send the request but how can I call the specific action field and change the key name in something else?

Zapier scripting image

The key name is currently "type" but I want to change it for instance to "type1".

Thanks in advance.

Leroy Buiter
  • 31
  • 1
  • 6

2 Answers2

1

Fixed it myself btw, maybe for someone who needs to know.

'use strict';

var Zap = {

CompanyAdd_pre_write: function(bundle) {
var actionfields  = bundle.action_fields;
var stringify = JSON.stringify(actionfields);
var body = stringify.replace("type1", "type"); // renaming key
bundle.request.data = body;
console.log(actionfields);
return bundle.request;



}

};
Leroy Buiter
  • 31
  • 1
  • 6
0

David here, from the Zapier Platform team.

key is set by the key of the action itself. See here:

Those would be action_pre_write, broken_js_pre_write, etc. Feel free to tweak these for a private app, but note that it'll break any existing zaps that use that action.

​Let me know if you've got any other questions!

xavdid
  • 5,092
  • 3
  • 20
  • 32
  • Yes, but I need to modify this "key" through Sciprting because the API I'm using has multiple "type" property names. And at the moment your action field "Key" needs to be unique even if the parent key is different. So that's why I need to pre_write this property name (key) before I send the request. I need to use Parent "emails" And "email" + "type" for the child elements. So basically I need to change the "type1" in for instance "type". Do you have a small example how I can change the key "type1" for instance to "type" in scripting? Would help me a lot. Thanks! – Leroy Buiter Dec 13 '18 at 10:03