Refresh token returns fetch returns Invalid grant_type parameter or parameter missing
I've setup an API in Next14 App Router to retrieve an access token from the oauth2/token endpoint. I have the client details and refresh token from the Netatmo My App page and I make the call using a server side fetch as...
// route.ts
export const dynamic = "force-static";
export async function GET() {
const payload = JSON.stringify({
grant_type: "refresh_token",
refresh_token: process.env.NETATMO_WEATHER_REFRESH_TOKEN,
client_id: process.env.NETATMO_CLIENT_ID,
client_secret: process.env.NETATMO_CLIENT_SECRET,
});
console.log({ payload });
const res = await fetch("https://api.netatmo.com/oauth2/token", {
headers: {
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
},
method: "POST",
body: payload,
});
const data = await res.json();
return Response.json({ data });
}
The console outputs the expected values but the fetch return still returns...
{"error":"invalid_request","error_description":"Invalid grant_type parameter or parameter missing"}
What am I missing here?
Comments
2 comments
Hello Ali,
Seems like a simple encoding problem for me
Can you try the following code in your Body ?
Have a good day,
Leslie - Community Manager
Hi Leslie,
You are an absolute legend - that fixed it thanks so much!
Please sign in to leave a comment.