+ Start a Discussion
Stuart KingStuart King 

cURL the login instance for data

Our group is changing over some code in response to a change in instance.  This code follows the methods outlined in the quick start guide. https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/quickstart.htm  At the moment, we acquire an auth token by hitting the login instance, and then query our numbered instance for data.

To prevent having to keep changing the configuration parameter to point to our new ID when it changes, is it possible to still query the login instance to get data back?  I've tested on my end without any luck, but I figured I'd check to see if I'm missing anything.

We're exploring setting up a custom domain, which will likely  be our alternative, but the easier solution would be better.

 
Best Answer chosen by Stuart King
pconpcon
If you make your login call against login.salesforce.com (or test.salesforce.com for sandboxes) then you should get back a serverUrl (or a similar name) in your payload that has your access_token.  I say "or something similar" since I don't know off the top of my head what it's called in REST and I know it's serverUrl in soap.  Then you can get your instance name back from there.  There are lots of libraries that exist to handle all of the session stuff if you need it.  I can help you find one depending on what language you plan on using for your final code.  If you really want to do this all via commandline / cURL and you don't need oAuth (like a service login) then you can use SOAP to login and get your sessionId and serverUrl and then make any REST or SOAP calls you need.

All Answers

pconpcon
If you make your login call against login.salesforce.com (or test.salesforce.com for sandboxes) then you should get back a serverUrl (or a similar name) in your payload that has your access_token.  I say "or something similar" since I don't know off the top of my head what it's called in REST and I know it's serverUrl in soap.  Then you can get your instance name back from there.  There are lots of libraries that exist to handle all of the session stuff if you need it.  I can help you find one depending on what language you plan on using for your final code.  If you really want to do this all via commandline / cURL and you don't need oAuth (like a service login) then you can use SOAP to login and get your sessionId and serverUrl and then make any REST or SOAP calls you need.
This was selected as the best answer
Stuart KingStuart King
Thank you pcon, that answers my question.  It makes the most sense to use the instance_url parameter in the initial auth request rather than hard code it.  I appreciate your quick reponse!