0

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
BG1983
  • 39
  • 6
  • About `I have no issues with posting to pipedrive via the api with python.`, can you provide the python script? – Tanaike Feb 16 '22 at 01:18
  • I edited my original post to add the python.. sorry I am not sure how to separate these 2 code blocks on my phone. – BG1983 Feb 16 '22 at 14:21
  • Thank you for replying. From your provided python script, I proposed a sample script as an answer. Could you please confirm it? If that was not useful, I apologize. – Tanaike Feb 17 '22 at 00:37

1 Answers1

1

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:

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • Yep, that worked. Not sure if was the 'put' or the extra brackets around field name, but regardless, it worked, appreciate your help! – BG1983 Feb 17 '22 at 14:06
  • @BG1983 Thank you for replying. I'm glad your issue was resolved. I could correctly understand your question with your cooperation. Thank you, too. – Tanaike Feb 18 '22 at 01:10