Google Apps脚本:Salesforce API调用 [英] Google Apps Script: Salesforce API Call

查看:141
本文介绍了Google Apps脚本:Salesforce API调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚吃完早餐,已经遇到了麻烦。我正在尝试从我的Google表格中调用salesforce REST api。我已经在Python中本地编写了一个工作脚本,但是将其转换为JS,出现了一些问题:

  function authenticateSF(){ 

var url ='https://login.salesforce.com/services/oauth2/token';
var options = {
grant_type:'password',
client_id:'XXXXXXXXXXX',
client_secret:'111111111111',
username:'ITSME@smee.com ',
密码:'smee'
};

var results = UrlFetchApp.fetch(url,options);



$ b $ p
$ b

这是错误回应:


https://login.salesforce请求失败。截断服务器响应:
{error_description:授权类型不是
支持,错误:unsupported_grant_type }(使用muteHttpExceptions
选项来检查完整响应)(第12行,文件代码)

请注意,这些精确的参数在我的本地python脚本中正常工作(将关键值放在引号内)。

以下是相关文档:
Google Script:连接到外部API

谢谢大家!

$ p

$ p

$ p


$ b Google的UrlFetchApp对象会自动默认为GET请求。

要进行身份验证,您必须在选项中明确设置方法post:
$ b

function authenticateSF (){

var url ='https://login.salesforce.com/services/oauth2/token';
var payload = {
'grant_type':'password',
'client_id':'XXXXXXXXXXX',
'client_secret':'111111111111',
'username ':'ITSME@smee.com',
'密码':'smee'
};

var options = {
'method':'post',
'payload':payload
};

var results = UrlFetchApp.fetch(url,options);
}


Just finished breakfast and already hit a snag. I'm trying to call the salesforce REST api from my google sheets. I've written a working script locally in python, but converting it into JS, something went wrong:

function authenticateSF(){

  var url = 'https://login.salesforce.com/services/oauth2/token';
  var options = {
    grant_type:'password',
    client_id:'XXXXXXXXXXX',
    client_secret:'111111111111',
    username:'ITSME@smee.com',
    password:'smee'
  };

  var results = UrlFetchApp.fetch(url, options);
}

Here is the error response:

Request failed for https://login.salesforce.com/services/oauth2/token returned code 400. Truncated server response: {"error_description":"grant type not supported","error":"unsupported_grant_type"} (use muteHttpExceptions option to examine full response) (line 12, file "Code")

Mind you, these exact parameters work fine in my local python script (putting the key values inside quotations).

Here are the relevant docs: Google Script: Connecting to external API's Salesforce: REST API guide

Thank you all!

解决方案

Google's UrlFetchApp object automatically defaults to a GET request. To authenticate, you have to explicitly set in the options the method "post":

function authenticateSF(){

  var url = 'https://login.salesforce.com/services/oauth2/token';
  var payload = {
    'grant_type':'password',
    'client_id':'XXXXXXXXXXX',
    'client_secret':'111111111111',
    'username':'ITSME@smee.com',
    'password':'smee'
  };

  var options = {
    'method':'post',
    'payload':payload
  };

  var results = UrlFetchApp.fetch(url, options);
}

这篇关于Google Apps脚本:Salesforce API调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆