You need to sign in to do that
Don't have an account?

Issue with salesforce while getting access_token
Hello Team,
Could anyone please help me to resolve the below issue :
We are planning to integrate Gupshup wtih Salesforce platform and trying to get access_token using the bellow code snippet.
--------------------------------------------------------------------------------------------------------------------------------
Code Snippet :
/** This is a sample code for your bot**/
function MessageHandler(context, event) {
context.console.log("test")
var grant_type;
var client_id;
var client_secret;
var redirect_uri;
var username;
var password;
if(event.message.toLowerCase() == "post") {
var contextParam = {
"grant_type":"password",
"client_id":"3MVG9Y6d_Btp4xp5fHfBCvTWgHlfBKxrEf0lFIt9p71zfTmei0q9P8QxoaRowTIefchOoNdY8syyWOriUKYlV",
"client_secret":"7975635620731036814",
"redirect_uri":"https://localhost:8443/_callback",
"username":"apex_integration@sfdc.com",
"password":"Mardal786*k7Q58cu1ffXZEm0NOEgWi8vIv"
};
var url = "https://login.salesforce.com/services/oauth2/token";
var param = JSON.stringify(contextParam);
var header = {"Content-Type":"application/x-www-form-urlencoded"};
context.console.log("contextparm")
context.simplehttp.makePost(url,param,header);
}
}
/** Functions declared below are required **/
function EventHandler(context, event) {
if(! context.simpledb.botleveldata.numinstance)
context.simpledb.botleveldata.numinstance = 0;
numinstances = parseInt(context.simpledb.botleveldata.numinstance) + 1;
context.simpledb.botleveldata.numinstance = numinstances;
context.sendResponse("Thanks for adding me. You are:" + numinstances);
}
function HttpResponseHandler(context, event) {
context.console.log(event.getresp)
var result= JSON.parse(event.getresp);
if(result=="success"){
context.console.log("success")
context.sendResponse("We have successfully stored your data");
}
context.sendResponse(event.getresp);
context.console.log("final")
}
function DbGetHandler(context, event) {
context.sendResponse("testdbput keyword was last get by:" + event.dbval);
}
function DbPutHandler(context, event) {
context.sendResponse("testdbput keyword was last put by:" + event.dbval);
}
--------------------------------------------------------------------------------------------------------------------------------
Error Dexcription :
{"error":"unsupported_grant_type","error_description":"grant type not supported"}
Any help would be greatly appriciated.
Thanks,
Fazur
Could anyone please help me to resolve the below issue :
We are planning to integrate Gupshup wtih Salesforce platform and trying to get access_token using the bellow code snippet.
--------------------------------------------------------------------------------------------------------------------------------
Code Snippet :
/** This is a sample code for your bot**/
function MessageHandler(context, event) {
context.console.log("test")
var grant_type;
var client_id;
var client_secret;
var redirect_uri;
var username;
var password;
if(event.message.toLowerCase() == "post") {
var contextParam = {
"grant_type":"password",
"client_id":"3MVG9Y6d_Btp4xp5fHfBCvTWgHlfBKxrEf0lFIt9p71zfTmei0q9P8QxoaRowTIefchOoNdY8syyWOriUKYlV",
"client_secret":"7975635620731036814",
"redirect_uri":"https://localhost:8443/_callback",
"username":"apex_integration@sfdc.com",
"password":"Mardal786*k7Q58cu1ffXZEm0NOEgWi8vIv"
};
var url = "https://login.salesforce.com/services/oauth2/token";
var param = JSON.stringify(contextParam);
var header = {"Content-Type":"application/x-www-form-urlencoded"};
context.console.log("contextparm")
context.simplehttp.makePost(url,param,header);
}
}
/** Functions declared below are required **/
function EventHandler(context, event) {
if(! context.simpledb.botleveldata.numinstance)
context.simpledb.botleveldata.numinstance = 0;
numinstances = parseInt(context.simpledb.botleveldata.numinstance) + 1;
context.simpledb.botleveldata.numinstance = numinstances;
context.sendResponse("Thanks for adding me. You are:" + numinstances);
}
function HttpResponseHandler(context, event) {
context.console.log(event.getresp)
var result= JSON.parse(event.getresp);
if(result=="success"){
context.console.log("success")
context.sendResponse("We have successfully stored your data");
}
context.sendResponse(event.getresp);
context.console.log("final")
}
function DbGetHandler(context, event) {
context.sendResponse("testdbput keyword was last get by:" + event.dbval);
}
function DbPutHandler(context, event) {
context.sendResponse("testdbput keyword was last put by:" + event.dbval);
}
--------------------------------------------------------------------------------------------------------------------------------
Error Dexcription :
{"error":"unsupported_grant_type","error_description":"grant type not supported"}
Any help would be greatly appriciated.
Thanks,
Fazur

https://developer.salesforce.com/forums/?id=906F0000000BCs9IAG