API request not working as expected while using content type as "application/x-www-form-urlencoded"

Hi Team,

We are using our platform request method to fetch access token from a third-party domain using client credentials.

The client credentials are url encoded and even-though we are using content type as “application/x-www-form-urlencoded” the body is not being formatted as expected , due to which we are receiving 401 unauthorised error.

Any suggestions to send data through url -encoding would be really helpful.

Regards,
Ganesh.

@tejakummarikuntla - Appreciate an update on this.

This appears to be a request format issue. It works as expected when sending the parameters inside the form key. Thanks for the assistance @Aadharsh_R

try {
    const headers = {
      'Content-Type' : 'application/x-www-form-urlencoded'
    }
    const response = await $request.post('https://httpbin.org/post', {
      headers : headers,
      form: {
          username: 'xyzzzzz',
          password: 'abc12345#'
        }
    });
    console.log('Response:' + JSON.stringify(response));

  } catch (error) {
    console.error(error)
  }
2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.