# Failed to access using rest easy

**URL:** <https://community.dreamfactory.com/t/failed-to-access-using-rest-easy/4471>\
**Category:** REST API\
**Tags:** community, rest\
**Created:** [June 8, 2018, 4:04pm UTC](https://community.dreamfactory.com/t/failed-to-access-using-rest-easy/4471 "2018-06-08T16:04:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MD\_Kamal\_Hossain\_Sha](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/md_kamal_hossain_sha/32/1110_2.png) [@MD\_Kamal\_Hossain\_Sha](https://community.dreamfactory.com/u/MD_Kamal_Hossain_Sha)\
**Post date:** [June 8, 2018, 4:04pm UTC](https://community.dreamfactory.com/t/failed-to-access-using-rest-easy/4471/1 "2018-06-08T16:04:43Z")

</div>

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.

 ![Screenshot%20from%202018-06-08%2021-58-34](https://canada1.discourse-cdn.com/flex035/uploads/dreamfactory/original/2X/9/917926cb401937bfda879712d4a37b771a4e57e9.png)

---

<div class="post-metadata">

**Author:** ![jraiche](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@jraiche](https://community.dreamfactory.com/u/jraiche)\
**Post date:** [June 8, 2018, 7:54pm UTC](https://community.dreamfactory.com/t/failed-to-access-using-rest-easy/4471/2 "2018-06-08T19:54:46Z")

</div>

Hey,

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: [https://wiki.dreamfactory.com/DreamFactory/Tutorials/Access\_Using\_API\_Key](https://wiki.dreamfactory.com/DreamFactory/Tutorials/Access_Using_API_Key)

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](https://blog.dreamfactory.com/blog/bid/326379/Getting-Started-with-the-DreamFactory-API) and [here](https://wiki.dreamfactory.com/DreamFactory/Tutorials/Basic_Auth).

Hope that helped,  
Josiah

---

<div class="post-metadata">

**Author:** ![MD\_Kamal\_Hossain\_Sha](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.dreamfactory.com/md_kamal_hossain_sha/32/1110_2.png) [@MD\_Kamal\_Hossain\_Sha](https://community.dreamfactory.com/u/MD_Kamal_Hossain_Sha)\
**Post date:** [June 9, 2018, 7:22am UTC](https://community.dreamfactory.com/t/failed-to-access-using-rest-easy/4471/3 "2018-06-09T07:22:20Z")

</div>

thank you 🙂 its working.
