Mapbox API - update tileset

562 views Asked by At

I am trying to replace tileset resources - using the https://docs.mapbox.com/api/maps/mapbox-tiling-service/#replace-a-tileset-source. I get the 200 response code for tilesetId I provide, but I cannot see my changes when I check it in my mapbox -> studio -> tilesets section.

    const updateURL = `https://api.mapbox.com/tilesets/v1/sources/${username}/${id}?access_token=${accessToken}`;
        const updateTilesetOptions = {
            'method': 'PUT',
            'url': updateURL,
            'headers': {
                'Content-Type': 'multipart/form-data'
            },
            formData: {
                'file': {
                    'value': Buffer.from(fileToUpload.data).toString(),
                    'options': {
                        'filename': fileToUpload.name,
                        'contentType': null
                    }
                }
            }
        };
    const updateResponse = await requestPromise(updateTilesetOptions);
    console.log("updateResponse.statusCode " , updateResponse.statusCode)
    if (updateResponse.statusCode >= 400) {
        return {
           message: updateResponse.statusMessage,
           code: updateResponse.statusCode,
           source: "Update Tileset"
        }
   }

Can someone suggest what I am doing wrong. Note: I also tried to publish tileset after udpating the source, but I am getting 400 error.

1

There are 1 answers

0
spreaderman On

I received a reply from Mapbox. This is the correct process;

(1) Delete the existing tileset source. If you just update the existing tileset, you are indeed appending data to it.

(2) Create a new tileset source with the same ID

(3) Publish your updated tileset. Please note that this suggests that you already have a tileset recipe configured for the existing tileset

Please let me know if it works for you. It works for me now. I was missing the publishing step.