Autodesk-Forge / forge-api-nodejs-client

Forge Node.js SDK: Provides Node.js SDK to help you easily integrate Forge REST APIs into the application
Apache License 2.0
124 stars 86 forks source link

ItemsAPI.postItem Generates 400 Error #79

Open sudispono opened 2 years ago

sudispono commented 2 years ago

Howdy all,

Software team lead for Bechtel Center at Purdue here.

Problem: I was getting a "BAD_INPUT" error by utilizing the postItem() function.

Description: Consulted the api docs, and found this note on the data.attributes.displayName field:

Note that for A360 projects, this field is required.

Note that for BIM 360 projects, this field is reserved for future releases and should not be used. Use included[0].attributes.name for the file name.

The current version of postItem function utilizes the "CreateStorageDataAttributes" model within a "createItemData". A TypeScript compile error results from using "displayName" instead of "name" with this model, but using "name" results in a 400 error as shown below (1). By implementing a workaround and modifying by types file I could get it working (2).

It is quite possible I missed something, and I simply used something incorrectly.

Thank you for your work on this module, have a great day.

Supporting Docs: 1:

API ERROR CODE:  400
MESSAGE:  BadRequest
BODY:  {
  jsonapi: { version: '1.0' },
  errors: [
    {
      id: REDACTED,
      status: '400',
      code: 'BAD_INPUT',
      title: 'One or more input values in the request were bad',
      detail: 'Display name not found, should be in resource: "data.attributes.displayName".'
    }
  ]
}

2:

CODE:  201
BODY:  {
  jsonapi: { version: '1.0' },
  links: {
    self: {
      href: REDACTED
    }
  },
  data: {
    type: 'items',
    id: REDACTED,
    attributes: {
      displayName: 'foo.txt',
      createTime: '2022-01-27T19:55:39.0000000Z',
      createUserId: REDACTED,
      createUserName: 'Gavin',
      lastModifiedTime: '2022-01-27T19:55:39.0000000Z',
      lastModifiedUserId: REDACTED,
      lastModifiedUserName: 'Gavin',
      hidden: false,
      reserved: false,
      extension: [Object]
    },
    links: { self: [Object] },
    relationships: {
      tip: [Object],
      versions: [Object],
      parent: [Object],
      refs: [Object],
      links: [Object]
    }
  },
  included: [
    {
      type: 'versions',
      id: REDACTED,
      attributes: [Object],
      links: [Object],
      relationships: [Object]
    }
  ]
}