Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script Http POST从API返回404_Google Apps Script_Google Sheets_Http Status Code 404_Urlfetch - Fatal编程技术网

Google apps script Http POST从API返回404

Google apps script Http POST从API返回404,google-apps-script,google-sheets,http-status-code-404,urlfetch,Google Apps Script,Google Sheets,Http Status Code 404,Urlfetch,我正在尝试创建一个GoogleAPI脚本,以便在每天将信息添加到GoogleSheet时将帖子发送回端点 他们提供的文件如下: 这是我在谷歌应用程序脚本中根据过去使用过且成功的脚本设置的代码: function elnReturn() { lastRowData(); DataGather(); } function lastRowData(){ var sss = SpreadsheetApp.openById('1mNMlS02QIqs653VXbOlzW1kBC

我正在尝试创建一个GoogleAPI脚本,以便在每天将信息添加到GoogleSheet时将帖子发送回端点

他们提供的文件如下:

这是我在谷歌应用程序脚本中根据过去使用过且成功的脚本设置的代码:

function elnReturn() {
    lastRowData();
    DataGather();
}


function lastRowData(){

 var sss = SpreadsheetApp.openById('1mNMlS02QIqs653VXbOlzW1kBC7S2G-WWVYyqRRGX0Ys')
 var ss = sss.getSheetByName('Data')
 var lastRow = ss.getLastRow() 
 var lastCol = ss.getLastColumn()
 var lastRowData = ss.getRange(lastRow,1,1,lastCol).getValues()
 return lastRowData[0]

}


function DataGather(){
 var lastRow = lastRowData()
 var data = {

         'first_name' : lastRow[1],
         'last_name' : lastRow[2],
         'status' : 'Cold',
         'city' : lastRow[26],
         'state' : lastRow[27],
         'zip_code' : lastRow[28],
         'email_address' : lastRow[0],
         'phone_home' : lastRow[3],
         'user_ip' : lastRow[43],
         'home_type' : lastRow[31],
         'num_bath' : lastRow[41],
         'num_bed' : lastRow[40],
         'budget' : lastRow[43],
         'client_id' : 'CM',
         'comments' : 'Lead Return after 6th Day',      
     }

var payload = JSON.stringify(data)  

 var headers = {

     'ckm_campaign_id': '42',
     'ckm_key': 'jkdX9gZD6o',
     // Add any other required parameters for XXX API.
};
var url = 'https://elnpost.net/d.ashx'
var options = {
    'method': 'post',
    'contentType': 'application/json', 
    'payload' : payload,
};
var response = UrlFetchApp.fetch(url, options);
}     
收到的答复:

Error   Oct 1, 2019, 4:40:38 PM Request failed for https://elnpost.net returned code 404. Truncated server response: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/... (use muteHttpExceptions option to examine full response) at DataGather(Code:54) at elnReturn(Code:3)
错误2019年10月1日下午4:40:38请求失败https://elnpost.net 返回代码404。截断服务器响应:使用Google Apps脚本向以下服务器发送post请求的一般过程:
  • 根据API的文档指定标题
  • 根据API文档指定请求主体
  • 请求机构
  • 将以下内容合并到URL获取请求的选项中:

    • 方法
    • muteHttpExceptions
    • contentType
    • 有效负载
    • 标题
样本请求:

var url = 'YOU URL';
var payload = JSON.stringify(body); 
var options = { 
 'method': 'post',
 'muteHttpExceptions': true,
 'contentType': 'application/json',
 'payload': payload,
 'headers': headers 
};
var response = UrlFetchApp.fetch(url, options); 

我可以问你一些已经被使用并且成功的
表单吗?我们使用了一些类似的东西,所以当一个表单发布到谷歌表单时,它会发送到我们不再使用的crm。我把代码改成使用新应用程序的端点和凭据,谢谢你的回复。不幸的是,从你的回复中,我无法理解那些已经被使用并且成功的
@Jeremy-几件事。首先,我不认为
ckm_活动id
ckm_key
应该在标题下;查看文档,它们似乎是其他所有“字段”的一部分。第二,我建议首先使用实际/真实的数据点测试应用程序脚本之外的API(可能是打开的),这样,您就可以确定应该使用什么参数、在哪里以及如何使用。第三,如果您仍然面临问题,那么如果您也可以分享一些提供给API的实际细节,这会有所帮助,因为当我尝试时,它给了我一个200 OK,但也表明没有找到合格的买家。尝试将
muteHttpExceptions:true
添加到有效负载中。