0
votes

I'm attempting to add the data from action_fields to the bundle.request.url as a querystring. Here is raw bundle data

{
  "auth_fields": {
    "sub_domain": "abc", 
    "apiKey": "1234"
  }, 
  "request": {
    "files": {}, 
    "url": "https://abc.my.workfront.com/attask/api/v7.0/project?&method=post", 
    "headers": {
      "Content-Type": "application/json; charset=utf-8", 
      "Accept": "application/json"
    }, 
    "params": {
      "apiKey": "1234"
    }, 
    "data": "{\"status\": \"PLN\", \"name\": \"Test 2\"}", 
    "method": "POST"
  }, 
  "action_fields": {
    "status": "PLN", 
    "name": "Test 2"
  }, 
  "action_fields_full": {
    "status": "PLN", 
    "name": "Test 2"
  }, 
  "meta": {
    "frontend": false
  }, 
  "action_fields_raw": {
    "status": "PLN", 
    "name": "Test 2"
  }, 
  "url_raw": "https://{{sub_domain}}.my.workfront.com/attask/api/v7.0/project?&method=post", 
  "zap": {}
}

I'm working off of an example Zapier provides and came up with this

'use strict';

var Zap = {
    project_pre_write: function(bundle) {
       // bundle.request.method = "POST";
        console.log(bundle.request.action_fields["status"]);
        bundle.request.url = "http://abc.my.workfront.com/attask/api/v8.0/project?method=post";
        bundle.request.params = $.param(bundle.request.action_fields);
        console.log(bundle.request.params);

        return bundle.request;
    }

};  

But I have this error thrown

TypeError: Cannot read property 'jquery' of undefined:

I'm no Javascript expert (barely even a user) so any thoughts would be appreciated. The end result should look like this

http://abc.my.wrokfront.com/attask/api/v7.0/project?method=post&name=Test%202&status=PLN&apiKey=1234
1

1 Answers

0
votes

Try this:

bundle.request.url += '&' + jQuery.param(bundle.action_fields);