mapbox/mapbox-sdk-js

createUpload returns 422 response from API with `The request body contains the invalid property "private"`

jlumia opened this issue · 9 comments

I am getting this error when calling the createUpload method. Version "mapbox": "^1.0.0-beta9". I didn't know if this was the right place to put this comment.

await uploadsClient .createUpload({ mapId: ${userName}.${sources[0].tilesetName}, url: s3Creds.url, tilesetName: sources[0].fileName }) .send();

MapiError { message: 'The request body contains the invalid property "private".', type: 'HttpError', statusCode: 422, request: MapiRequest { id: 34, _options: { method: 'POST', path: '/uploads/v1/:ownerId', body: { url: 'https://tilestream-tilesets-production.s3.amazonaws.com/<myamazonurl>', tileset: '<mytileset>', name: '<mysource>', private: true } }, emitter: EventEmitter { _events: {}, _eventsCount: 0 }, client: NodeClient { accessToken: '<mytoken>', origin: 'https://api.mapbox.com' }, response: null, error: [Circular], sent: true, aborted: false, path: '/uploads/v1/:ownerId', method: 'POST', origin: 'https://api.mapbox.com', query: {}, params: {}, body: { url: 'https://tilestream-tilesets-production.s3.amazonaws.com/<myamazonurl>', tileset: '<mytileset>', name: '<mysource>', private: true }, file: null, encoding: 'utf8', sendFileAs: null, headers: { 'content-type': 'application/json' } }, body: { message: 'The request body contains the invalid property "private".' } }

"mapbox": "^1.0.0-beta9"

That's a very old version, could you try upgrading to the latest @mapbox/mapbox-sdk package instead of the old mapbox package?

@andrewharvey Sorry, that was some old cruft from the package json. I am actually using "@mapbox/mapbox-sdk": "^0.11.0" and leveraging it in my .js file const mapboxUploads = require('@mapbox/mapbox-sdk/services/uploads');

I can replicate this with

const MapboxUploads = require('@mapbox/mapbox-sdk/services/uploads');
const uploadsService = MapboxUploads({ accessToken: 'sk.' });

uploadsService.createUpload({
    mapId: 'username.tileset',
    url: 'test',
    tilesetName: 'tileset'
})
    .send()
    .then(response => {
      console.log('Response', response)
    })
    .catch(error => {
      console.log('Error', error)
    });

and Mapbox API returns a 422 response with The request body contains the invalid property "private". however according to https://docs.mapbox.com/api/maps/#create-an-upload private is a valid body parameter:

Optional. A boolean that describes whether the tileset must be used with an access token from your Mapbox account. Default is true.

Doesn't look like this is something we can address in mapbox-sdk-js since we are following the API documentation.

Since this looks like an API or API documentation issue best to contact Mapbox Support about it.

@andrewharvey thank you so much for taking the time to replicate/understand this issue. Much appreciated! This is a great API as well - thank you for providing this to the community. I will contact Mapbox and see what they say.

This is a great API as well - thank you for providing this to the community.

Most of the work was done by others https://github.com/mapbox/mapbox-sdk-js/graphs/contributors but I do try and keep it maintained and updated where I can.

I've experienced that same issue. I did some temporary fix by removing all references to a "private" parameter in the library (I use this sdk in browser with browserify). The uploads work for me now, but it would be better to have a permanent stable fix.

encountered the same issue, agree that it's wrong in the endpoint spec , but regardless I think it should be an optional field and the client does not seem to allow to unset it (always is sent as private: true) which should be server default, not the client's

Version: "@mapbox/mapbox-sdk": "^0.11.0",

Same as above. What is a quick fix? Should I downgrade to a previous version? Any roadmap to fix?

Version: "@mapbox/mapbox-sdk": "^0.11.0",

const uploadRequest = mbx.uploads.createUpload({
    // ... 
  });
  // @note: https://github.com/mapbox/mapbox-sdk-js/issues/392
  delete uploadRequest.body.private;
  const uploadRes = await uploadRequest.send();

Very hacky... but it works!