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
- Sign in to the Sandbox environment using your account credentials.
- 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.
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.