How do I connect to a sandbox through REST API?

You can connect to a specific sandbox through REST API calls by connecting to the Sandbox environment or using the Metadata-Context key respectively. Here's how you can do it using UI and POSTMAN.

UI

  1. Sign in to the Sandbox environment using your account credentials.
  2. Call the REST API using your account

When you’re in the sandbox environment, the response will include custom objects and attributes defined in that sandbox.

POSTMAN

You can connect to a specific sandbox when calling a REST API by specifying the following headers:

  • Key = Metadata-Context
  • Value = sandbox="SandboxName"

Example 1

In this scenario, you've an unpublished new custom object named CO1 in Sandbox1. When you call a REST API to get or update on the CO1 object, you'll get the correct response.

Note: You can call only the custom resources that are specific to that Sandbox environment. For example, if you call the CO1 API outside any sandbox or while in any other sandbox such as Sandbox2 then you'll get an error 404.

Example 2

In this scenario, you've already published a custom object named CO2. Also, in Sandbox1 you've added a custom attribute named Attribute1 to CO2. When you call the CO2 REST API while in Sandbox1, your REST output will include Attribute 1.

Note: If you call the CO2 REST API while outside the sandbox or in any other sandbox, your REST output will not include the Attribute 1 field. Although it will include all the fields in the mainline. Here, you can't update Attribute 1 in CO2 as well.