Anthony Hervy
Anthony Hervy

Reputation: 1448

How to create public style with API?

I'm trying to create a new style in public with a json file on mapbox.

Documentation (https://docs.mapbox.com/api/maps/#create-a-style) say we can create new style with command

curl -X POST "https://api.mapbox.com/styles/v1/urbaneaseantho?access_token=sYOURTOKEN" --data @test2.json --header "Content-Type:application/json"

Return say is upload :

{"version":8,"name":"My Awesome Style","metadata":{},"sources":{"myvectorsource":{"url":"mapbox://{map_id}","type":"vector"},"myrastersource":{"url":"mapbox://{map_id}","type":"raster"}},"sprite":"mapbox://sprites/urbaneaseantho/cjw0ebb5v01p41co9znianoam/ck2u8j60r58fu0sgyxrigm3cu","glyphs":"mapbox://fonts/urbaneaseantho/{fontstack}/{range}.pbf","layers":[],"created":"2019-05-23T08:29:54.901Z","id":"cjw0ebb5v01p41co9znianoam","modified":"2019-05-23T08:29:54.901Z","owner":"urbaneaseantho","visibility":"private"}

My problem is the visibility, I need to set on "public" by default.

With ""visibility": "public" in my test2.json file, same result, if add "draft": false , mapbox don't want my file

Other way try to update style, but when use

curl -X POST "https://api.mapbox.com/styles/v1/urbaneaseantho/STYLE_ID?access_token=TOKEN" --data @test_update.json --header "Content-Type:application/json"

return is

{"message":"Not Found"}

Is it possible or maybe is an api limit ?

Thank you

Upvotes: 3

Views: 610

Answers (1)

Anthony Hervy
Anthony Hervy

Reputation: 1448

Solution from Mapbox support :

  1. Make a GET call to retrieve the style object
  2. Modify the returned JSON object as desired (in your case changing "visibility" to "public")
  3. Remove the "created" and "modified" attributes from the style object
  4. PATCH using the updated Style object as the body of the call

Upvotes: 1

Related Questions