Sign in with apple REST api keep getting [Request failed with status code 400] error

I am implementing apple sign in on my website

On my backend(Nodejs), I need to request an authentication token using https://appleid.apple.com/auth/token REST api.

I used Axios and coded as following

export const createSignWithAppleSecret = () => {
    const token = jwt.sign({}, signWithApplePrivateKey, {
        algorithm: 'ES256',
        expiresIn: '1h',
        audience: APPLE_DOMAIN,
        issuer: APPLE_TEAM_ID,
        subject: APPLE_SERVICE_ID,
        keyid: APPLE_KEY_ID,
    });
    return token;
};



export const getAppleToken = async (code: string) =>
    axios.post(
        'https://appleid.apple.com/auth/token',
        qs.stringify({
            grant_type: 'authorization_code',
            code,
            client_secret: createSignWithAppleSecret(),
            client_id: APPLE_SERVICE_ID,
            redirect_uri: APPLE_REDIRECT_URI,
        }),
        {
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',

            },
        }
    );

But I am getting Reqest failed with status code 400

Error: Request failed with status code 400\n    at createError (/home/ubuntu/sooldamhwa/www/node_modules/axios/lib/core/createError.js:16:15)\n    at settle (/home/ubuntu/sooldamhwa/www/node_modules/axios/lib/core/settle.js:17:12)\n    at IncomingMessage.handleStreamEnd (/home/ubuntu/sooldamhwa/www/node_modules/axios/lib/adapters/http.js:260:11)\n    at IncomingMessage.emit (events.js:327:22)\n    at IncomingMessage.EventEmitter.emit (domain.js:485:12)\n    at endReadableNT (_stream_readable.js:1201:12)\n    at processTicksAndRejections (internal/process/task_queues.js:84:21)

The api endpoint is correct, and I have configured header as document instructed( https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens)

Could someone please let me know what I did wrong?