Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API problem #288

Open
alexanderzatko opened this issue Feb 1, 2025 · 2 comments
Open

API problem #288

alexanderzatko opened this issue Feb 1, 2025 · 2 comments

Comments

@alexanderzatko
Copy link

alexanderzatko commented Feb 1, 2025

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.

@alexanderzatko
Copy link
Author

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:

  1. Request editor role access from an administrator
  2. Use the individual GCP creation endpoint instead

For now I will try to go with option 2

@timwaters
Copy link
Owner

timwaters commented Feb 3, 2025

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]"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants