question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The required parameter(s) are not present in the request

See original GitHub issue

@alexindigo @felixge @DylanPiercey @JBtje

I am running Node v12.18.1 and axios v3.0.0 and form-data v2.5.1 (using 2.5.1 based on this issue here https://github.com/form-data/form-data/issues/462)

I am getting an error saying that the ‘The required parameter(s) client_id,client_secret,grant_type not present in the request’

The request I am executing is to get an access token from the Autodesk Developer API. The example for executing this request in their tutorial is as follows:

curl - i - X POST\ 'https://developer.api.autodesk.com/authentication/v1/authenticate'\ -
  H 'Content-Type: application/x-www-form-urlencoded'\ -
  d 'client_id=CLIENT_ID'\ -
  d 'client_secret=CLIENT_SECRET'\ -
  d 'grant_type=client_credentials'\ -
  d 'scope=code:all data:write data:read bucket:create bucket:delete'

You can see that this request is supposed to be a POST and it expects “x-www-form-urlencoded” content type. Executing the above curl request works fine and I get the proper response.

I expect, therefore, that the following code should process this request successfully as well. At least because it follows the same logic. However, this is not the case and I get the above error - where the “client_id”, “client_secret”, and “grant_type” are not there even though I append them… (Please note that the id and secret are hidden here.):

const form = new FormData();
    form.append("client_id", CLIENT_ID);
    form.append("client_secret", CLIENT_SECRET);
    form.append("grant_type", "client_credentials");
    form.append("scope", "code:all data:write data:read bucket:create bucket:delete");
    
    const resp = await axios.post("https://developer.api.autodesk.com/authentication/v1/authenticate", form, {
      headers: {
        "Content-Type": "application/x-www-form-urlencoded"
      }
    });

Logging the form object after appending the values looks like this:

{
  form: FormData {
    _overheadLength: 433,
    _valueLength: 118,
    _valuesToMeasure: [],
    writable: false,
    readable: true,
    dataSize: 0,
    maxDataSize: 2097152,
    pauseStreams: true,
    _released: false,
    _streams: [
      '----------------------------896880656847627813546978\r\n' +
        'Content-Disposition: form-data; name="client_id"\r\n' +
        '\r\n',
      '<CLIENT_ID>',
      [Function: bound ],
      '----------------------------896880656847627813546978\r\n' +
        'Content-Disposition: form-data; name="client_secret"\r\n' +
        '\r\n',
      '<CLIENT_SECRET>',
      [Function: bound ],
      '----------------------------896880656847627813546978\r\n' +
        'Content-Disposition: form-data; name="grant_type"\r\n' +
        '\r\n',
      'client_credentials',
      [Function: bound ],
      '----------------------------896880656847627813546978\r\n' +
        'Content-Disposition: form-data; name="scope"\r\n' +
        '\r\n',
      'all data:write data:read bucket:create bucket:delete',
      [Function: bound ]
    ],
    _currentStream: null,
    _insideLoop: false,
    _pendingNext: false,
    _boundary: '--------------------------896880656847627813546978'
  }
}

Full Error Message:

Error: Request failed with status code 400
    at createError (/Users/danielmaartens/drm/sovtech/palian/autodesk/tutorials/inventor-integration/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/Users/danielmaartens/drm/sovtech/palian/autodesk/tutorials/inventor-integration/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/Users/danielmaartens/drm/sovtech/palian/autodesk/tutorials/inventor-integration/node_modules/axios/lib/adapters/http.js:236:11)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (_stream_readable.js:1221:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  config: {
    url: 'https://developer.api.autodesk.com/authentication/v1/authenticate',
    method: 'post',
    data: FormData {
      _overheadLength: 433,
      _valueLength: 118,
      _valuesToMeasure: [],
      writable: false,
      readable: true,
      dataSize: 0,
      maxDataSize: 2097152,
      pauseStreams: true,
      _released: true,
      _streams: [],
      _currentStream: null,
      _insideLoop: false,
      _pendingNext: false,
      _boundary: '--------------------------231060729760745310281464',
      _events: [Object: null prototype],
      _eventsCount: 1
    },
    headers: {
      Accept: 'application/json, text/plain, */*',
      'Content-Type': 'application/x-www-form-urlencoded',
      'User-Agent': 'axios/0.19.2'
    },
    transformRequest: [ [Function: transformRequest] ],
    transformResponse: [ [Function: transformResponse] ],
    timeout: 0,
    adapter: [Function: httpAdapter],
    xsrfCookieName: 'XSRF-TOKEN',
    xsrfHeaderName: 'X-XSRF-TOKEN',
    maxContentLength: -1,
    validateStatus: [Function: validateStatus]
  },
  request: ClientRequest {
    _events: [Object: null prototype] {
      socket: [Function],
      abort: [Function],
      aborted: [Function],
      error: [Function],
      timeout: [Function],
      prefinish: [Function: requestOnPrefinish]
    },
    _eventsCount: 6,
    _maxListeners: undefined,
    outputData: [],
    outputSize: 0,
    writable: true,
    _last: true,
    chunkedEncoding: true,
    shouldKeepAlive: false,
    useChunkedEncodingByDefault: true,
    sendDate: false,
    _removedConnection: false,
    _removedContLen: false,
    _removedTE: false,
    _contentLength: null,
    _hasBody: true,
    _trailer: '',
    finished: true,
    _headerSent: true,
    socket: TLSSocket {
      _tlsOptions: [Object],
      _secureEstablished: true,
      _securePending: false,
      _newSessionPending: false,
      _controlReleased: true,
      secureConnecting: true,
      _SNICallback: null,
      servername: 'developer.api.autodesk.com',
      alpnProtocol: false,
      authorized: true,
      authorizationError: null,
      encrypted: true,
      _events: [Object: null prototype],
      _eventsCount: 10,
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: 'developer.api.autodesk.com',
      _readableState: [ReadableState],
      readable: true,
      _maxListeners: undefined,
      _writableState: [WritableState],
      writable: false,
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: undefined,
      _server: null,
      ssl: [TLSWrap],
      _requestCert: true,
      _rejectUnauthorized: true,
      parser: null,
      _httpMessage: [Circular],
      [Symbol(res)]: [TLSWrap],
      [Symbol(verified)]: true,
      [Symbol(pendingSession)]: null,
      [Symbol(asyncId)]: 11,
      [Symbol(kHandle)]: [TLSWrap],
      [Symbol(kSetNoDelay)]: false,
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kBytesRead)]: 0,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(connect-options)]: [Object]
    },
    connection: TLSSocket {
      _tlsOptions: [Object],
      _secureEstablished: true,
      _securePending: false,
      _newSessionPending: false,
      _controlReleased: true,
      secureConnecting: true,
      _SNICallback: null,
      servername: 'developer.api.autodesk.com',
      alpnProtocol: false,
      authorized: true,
      authorizationError: null,
      encrypted: true,
      _events: [Object: null prototype],
      _eventsCount: 10,
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: 'developer.api.autodesk.com',
      _readableState: [ReadableState],
      readable: true,
      _maxListeners: undefined,
      _writableState: [WritableState],
      writable: false,
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: undefined,
      _server: null,
      ssl: [TLSWrap],
      _requestCert: true,
      _rejectUnauthorized: true,
      parser: null,
      _httpMessage: [Circular],
      [Symbol(res)]: [TLSWrap],
      [Symbol(verified)]: true,
      [Symbol(pendingSession)]: null,
      [Symbol(asyncId)]: 11,
      [Symbol(kHandle)]: [TLSWrap],
      [Symbol(kSetNoDelay)]: false,
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kBytesRead)]: 0,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(connect-options)]: [Object]
    },
    _header: 'POST /authentication/v1/authenticate HTTP/1.1\r\n' +
      'Accept: application/json, text/plain, */*\r\n' +
      'Content-Type: application/x-www-form-urlencoded\r\n' +
      'User-Agent: axios/0.19.2\r\n' +
      'Host: developer.api.autodesk.com\r\n' +
      'Connection: close\r\n' +
      'Transfer-Encoding: chunked\r\n' +
      '\r\n',
    _onPendingData: [Function: noopPendingOutput],
    agent: Agent {
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      defaultPort: 443,
      protocol: 'https:',
      options: [Object],
      requests: {},
      sockets: [Object],
      freeSockets: {},
      keepAliveMsecs: 1000,
      keepAlive: false,
      maxSockets: Infinity,
      maxFreeSockets: 256,
      maxCachedSessions: 100,
      _sessionCache: [Object],
      [Symbol(kCapture)]: false
    },
    socketPath: undefined,
    method: 'POST',
    insecureHTTPParser: undefined,
    path: '/authentication/v1/authenticate',
    _ended: true,
    res: IncomingMessage {
      _readableState: [ReadableState],
      readable: false,
      _events: [Object: null prototype],
      _eventsCount: 3,
      _maxListeners: undefined,
      socket: [TLSSocket],
      connection: [TLSSocket],
      httpVersionMajor: 1,
      httpVersionMinor: 1,
      httpVersion: '1.1',
      complete: true,
      headers: [Object],
      rawHeaders: [Array],
      trailers: {},
      rawTrailers: [],
      aborted: false,
      upgrade: false,
      url: '',
      method: null,
      statusCode: 400,
      statusMessage: 'Bad Request',
      client: [TLSSocket],
      _consuming: false,
      _dumped: false,
      req: [Circular],
      responseUrl: 'https://developer.api.autodesk.com/authentication/v1/authenticate',
      redirects: [],
      [Symbol(kCapture)]: false
    },
    aborted: false,
    timeoutCb: null,
    upgradeOrConnect: false,
    parser: null,
    maxHeadersCount: null,
    reusedSocket: false,
    _redirectable: Writable {
      _writableState: [WritableState],
      writable: true,
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      _options: [Object],
      _redirectCount: 0,
      _redirects: [],
      _requestBodyLength: 607,
      _requestBodyBuffers: [],
      _onNativeResponse: [Function],
      _currentRequest: [Circular],
      _currentUrl: 'https://developer.api.autodesk.com/authentication/v1/authenticate',
      [Symbol(kCapture)]: false
    },
    [Symbol(kCapture)]: false,
    [Symbol(kNeedDrain)]: false,
    [Symbol(corked)]: 0,
    [Symbol(kOutHeaders)]: [Object: null prototype] {
      accept: [Array],
      'content-type': [Array],
      'user-agent': [Array],
      host: [Array]
    }
  },
  response: {
    status: 400,
    statusText: 'Bad Request',
    headers: {
      'content-type': 'application/json',
      date: 'Tue, 14 Jul 2020 09:04:44 GMT',
      'content-length': '224',
      connection: 'Close'
    },
    config: {
      url: 'https://developer.api.autodesk.com/authentication/v1/authenticate',
      method: 'post',
      data: [FormData],
      headers: [Object],
      transformRequest: [Array],
      transformResponse: [Array],
      timeout: 0,
      adapter: [Function: httpAdapter],
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      validateStatus: [Function: validateStatus]
    },
    request: ClientRequest {
      _events: [Object: null prototype],
      _eventsCount: 6,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      _last: true,
      chunkedEncoding: true,
      shouldKeepAlive: false,
      useChunkedEncodingByDefault: true,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: null,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      socket: [TLSSocket],
      connection: [TLSSocket],
      _header: 'POST /authentication/v1/authenticate HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'Content-Type: application/x-www-form-urlencoded\r\n' +
        'User-Agent: axios/0.19.2\r\n' +
        'Host: developer.api.autodesk.com\r\n' +
        'Connection: close\r\n' +
        'Transfer-Encoding: chunked\r\n' +
        '\r\n',
      _onPendingData: [Function: noopPendingOutput],
      agent: [Agent],
      socketPath: undefined,
      method: 'POST',
      insecureHTTPParser: undefined,
      path: '/authentication/v1/authenticate',
      _ended: true,
      res: [IncomingMessage],
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      _redirectable: [Writable],
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype]
    },
    data: {
      developerMessage: 'The required parameter(s) client_id,client_secret,grant_type not present in the request',
      errorCode: 'AUTH-008',
      'more info': 'https://forge.autodesk.com/en/docs/oauth/v2/developers_guide/error_handling/'
    }
  },
  isAxiosError: true,
  toJSON: [Function]
}

What am I missing here ? Do you have any clue as to what could be causing this behaviour ?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
hharb1commented, Jun 10, 2022

I faced the same issue,

what you have to do is setting content type as application/x-www-form-urlencoded

and send your data as query string.

` const url = ‘https://developer.api.autodesk.com/authentication/v1/authenticate’;

const result = await lastValueFrom(this.httpService.post(url,
    queryString.stringify({

        client_id: '<your_client_id>',
        client_secret: '<your_client_secret>',
        grant_type: 'client_credentials',
        scope: 'data:write data:read bucket:create bucket:delete'

    }),
    {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    }));`

NOTE: import * as queryString from ‘query-string’ --> make sure that the library is query-string and not query-string.

0reactions
dkoltovichcommented, Sep 10, 2020

I might be wrong but this is not an issue of the library. Authorization endpoint requires x-www-form-urlencoded content type in your case. But you are using form-data instead.

Even if you manually change the “Content-Type” request header to x-www-form-urlencoded, it wouldn’t work. Because if you use the “form-data” library the actual data encoded in form-data format (sections with boundaries in form-data against key-value pairs in urlencoded). As a result, the server can’t correctly decode your request and find the required fields.

I agree with @JBtje that this library will not be useful in your case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Curl 2-Legged Token with Autodesk Forge fails (AUTH-008)
In this case, I see a space in your data, before you specify the scope. Could that be the reason? There is another...
Read more >
Required Parameter Not Found - Imperva Documentation Portal
Required Parameter Not Found Summary The HTTP Request was missing one or more of the parameters that are marked as required for this...
Read more >
Tutorial: Build a REST API with HTTP non-proxy integration
Learn how to create an API Gateway API with the HTTP custom integration using the API Gateway console.
Read more >
Describing Parameters - Swagger
Query parameters are the most common type of parameters. They appear at the end of the request URL after a question mark (...
Read more >
parameters • Akka HTTP - Documentation
parameters. This page explains how to extract multiple query parameter values from the request, or parameters that might or might not be present....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found