Skip to content

Fix encoding templates create to send raw YAML body#5

Open
dweinber wants to merge 5 commits into
mainfrom
fix/templates-create-yaml-body
Open

Fix encoding templates create to send raw YAML body#5
dweinber wants to merge 5 commits into
mainfrom
fix/templates-create-yaml-body

Conversation

@dweinber
Copy link
Copy Markdown
Member

@dweinber dweinber commented Apr 29, 2026

Summary

bitmovin encoding templates create previously failed for every well-formed template with:

{"error":true,"httpStatusCode":400,
 "message":"Could not parse encoding template. Please make sure to provide
            valid YAML or JSON and to replace all placeholders"}

The /encoding/templates endpoint expects a raw YAML body with Content-Type: application/yaml, but the SDK always serializes to JSON and sets Content-Type: application/json. So the body the API received was a JSON-stringified envelope ({"name": "...", "template": "metadata:\\n..."}) rather than a YAML document.

Changes

  • Bypass the SDK and POST the YAML body directly with Content-Type: application/yaml. Surface the API's developerMessage on failure for actionable errors.
  • Drop the --name flag. The API derives the template name from metadata.name in the YAML and ignores any ?name= query parameter, so the flag was misleading users into thinking it had effect.
  • Add a resolveAuth() helper in lib/client.ts alongside getClient(), so commands that need to make raw HTTP requests outside the SDK resolve auth the same way (CLI override → env var → config file).

Tests

  • New test asserts the request method, URL, body, and Content-Type / X-Api-Key headers.
  • New test asserts that an API error is surfaced with the developerMessage extracted, and the command exits non-zero.
  • All tests pass locally.
  • Verified end-to-end against the real API: creating a template now returns 201 Created with the template ID, and a malformed template returns the API's Could not parse encoding template error rather than a generic SDK failure.

Test plan

  • CI green
  • bitmovin encoding templates create ./valid.yaml returns the template ID
  • bitmovin encoding templates create ./malformed.yaml exits non-zero with the API error message

dweinber and others added 2 commits April 29, 2026 11:18
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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() with Content-Type: application/yaml for template creation, bypassing the SDK’s JSON-only behavior.
  • Add resolveAuth() (and API_BASE_URL) to share auth-resolution logic between SDK and raw HTTP calls.
  • Remove the misleading --name flag 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.

Comment thread src/commands/encoding/templates/create.ts Outdated
Comment thread test/commands/encoding-templates.test.ts Outdated
Comment thread test/commands/encoding-templates.test.ts Outdated
- Parse top-level API errors
- Capture create stdout in tests
- Assert surfaced API failure details
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 fetch POST for template creation with Content-Type: application/yaml and improved error message extraction.
  • Remove the misleading --name flag and update CLI docs/examples to reflect name derivation from metadata.name.
  • Add resolveAuth() (and API_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.

Comment thread test/commands/encoding-templates.test.ts
Comment thread src/commands/encoding/templates/create.ts Outdated
- Preserve API error metadata for JSON output

- Clean up test API key environment state
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 fetch POST of the YAML body to /encoding/templates, and surface API developerMessage (and request ID when available) on failures.
  • Remove the misleading --name flag (name is derived from metadata.name in the YAML).
  • Add resolveAuth() (and API_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.

@dweinber dweinber requested a review from lukaskroepfl April 30, 2026 14:56
@lukaskroepfl
Copy link
Copy Markdown
Member

Real bug, real fix. Tests are solid. Two substantive concerns and a smaller note before I approve.

Strengths

  • Diagnosis is clear: SDK serializes to JSON; /encoding/templates wants raw YAML; bypassing the SDK is the right call until/unless the SDK grows an escape hatch.
  • Tests pin the request shape (URL, method, body verbatim, Content-Type, X-Api-Key) and cover both JSON-mode error output (with requestId) and human-mode error output. Good coverage of what could regress.
  • Dropping --name is correct — the API ignores ?name= and derives from metadata.name. README + skill output updated to match.

Concerns

  1. Hardcoded API_BASE_URL. 'https://api.bitmovin.com/v1' is now baked into the CLI as a constant for every command that bypasses the SDK. The SDK itself accepts a baseUrl (used by Bitmovin-internal staging/regional setups). After this lands, SDK calls and raw-fetch calls will diverge as soon as anyone overrides the SDK base URL — including, potentially, support/internal teams. Two reasonable paths:

    • Read the SDK's resolved base URL from the same source the SDK uses (env var like BITMOVIN_API_BASE_URL, or config), and have resolveAuth return it alongside apiKey/tenantOrgId.
    • At minimum, support a BITMOVIN_API_BASE_URL env var override here so internal users aren't forced to fork.

    Even just the env-var path would be enough for now.

  2. Breaking change with no CHANGELOG entry. --name removal will break anyone scripting bitmovin encoding templates create ./t.yaml --name "X" — they'll get an oclif Unexpected argument: --name error. Recent PRs (Mask secrets in account info by default #6, Resolve API key from env var in config show #7) added CHANGELOG entries for breaking changes; please do the same here under [Unreleased] / Changed (BREAKING).

Smaller note

  1. await this.isJsonMode() line on its own in run() looks like a stray no-op. It's actually load-bearing — it primes BaseCommand's internal _jsonMode flag so the subsequent this.log(...) knows to route to stderr in JSON mode. A one-line comment would save the next reader a trip through base-command.ts. Or restructure: branch on await this.isJsonMode() directly rather than relying on this.log's side-channel routing.

Question

  1. Is there an SDK-side path to send a raw-body request with a custom Content-Type that I missed? If not, worth raising upstream so this bypass can eventually be removed — but bypassing for now is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants