Home > Back-end >  Google sheets appscript - Pipedrive post
Google sheets appscript - Pipedrive post

Time:02-17

I am getting the error 'Exception: Request failed for https://api.pipedrive.com returned code 404. Truncated server response: {"status":false,"error":"Unknown method ."} (use muteHttpExceptions option to examine full response)' when attempting a put/post request to a Pipedrive deal. (Date Field) Below is the function producing the error. I am pretty sure this is something obvious but have not been able to determine the cause on my own. Any help would be appreciated.

function Update_pipedrive_Date(dealid, field_name){
  var todays_date = Utilities.formatDate(new Date(), "GMT-5", "yyyy-MM-dd"); // "yyyy-MM-dd'T'HH:mm:ss'Z'"
  var url = 'https://api.pipedrive.com/v1/deals/'   dealid   '?api_token=' oys_api_key
  var data = {field_name: todays_date};
  var options = {
  'method': 'post',
  'contentType': 'application/json',
  'payload': JSON.stringify(data)
};
var response = UrlFetchApp.fetch(url, options);
  return response
}


def update_field(this_dealid, fieldid):
    tday = now.strftime("%Y-%m-%d")
    headers = {'content-type': 'application/json'}
    updates = {fieldid: tday}
    resp = requests.put(
        'https://api.pipedrive.com/v1/deals/'   str(
            this_dealid)   '?api_token='   api_key,
        data=json.dumps(updates), headers=headers)
    return resp

CodePudding user response:

I believe your goal is as follows.

  • Your provided python script works fine.
  • You want to convert your python script to Google Apps Script.

Modification points:

  • Your python script requests the PUT method. But your Google Apps Script requests the POST method.
  • In the case of {field_name: todays_date}, the key is always "field_name".

When these points are reflected in your script, how about the following modification?

Modified script:

var field_name = "###"; // Please set your field_name.
var dealid = "###"; // Please set your dealid.
var oys_api_key = "###"; // Please set your oys_api_key.

var todays_date = Utilities.formatDate(new Date(), "GMT-5", "yyyy-MM-dd");
var url = 'https://api.pipedrive.com/v1/deals/'   dealid   '?api_token='   oys_api_key;
var data = { [field_name]: todays_date };
var options = {
  'method': 'put',
  'contentType': 'application/json',
  'payload': JSON.stringify(data)
};
var response = UrlFetchApp.fetch(url, options);

Note:

  • I think that the request of this Google Apps Script is the same as your python script. But if this script occurs an error, please confirm your variables of field_name, dealid, oys_api_key again. Even when these variables are the valid values, when an error occurs, I'm worried that the URL might not be able to be accessed from the Google side.

Reference:

  • Related