SalesForce创建潜在客户休息API

时间:2019-01-23 09:18:15

标签: salesforce salesforce-lightning salesforce-communities

我的任务非常简单,我要做的就是在salesforce的负责人部分中创建记录。我已经创建了一个免费帐户,但无法在下面的REST API中弄清什么是 https://yourinstance.saleforce.com

https://yourinstance.salesforce.com/services/data/v39.0/sobjects/Lead

正文JSON:

{
    "body": {
    "Salutation": "Mr.",
    "FirstName": "H",
    "LastName": "Sam",
    "Company": "Samosto"
    }
}

标题:

Authorization: Bearer 00D0o0000015jPn!ARgAQPiIGhuYGUG_c0HDKNR0hxTX9zS82Fv1lIuqn4rapFJHPR422gLyi10rF8Auukb._hj9pj532DP7IajQV36lyKpUNEXdxvL

Content-Type: application/json

Sforce-Auto-Assign: TRUE

任何帮助将不胜感激!

2 个答案:

答案 0 :(得分:1)

这是您要登录的组织的URL。由于大多数组织在指南或示例中都使用自己的域名,因此您会看到正在使用此“ https://yourinstance.saleforce.com”。

您可以简单地在登录Salesforce时从URL中获取它,或转到设置->快速搜索“我的域”,您将看到域名。 从此处进行检查是一件好事,因为通用URL也可以作为登录选项被阻止。

答案 1 :(得分:0)

fwiw 我认为 API 已更改为 Account。这对我有用

// to run:
//     node create_new_account.js --config ./config_na150_scan_email_app.json
//
// links:
// https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_create.htm



const axios = require("axios");
const qs = require("qs");
const yargs = require("yargs");

const argv = yargs
    .command('create_account', 'test creating salesforce leads', {
        config: {
            description: 'config',
            alias: 'c',
            type: 'string',
        }
    })
    .help()
    .alias('help', 'h')
    .argv;


let { salesforce, scanResultsURL } = require(argv.config);

const auth_data = qs.stringify({"username": salesforce.username,
                "password": salesforce.password + salesforce.security_token,
                "grant_type": "password",
                "client_id": salesforce.consumer_key,
                "client_secret": salesforce.customer_secret,
                "redirect_uri": salesforce.redirect_uri});

console.log("auth data", auth_data)

const auth_config = {
    method: "post",
    url: salesforce.oauth2_uri,
    data: auth_data,
    headers: {"Content-Type": "application/x-www-form-urlencoded"}
}


const action_url = "https://na<TBD>.salesforce.com/services/data/v51.0/sobjects/Account"

console.log('action url', action_url)

data = {
    "Name" : "test Salesforce account API"
}

async function createAccout() {

    // "get" token
    axios(auth_config).then(function (response) {

    auth_header = {"Authorization": "Bearer " + response["data"]["access_token"]}

    action_config = {
        method: "post",
        url: action_url,
        headers: auth_header,
        data: data
    }


    // use valid token to send email
    axios(action_config).then(function (response) {

        console.log("action response", response["data"]); // TODO rm

    }).catch(function (error) {
        console.log("authenticated passed, action failed")

        console.log("action error", error); // TODO something
    })

    }).catch(function (error) {
    console.log("action token error", error); // TODO something
    })

}