Fix encoding templates create to send raw YAML body#5
Conversation
The /encoding/templates endpoint expects a raw YAML body with Content-Type: application/yaml. The SDK only sends Content-Type: application/json with a JSON-stringified body, so the API rejected every well-formed template with "Could not parse encoding template". Bypass the SDK and POST raw YAML directly. Also drop the --name flag — the API takes the template name from `metadata.name` in the YAML and ignores any `?name=` query parameter, so the flag was misleading. Add a resolveAuth() helper alongside getClient() so commands that need raw HTTP calls can resolve the API key the same way (CLI override → env var → config file). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes bitmovin encoding templates create to send encoding templates as a raw YAML request body (as required by the /encoding/templates API), rather than JSON-serializing an envelope that the API rejects.
Changes:
- Send raw YAML via
fetch()withContent-Type: application/yamlfor template creation, bypassing the SDK’s JSON-only behavior. - Add
resolveAuth()(andAPI_BASE_URL) to share auth-resolution logic between SDK and raw HTTP calls. - Remove the misleading
--nameflag and update docs/examples accordingly.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/commands/encoding/templates/create.ts |
Implements direct YAML POST + improved error surfacing; removes --name flag usage. |
src/lib/client.ts |
Introduces resolveAuth() and API_BASE_URL, and refactors getClient() to use resolveAuth(). |
test/commands/encoding-templates.test.ts |
Adds tests verifying YAML body/headers, JSON mode output, and failure handling. |
src/commands/skill.ts |
Updates CLI help examples to reflect removal of --name. |
README.md |
Updates documentation example to reflect name derivation from metadata.name. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Parse top-level API errors - Capture create stdout in tests - Assert surfaced API failure details
There was a problem hiding this comment.
Pull request overview
Fixes bitmovin encoding templates create by sending the encoding template YAML to /encoding/templates as a raw YAML request body with Content-Type: application/yaml, rather than JSON-wrapping it via the SDK.
Changes:
- Implement raw
fetchPOST for template creation withContent-Type: application/yamland improved error message extraction. - Remove the misleading
--nameflag and update CLI docs/examples to reflect name derivation frommetadata.name. - Add
resolveAuth()(andAPI_BASE_URL) to share auth resolution logic for non-SDK HTTP requests.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/commands/encoding/templates/create.ts |
Bypasses SDK to POST raw YAML, adds auth/header setup and improved API error message surfacing. |
src/lib/client.ts |
Introduces resolveAuth() helper (used by both SDK client and raw HTTP commands) and exports API_BASE_URL. |
test/commands/encoding-templates.test.ts |
Adds tests asserting raw YAML POST behavior, correct headers, --json cleanliness, and error surfacing. |
src/commands/skill.ts |
Updates CLI reference examples to remove --name and document name source. |
README.md |
Updates usage example to remove --name and document name source. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Preserve API error metadata for JSON output - Clean up test API key environment state
There was a problem hiding this comment.
Pull request overview
Fixes bitmovin encoding templates create by sending encoding templates to the Bitmovin API as raw YAML with Content-Type: application/yaml (instead of a JSON-wrapped payload via the SDK), matching what /encoding/templates expects.
Changes:
- Implement direct
fetchPOST of the YAML body to/encoding/templates, and surface APIdeveloperMessage(and request ID when available) on failures. - Remove the misleading
--nameflag (name is derived frommetadata.namein the YAML). - Add
resolveAuth()(andAPI_BASE_URL) to share consistent auth resolution for commands that need raw HTTP outside the SDK, plus add/create command tests covering success and error modes.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/commands/encoding-templates.test.ts | Adds coverage for create: verbatim YAML POST + headers, clean --json output, and API error surfacing. |
| src/lib/client.ts | Introduces resolveAuth() for shared auth resolution and exports API_BASE_URL; refactors getClient() to use it. |
| src/commands/skill.ts | Updates CLI examples to remove --name and clarify name source. |
| src/commands/encoding/templates/create.ts | Switches from SDK call to raw YAML POST with proper headers and improved error parsing/propagation. |
| README.md | Updates documentation example to remove --name and clarify name source. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Real bug, real fix. Tests are solid. Two substantive concerns and a smaller note before I approve. Strengths
Concerns
Smaller note
Question
|
Summary
bitmovin encoding templates createpreviously failed for every well-formed template with:The
/encoding/templatesendpoint expects a raw YAML body withContent-Type: application/yaml, but the SDK always serializes to JSON and setsContent-Type: application/json. So the body the API received was a JSON-stringified envelope ({"name": "...", "template": "metadata:\\n..."}) rather than a YAML document.Changes
Content-Type: application/yaml. Surface the API'sdeveloperMessageon failure for actionable errors.--nameflag. The API derives the template name frommetadata.namein the YAML and ignores any?name=query parameter, so the flag was misleading users into thinking it had effect.resolveAuth()helper inlib/client.tsalongsidegetClient(), so commands that need to make raw HTTP requests outside the SDK resolve auth the same way (CLI override → env var → config file).Tests
developerMessageextracted, and the command exits non-zero.201 Createdwith the template ID, and a malformed template returns the API'sCould not parse encoding templateerror rather than a generic SDK failure.Test plan
bitmovin encoding templates create ./valid.yamlreturns the template IDbitmovin encoding templates create ./malformed.yamlexits non-zero with the API error message