uadmin: Data Access API Read does not work in JS

Greetings. I just want to say that Data Access API is one of the best feature ever so that I do not have to create an API file to access data. I accidentally found this from one of the closed issues. Fantastic!

http://localhost:8080/api/d lists all information related to Data Access API. I access http://localhost:8080/api/d/restaurant/read to read all Restaurant data.

{
  "result": [
    {
      "ID": 1,
      "DeletedAt": null,
      "Name": "Burger King",
      "Address": ""
    },
    {
      "ID": 2,
      "DeletedAt": null,
      "Name": "Domino's Pizza",
      "Address": ""
    },
    {
      "ID": 3,
      "DeletedAt": null,
      "Name": "Subway",
      "Address": ""
    },
    {
      "ID": 4,
      "DeletedAt": null,
      "Name": "Panda Express",
      "Address": ""
    }
  ],
  "status": "ok"
}

but performing in JS, i got this error

{
  "err_msg": "Permission denied",
  "status": "error"
}

Any advices please?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 2
  • Comments: 20 (1 by maintainers)

Most upvoted comments

I found the reason why. If your account is not logged in the uadmin page, you will get an error. That means you need to login your admin account first so that you can read data in JS.

There are so many questions to think about in the bigger picture. At least you discovered the secret treasure of uadmin.

thank you @dxlvgcw. could be better if we have more examples than my references I have. i will leave more questions here

  1. the use of join and how it works
  2. how to use aggregation operators
  3. the use of group by
  4. the use of uadmin functions for data access api
  5. m2m still not clear to me
  6. apply public permission to all instead of letting me create function like APIPublicRead for every model
  7. how prequery and postquery works and whats the difference between them
  8. upload image and file attachment to model
  9. data access api to send email
  10. login and logout api is not listed in help
  11. get data from a different database
  12. show the total number of records in your model
  13. data access api to export excel file

i would request @Spotlight64 to reopen this issue

@alphakitchown Use APIPublicRead model method. Return the value to true to enable public access. Place it below your type struct inside your model file. Instead of *Model, replace it with the name of your struct.

func (m *Model) APIPublicRead(r *http.Request) bool {
    return true
}