fix(link): send QR code custom options as multipart/form-data#137
Merged
Conversation
The QR create endpoint (/qrs) consumes multipart/form-data, but createQrCode sent the personalization options (title, backgroundColor, color, size, logo) as a JSON body. The API rejected that payload with HTTP 400, so QR codes could only be created without custom options. Build the request as multipart/form-data, sending each option as a form field and the logo (base64) as a decoded file upload. When no options are provided, fall back to an empty JSON body since the API rejects an empty multipart payload. Re-enables the previously skipped custom-options integration test and adds unit coverage for both the multipart and empty-body paths. https://claude.ai/code/session_01Taskt9xiXWzsGVmKPbPpnj
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #137 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 8 8
Lines 477 492 +15
Branches 95 101 +6
=========================================
+ Hits 477 492 +15 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Creating a QR code with custom options (
title,backgroundColor,color,size,logo) failed against the Hyphen API. The previously-skipped integration test confirmed it (see#133), and I reproduced it against the live API:Root cause
The QR create endpoint in
apix(POST /organizations/:org/link/codes/:code/qrs) consumesmultipart/form-data—fastify/multipartis registered withattachFieldsToBody: true, the schema declaresconsumes: ['multipart/form-data'], each field is read asbody[key].value, andlogois a file (isFile: true).The SDK's
createQrCode, however, sent the options as a JSON body withcontent-type: application/json. Schema validation expected each field to be an object ({ value }), so a JSON string like{ "title": "..." }was rejected with HTTP 400.This is why QR creation without options worked (the body serialized to
{}, which passes validation) but with options always failed — exactly the reported symptom.Fix (SDK only)
createQrCodenow builds amultipart/form-datarequest:title,backgroundColor,color,sizeare sent as form fields.logo(a base64 string) is decoded and appended as a file upload, matching the API'sisFileexpectation.content-typeheader is dropped so the multipart boundary is set automatically byfetch.{"message":"body must be object"}— this preserves the existing default-QR behavior.The public API is unchanged: callers still pass
CreateQrCodeOptionsexactly as before. Noapixchanges are required — the SDK simply now conforms to the existing multipart contract.Verification
pnpm test: 233 passed, 100% coverage (statements/branches/functions/lines).pnpm build: succeeds with no type errors.Closes #133
https://claude.ai/code/session_01Taskt9xiXWzsGVmKPbPpnj
Generated by Claude Code