From c5d2e3a7f67927f80c6667b1ee4d2f14998cb57f Mon Sep 17 00:00:00 2001 From: Damian Jachyra <44927998+damianjachyra@users.noreply.github.com> Date: Thu, 2 Oct 2025 09:44:25 -0400 Subject: [PATCH 1/2] fix: add missing Content-Type header to POST requests - Add Content-Type: application/json header to post() function - Fix header casing from X-Magic-Secret-key to X-Magic-Secret-Key - Update CHANGELOG.md with v2.8.1 release notes - Resolves 422 errors caused by FastAPI not parsing JSON body correctly --- CHANGELOG.md | 13 +++++++++++++ src/utils/rest.ts | 7 +++++-- test/spec/utils/rest/get.spec.ts | 4 ++-- test/spec/utils/rest/post.spec.ts | 2 +- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f10a60..c2873b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +# v2.8.1 (Thu Oct 02 2025) + +#### 🐛 Bug Fix + +- Add missing Content-Type header to POST requests to fix 422 errors ([@damianjachyra](https://github.com/damianjachyra)) +- Fix header casing from X-Magic-Secret-key to X-Magic-Secret-Key ([@damianjachyra](https://github.com/damianjachyra)) + +#### Authors: 1 + +- Damian Jachyra ([@damianjachyra](https://github.com/damianjachyra)) + +--- + # v2.8.0 (Fri Sep 12 2025) #### 🚀 Enhancement diff --git a/src/utils/rest.ts b/src/utils/rest.ts index 69b6d9a..176d8b8 100644 --- a/src/utils/rest.ts +++ b/src/utils/rest.ts @@ -38,7 +38,10 @@ export function post, TR ) { return emitRequest(url, { method: 'POST', - headers: { 'X-Magic-Secret-key': secretApiKey }, + headers: { + 'X-Magic-Secret-Key': secretApiKey, + 'Content-Type': 'application/json' + }, body: JSON.stringify(body), }); } @@ -50,6 +53,6 @@ export function get(url: string, secretApiKey: string, params?: any) const urlWithParams = generateQuery(url, params); return emitRequest(urlWithParams, { method: 'GET', - headers: { 'X-Magic-Secret-key': secretApiKey }, + headers: { 'X-Magic-Secret-Key': secretApiKey }, }); } diff --git a/test/spec/utils/rest/get.spec.ts b/test/spec/utils/rest/get.spec.ts index e87f69d..175bc9c 100644 --- a/test/spec/utils/rest/get.spec.ts +++ b/test/spec/utils/rest/get.spec.ts @@ -21,7 +21,7 @@ test('Successfully GETs to the given endpoint & stringifies query params', async 'https://example.com/hello/world?foo=hello&bar=world', { method: 'GET', - headers: { 'X-Magic-Secret-key': API_KEY }, + headers: { 'X-Magic-Secret-Key': API_KEY }, }, ]); }); @@ -39,7 +39,7 @@ test('Successfully GETs to the given endpoint with no query params', async () => 'https://example.com/hello/world', { method: 'GET', - headers: { 'X-Magic-Secret-key': API_KEY }, + headers: { 'X-Magic-Secret-Key': API_KEY }, }, ]); }); diff --git a/test/spec/utils/rest/post.spec.ts b/test/spec/utils/rest/post.spec.ts index 5e71e76..c500407 100644 --- a/test/spec/utils/rest/post.spec.ts +++ b/test/spec/utils/rest/post.spec.ts @@ -26,7 +26,7 @@ test('Successfully POSTs to the given endpoint & stringifies body', async () => 'https://example.com/hello/world', { method: 'POST', - headers: { 'X-Magic-Secret-key': API_KEY }, + headers: { 'X-Magic-Secret-Key': API_KEY }, body: '{"public_address":"0x0123"}', }, ]); From 9c3a4fcb8aaa1449d61cc4c4d02dfad5b7d0cc85 Mon Sep 17 00:00:00 2001 From: Damian Jachyra <44927998+damianjachyra@users.noreply.github.com> Date: Thu, 2 Oct 2025 09:46:29 -0400 Subject: [PATCH 2/2] fix: add missing Content-Type header to POST requests - Add Content-Type: application/json header to post() function - Fix header casing from X-Magic-Secret-key to X-Magic-Secret-Key - Resolves 422 errors caused by FastAPI not parsing JSON body correctly --- src/utils/rest.ts | 7 +++++-- test/spec/utils/rest/get.spec.ts | 4 ++-- test/spec/utils/rest/post.spec.ts | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/utils/rest.ts b/src/utils/rest.ts index 69b6d9a..176d8b8 100644 --- a/src/utils/rest.ts +++ b/src/utils/rest.ts @@ -38,7 +38,10 @@ export function post, TR ) { return emitRequest(url, { method: 'POST', - headers: { 'X-Magic-Secret-key': secretApiKey }, + headers: { + 'X-Magic-Secret-Key': secretApiKey, + 'Content-Type': 'application/json' + }, body: JSON.stringify(body), }); } @@ -50,6 +53,6 @@ export function get(url: string, secretApiKey: string, params?: any) const urlWithParams = generateQuery(url, params); return emitRequest(urlWithParams, { method: 'GET', - headers: { 'X-Magic-Secret-key': secretApiKey }, + headers: { 'X-Magic-Secret-Key': secretApiKey }, }); } diff --git a/test/spec/utils/rest/get.spec.ts b/test/spec/utils/rest/get.spec.ts index e87f69d..175bc9c 100644 --- a/test/spec/utils/rest/get.spec.ts +++ b/test/spec/utils/rest/get.spec.ts @@ -21,7 +21,7 @@ test('Successfully GETs to the given endpoint & stringifies query params', async 'https://example.com/hello/world?foo=hello&bar=world', { method: 'GET', - headers: { 'X-Magic-Secret-key': API_KEY }, + headers: { 'X-Magic-Secret-Key': API_KEY }, }, ]); }); @@ -39,7 +39,7 @@ test('Successfully GETs to the given endpoint with no query params', async () => 'https://example.com/hello/world', { method: 'GET', - headers: { 'X-Magic-Secret-key': API_KEY }, + headers: { 'X-Magic-Secret-Key': API_KEY }, }, ]); }); diff --git a/test/spec/utils/rest/post.spec.ts b/test/spec/utils/rest/post.spec.ts index 5e71e76..c500407 100644 --- a/test/spec/utils/rest/post.spec.ts +++ b/test/spec/utils/rest/post.spec.ts @@ -26,7 +26,7 @@ test('Successfully POSTs to the given endpoint & stringifies body', async () => 'https://example.com/hello/world', { method: 'POST', - headers: { 'X-Magic-Secret-key': API_KEY }, + headers: { 'X-Magic-Secret-Key': API_KEY }, body: '{"public_address":"0x0123"}', }, ]);