ARTICLE AD BOX
I am developing a Chainlink Functions (v0.3.x) request to fetch artist data from the Spotify API. I am simulating the request locally using the Chainlink Functions Toolkit (simulateScript), which runs in a Deno sandbox.
I am able to load my secrets correctly, but the authentication request to Spotify consistently fails with 400 Bad Request. The Spotify API requires the body to be application/x-www-form-urlencoded, but Functions.makeHttpRequest seems to be failing to format this correctly regardless of the method I use.
Environment:
Framework: Hardhat
Library: @chainlink/functions-toolkit
Runtime: Deno (via Chainlink simulation)
API: https://accounts.spotify.com/api/token (Client Credentials Flow)
The Code (Current Attempt):
I am manually constructing the Base64 Authorization header and trying to pass the **grant_type**as a raw string.
What I have tried:
Raw String Body: data: "grant_type=client_credentials" (Result: 400)
Object Body: data: { grant_type: "client_credentials" } (Result: 400 - likely serialized as JSON)
URL Query Params: url: ".../api/token?grant_type=client_credentials" with empty data (Result: 400)
Using npm:qs: Importing qs and using stringify({ grant_type: ... }) (Result: 400)
I have verified that my Client ID and Secret are correct (they work in a standard curl request).
How can I correctly send a POST request with application/x-www-form-urlencoded body using Functions.makeHttpRequest in the Chainlink Deno environment?
