Failed to access using rest easy



I am trying to access api using rest easy. api_key here is the api key of api_docs app. it only works if I authenticate using admin user…If I use any other user it wont work. either.



The whole key thing threw me for a bit at first as well.

API keys that are used in the API docs also require an access token. These are short lived tokens generated from calling the session endpoint. Anyway, what you should do is generate a new Role and App for REST Easy that has permissions without logging in as a user.

The steps:

  1. Create a role with access to the endpoints you want to use (make it read-only, just GET requests).
  2. Create an app with that role as the default. That means that anyone with the API key can do anything that role allows.
  3. Use that API key in the request.

Additionally, it appears you’re setting the header “api_key”; this won’t work. api_key is the url parameter format - you probably need to put it in the data section rather than the headers section. More info on this:

If you want to use the header for authentication, it’s called X-DreamFactory-Api-Key, and there is a parallel one for session tokens, X-DreamFactory-session-token. I discovered that it’s better to use query string parameters for simple GET requests because if there’s any odd headers the browser does a preflight OPTIONS call so every data request needs 2 round trips rather than 1.

If you want to log in as a user instead of a generic app, you can first POST a request to /user/session and get an access token, then use that token for 15 or 20 minutes. More info here and here.

Hope that helped,


thank you :slight_smile: its working.