API problem
After successfully getting a token, uploading a map, and verifying a token (all using API), I am unable to add control points to my map.
URL: https://mapwarper.net/api/v1/gcps/add_many
Method: POST
headers:
Accept-Language: en-us
X-User-Id: 489
Content-Type: application/json
Accept: */*
Accept-Encoding: gzip, deflate
X-User-Token: <my token here>
body:
{"gcps":[ { "mapid":"89204", "x":13.732928679828, "y":291.75644916533, "lat":48.3831032911, "lon":16.8349036568 }, { "mapid":"89204", "x":272.42981790593, "y":426.6767830045, "lat":47.826525191, "lon":18.8564658158 }, { "mapid":"89204", "x":379.74677541733, "y":77.53509104687, "lat":49.6134906752, "lon":19.4682669632 }, { "mapid":"89204", "x":582.5919954477, "y":128.54040212423, "lat":49.4184696716, "lon":21.0480880729 }, { "mapid":"89204", "x":777.92583459792, "y":202.42128224564, "lat":49.0879626791, "lon":22.5658321372 }, { "mapid":"89204", "x":416.6113429439, "y":376.89017450668, "lat":48.1247222464, "lon":19.90014553 }, { "mapid":"89204", "x":72.036229135096, "y":198.47591047018, "lat":48.8780240931, "lon":17.2026586527 } ] }
Response:
{
"errors": [
{
"title": "Unauthorized",
"detail": "Unauthorized Request"
}
]
}
Maybe this request does not allow token authentication? The example in the doc uses cookie.
Claude AI to the resque:
Looking at the code, I can help identify the issue. The GCPs controller has specific access controls:
rubyCopybefore_filter :check_editor_role, :only => [:add_many]
The error occurs because the endpoint requires editor privileges, not just authentication. Even with a valid token, you need to have the "editor" role to add multiple GCPs.
Options to resolve this:
- Request editor role access from an administrator
- Use the individual GCP creation endpoint instead
For now I will try to go with option 2
Looks like the methods / endpoint in the API is missing for this.
add_many in the v1/api is adding many control points to many maps - useful during an import process.
In the non-api api used in the application there is the add_many_to_map method, which adds many gcps to one specific map. Confusingly the url is add_many but is gcps/add_many/${map_id}
https://github.com/timwaters/mapwarper/blob/master/app/controllers/gcps_controller.rb#L178
curl -X POST http://localhost:3000/gcps/add_many/26.json --user [email protected]:pass -F "[email protected]"