How to get instance name/key via API

Is there a way to get the instance name of a Salesforce organisation (like na41) via the REST API in a reliable way? I’ve looked at existing resources available and they do not seem to expose that. I also considered parsing it out of the instance_url value, but it could vary if the org is using a custom domain.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

With a little bit of reverse engineering, it seems like we can get the instance key using this REST endpoint:

https://api.status.salesforce.com/v1/instanceAliases/[custom-domain]

As an example, if your Salesforce instance URL is:

You can get the key at:


In JavaScript:

fetch('https://api.status.salesforce.com/v1/instanceAliases/ci')
    .then((resp) => resp.json())
    .then(function (body) {
        console.log(body.instanceKey);
    })
    .catch(function (err) {
        console.error(err)
    });


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x