How to tell if instance specfic Salesforce URL is from Sandbox or Production?

salesforce

Solution

If you know the instance & sessionId, then you can call the REST api's discovery service at `{instance}/services/data/v25.0` passing the sessionId in a Authorization header, e.g. using curl this would be

curl -v -H "Authorization: OAuth {sessionId}" https://{instance}/services/data/v25.0/

This returns you the discovery data, including the users Identity Id, e.g.

"id": "https://login.salesforce.com/id/00D300000000QSfEAM/00530000000dImzAAE"

If the host is `login.salesforce.com` its production, if its `test.salesforce.com` its sandbox.

Problem

How to tell if instance specific Salesforce URL is from Sandbox or Production, if I have the URL and Session Id only?

Original source