2
votes

My task is pretty simple, all i have to do is to create records in the lead section of the salesforce. I have created a free account and i am not able to figure it out that, what is https://yourinstance.saleforce.com in the below rest api:

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

Body JSON:

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

Header:

Authorization: Bearer 00D0o0000015jPn!ARgAQPiIGhuYGUG_c0HDKNR0hxTX9zS82Fv1lIuqn4rapFJHPR422gLyi10rF8Auukb._hj9pj532DP7IajQV36lyKpUNEXdxvL

Content-Type: application/json

Sforce-Auto-Assign: TRUE

Any help will be highly appreciated!

2
What errors are you getting? You're not actually using "yourinstance" are you? - so cal cheesehead
i am not using yourinstance.saleforce.com and i am not sure what to use instead - Shubham Mishra
The name of your instance is in the URL, it will be whatever precedes salesforce.com. What errors are you running into? - so cal cheesehead

2 Answers

2
votes

This is the URL you have for the organization you want to login to. Since most of the orgs are using their own Domain names in guides or examples you will see this "https://yourinstance.saleforce.com" being used.

You can simply take it from the URL while logged in Salesforce or go to Setup -> quick search "My Domain" and you will see the domain name. It is a good thing to check it from here as the generic URL can also be blocked as a login option.

0
votes

fwiw i think the API has changed to Account. This is working for me

// 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
    })

}