Hi Dan,
Thanks for your help!
I’m using this rule:
function createLeadSalesforce(user, context, callback) {
user.app_metadata = user.app_metadata || {};
if (user.app_metadata.recordedAsLead) {
return callback(null, user, context);
}
const request = require('request');
const MY_SLACK_WEBHOOK_URL = 'YOUR SLACK WEBHOOK URL';
const slack = require('slack-notify')(MY_SLACK_WEBHOOK_URL);
//Populate the variables below with appropriate values
const SFCOM_CLIENT_ID = configuration.SALESFORCE_CLIENT_ID;
const SFCOM_CLIENT_SECRET = configuration.SALESFORCE_CLIENT_SECRET;
const USERNAME = configuration.SALESFORCE_USERNAME;
const PASSWORD = configuration.SALESFORCE_PASSWORD;
getAccessToken(
SFCOM_CLIENT_ID,
SFCOM_CLIENT_SECRET,
USERNAME,
PASSWORD,
(response) => {
if (!response.instance_url || !response.access_token) {
slack.alert({
channel: '#some_channel',
text: 'Error Getting SALESFORCE Access Token',
fields: {
error: response,
},
});
return;
}
createLead(
response.instance_url,
response.access_token,
(err, result) => {
if (err || !result || !result.id) {
// slack.alert({
// channel: '#some_channel',
// text: 'Error Creating SALESFORCE Lead',
// fields: {
// error: err || result
// }
// });
console.log('Error Creating SALESFORCE Lead', err || result);
return;
}
user.app_metadata.recordedAsLead = true;
auth0.users.updateAppMetadata(user.user_id, user.app_metadata);
}
);
}
);
//See http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_lead.htm
function createLead(url, access_token, callback) {
//Can use many more fields
const data = {
LastName: user.name,
Company: 'Web channel signups',
};
request.post(
{
url: url + '/services/data/v20.0/sobjects/Lead',
headers: {
Authorization: 'OAuth ' + access_token,
},
json: data,
},
(err, response, body) => {
return callback(err, body);
}
);
}
//Obtains a SFCOM access_token with user credentials
function getAccessToken(
client_id,
client_secret,
username,
password,
callback
) {
request.post(
{
url: 'https://login.salesforce.com/services/oauth2/token',
form: {
grant_type: 'password',
client_id: client_id,
client_secret: client_secret,
username: username,
password: password,
},
},
(err, respose, body) => {
return 'error dude';
}
);
}
// don’t wait for the SF API call to finish, return right away (the request will continue on the sandbox)`
callback(null, user, context);
}
My configuration details for Salesforce are accurate and stored in the Rules Settings. Not sure how to troubleshoot from here, unfortunately.