# Fix DocuSign "TEMPLATE_ID_INVALID" when the template works in the UI

## TL;DR
Template ids are per-environment, so grab the id from the API in the same environment your code calls. A demo template id fails against production and vice versa, even when the template name matches. List templates via the API, use the id from that response, and the error goes away.

```text
{
  "errorCode": "TEMPLATE_ID_INVALID",
  "message": "The template ID is invalid."
}
```

1. Check your API base URI: demo and production are different hosts with different template ids.
   Expected: you can name the environment your code targets.
2. List templates through the API in that environment and copy the template id from the response.
   Expected: you have an id the API itself recognizes.
3. Confirm the API user has the template shared with them.
   Expected: the template appears in the API user's template list.
4. Replace the hardcoded id with the environment-correct one and resend.
   Expected: envelope creation succeeds.

## Use this when
- the template opens fine in the web UI but the API rejects the id
- the error started after a demo-to-production move
- a colleague's id works but yours does not (different environments)

## Not for this skill when
- the template fails in the UI too (fix or restore the template)
- the id is correct but the call still fails (check permissions and sharing)
- you are building the template id dynamically (validate the lookup logic)

## Variant phrasings
- docusign TEMPLATE_ID_INVALID works in ui fails api
- docusign template id demo vs production mismatch
- docusign api cannot find template that exists
- docusign template shared with api user not found

## Why it happens
Demo and production are separate DocuSign systems; templates created in one do not exist in the other, though names often match. Code usually carries a hardcoded id copied from the wrong environment, and the UI lookup works because the human is logged into the right one.

## Edge cases
- Templates can be deleted or moved to folders that change sharing; re-verify periodically.
- Copying a template between environments creates a new id; update the config at copy time.
- Service users need the template explicitly shared; ownership by your admin account is not enough.
- Store template ids per environment in config, never as a single hardcoded value.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_TgqYXbYUTT-4M2CIjzNfmQ
