finally block deletes the environment even if startup or the request fails.
Install the SDK
Install@usestatemachines/sdk 0.6.0 or later. The SDK runs on Node.js 20.20 or later and is ESM only.
Set your API key
In the dashboard, select the workspace for the environment. Open API keys, create a key, and save its value when it appears. If you cannot create a key, see workspace access. SetSTATEMACHINES_API_KEY in the process that runs your script. Use your terminal’s secret handling or your CI secret store. The SDK reads the process environment. It does not load .env files.
Check that the variable exists without printing it:
Run the request
The example creates the environment withwait: false, so it gets the environment ID before startup finishes. It then waits for running inside try. connect('salesforce') returns credentials for the default actor, the Salesforce administrator.
first-request.mts and run it:
200 and the Salesforce limits response. A response other than success throws an error, so the run does not pass by mistake.
If startup fails or the wait times out, the finally block still deletes the environment. Pause, resume, and delete environments covers the other cases.
Continue with your integration
Replace the limits request with a supported Salesforce request. Checkresponse.ok before you treat a response as a success. The app returns its errors as HTTP responses. The SDK throws management API errors instead.
Use named apps when your test needs more than one Salesforce copy. Use snapshots when each test needs the same starting records. For failures before the first request, follow startup troubleshooting.