# Getting Controller properties from Adapters

**URL:** <https://discuss.emberjs.com/t/getting-controller-properties-from-adapters/8313>\
**Category:** Ember CLI\
**Created:** [July 5, 2015, 6:36am UTC](https://discuss.emberjs.com/t/getting-controller-properties-from-adapters/8313 "2015-07-05T06:36:46Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![rffaguiar](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/rffaguiar/32/11041_2.png) [@rffaguiar](https://discuss.emberjs.com/u/rffaguiar)\
**Post date:** [July 5, 2015, 6:36am UTC](https://discuss.emberjs.com/t/getting-controller-properties-from-adapters/8313/1 "2015-07-05T06:36:46Z")

</div>

I am using ember 1.12.0 and ember-cli 0.2.7

I am following this link [RESTAdapter - 4.6 - Ember API Documentation](http://emberjs.com/api/data/classes/DS.RESTAdapter.html) The problem is that everytime I use “this” inside a Adapter (like app/adapters/application.js) I got a error

```
Build error

<app name>/adapters/application

`this` at the top level is undefined

```

I.E. I get this error with this code:

```
export default DS.RESTAdapter.extend({
  headers: function() {
    return {
      "API_KEY": this.get("session.authToken"),
      "ANOTHER_HEADER": "Some header value"
    };
  }.property("session.authToken")
});

```

So, how can I get a controller property from a adapter?

---

<div class="post-metadata">

**Author:** ![broerse](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/broerse/32/9497_2.png) [@broerse](https://discuss.emberjs.com/u/broerse)\
**Post date:** [July 5, 2015, 6:59am UTC](https://discuss.emberjs.com/t/getting-controller-properties-from-adapters/8313/2 "2015-07-05T06:59:43Z")

</div>

`this.container.lookup("controller:application");` See: [https://github.com/broerse/ember-cli-blog/blob/master/app/adapters/application.js](https://github.com/broerse/ember-cli-blog/blob/master/app/adapters/application.js)

---

<div class="post-metadata">

**Author:** ![rffaguiar](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/rffaguiar/32/11041_2.png) [@rffaguiar](https://discuss.emberjs.com/u/rffaguiar)\
**Post date:** [July 5, 2015, 7:01pm UTC](https://discuss.emberjs.com/t/getting-controller-properties-from-adapters/8313/3 "2015-07-05T19:01:20Z")

</div>

> [@broerse](#):
>
> this.container.lookup(“controller:application”)

actually, I can`t even use “this” inside an adapter, it always give me a build error.

> `this` at the top level is undefined

---

<div class="post-metadata">

**Author:** ![broerse](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/broerse/32/9497_2.png) [@broerse](https://discuss.emberjs.com/u/broerse)\
**Post date:** [July 5, 2015, 7:18pm UTC](https://discuss.emberjs.com/t/getting-controller-properties-from-adapters/8313/4 "2015-07-05T19:18:59Z")

</div>

Did you use the bind(this) as in my adapter example? Is should work.

Edit: It should work without the bind(this) in your case.

---

<div class="post-metadata">

**Author:** ![rffaguiar](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/rffaguiar/32/11041_2.png) [@rffaguiar](https://discuss.emberjs.com/u/rffaguiar)\
**Post date:** [July 5, 2015, 7:31pm UTC](https://discuss.emberjs.com/t/getting-controller-properties-from-adapters/8313/5 "2015-07-05T19:31:07Z")

</div>

Yeah, maybe its because I am using the Ember Data? Basically, I am trying to do this:

```
import DS from 'ember-data';

export default DS.RESTAdapter.extend({ headers: function() {
    return {
      "API_KEY": this.get("session.authToken"),
      "ANOTHER_HEADER": "Some header value"
    };
}.property("session.authToken") });

```

**edit 1:** this code is in the docs [RESTAdapter - 4.6 - Ember API Documentation](http://emberjs.com/api/data/classes/DS.RESTAdapter.html)

---

<div class="post-metadata">

**Author:** ![broerse](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/broerse/32/9497_2.png) [@broerse](https://discuss.emberjs.com/u/broerse)\
**Post date:** [July 5, 2015, 7:31pm UTC](https://discuss.emberjs.com/t/getting-controller-properties-from-adapters/8313/6 "2015-07-05T19:31:49Z")

</div>

what if you write `var at = this.get("session.authToken")` before the return?

---

<div class="post-metadata">

**Author:** ![broerse](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/broerse/32/9497_2.png) [@broerse](https://discuss.emberjs.com/u/broerse)\
**Post date:** [July 5, 2015, 7:35pm UTC](https://discuss.emberjs.com/t/getting-controller-properties-from-adapters/8313/7 "2015-07-05T19:35:32Z")

</div>

Is is strange because I think it should work the way you wrote it. I will take look.

---

<div class="post-metadata">

**Author:** ![rffaguiar](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/rffaguiar/32/11041_2.png) [@rffaguiar](https://discuss.emberjs.com/u/rffaguiar)\
**Post date:** [July 5, 2015, 7:43pm UTC](https://discuss.emberjs.com/t/getting-controller-properties-from-adapters/8313/8 "2015-07-05T19:43:22Z")

</div>

Nothing ☹ .Ok, I will search if someone had this problem before and some source code. Thanks

---

<div class="post-metadata">

**Author:** ![broerse](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/broerse/32/9497_2.png) [@broerse](https://discuss.emberjs.com/u/broerse)\
**Post date:** [July 5, 2015, 7:51pm UTC](https://discuss.emberjs.com/t/getting-controller-properties-from-adapters/8313/9 "2015-07-05T19:51:50Z")

</div>

OK. It is strange code in your adapter (looks more like controller code) but it should work. I just inserted your code in a project and can’t get the error you have. If I need to check something please let me know.

---

<div class="post-metadata">

**Author:** ![rffaguiar](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/rffaguiar/32/11041_2.png) [@rffaguiar](https://discuss.emberjs.com/u/rffaguiar)\
**Post date:** [July 5, 2015, 9:28pm UTC](https://discuss.emberjs.com/t/getting-controller-properties-from-adapters/8313/10 "2015-07-05T21:28:14Z")

</div>

This code is not mine, Its directly from the ember docs, but the problem occurs on “this” keyword. Could you tell me which version of ember-cli, ember and ember-data you are using? Mine are: ember: 1.12.0, ember-cli: 0.2.7, ember-data: 1.0.0-beta.18.

Here is the link pointing directly: [RESTAdapter - 4.6 - Ember API Documentation](http://emberjs.com/api/data/classes/DS.RESTAdapter.html#toc_headers-customization)

---

<div class="post-metadata">

**Author:** ![broerse](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/broerse/32/9497_2.png) [@broerse](https://discuss.emberjs.com/u/broerse)\
**Post date:** [July 5, 2015, 9:30pm UTC](https://discuss.emberjs.com/t/getting-controller-properties-from-adapters/8313/11 "2015-07-05T21:30:06Z")

</div>

Ember Inspector 1.8.2 Ember 1.12.1 Ember Data 1.0.0-beta.19.2 jQuery 1.11.3

---

<div class="post-metadata">

**Author:** ![broerse](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/broerse/32/9497_2.png) [@broerse](https://discuss.emberjs.com/u/broerse)\
**Post date:** [July 5, 2015, 10:14pm UTC](https://discuss.emberjs.com/t/getting-controller-properties-from-adapters/8313/12 "2015-07-05T22:14:14Z")

</div>

A working test: [GitHub - broerse/rffaguiar](https://github.com/broerse/rffaguiar)

---

<div class="post-metadata">

**Author:** ![rffaguiar](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/rffaguiar/32/11041_2.png) [@rffaguiar](https://discuss.emberjs.com/u/rffaguiar)\
**Post date:** [July 5, 2015, 11:22pm UTC](https://discuss.emberjs.com/t/getting-controller-properties-from-adapters/8313/13 "2015-07-05T23:22:40Z")

</div>

wow, thanks. I just updated everything and now its working. Do I have a way to give you more years in your life for your help? 😃 Really thank you!
