# Invalid Context

**URL:** <https://forums.losant.com/t/invalid-context/1085>\
**Category:** Help\
**Created:** [August 22, 2018, 3:31pm UTC](https://forums.losant.com/t/invalid-context/1085 "2018-08-22T15:31:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul\_wareham](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@paul\_wareham](https://forums.losant.com/u/paul_wareham)\
**Post date:** [August 22, 2018, 3:31pm UTC](https://forums.losant.com/t/invalid-context/1085/1 "2018-08-22T15:31:27Z")

</div>

Hi Folks,

I’m getting the following error when attempting to render an Experience Page.

_Invalid context._

_ctx[keys3.0] no (or more than one) schemas match_

_You attempted to set invalid context variables._

I was playing around trying to get the new tag queries working using context variable, but I reversed all that work and am still getting the error after clearing caches.

Any ideas how I can track down the source of the error?

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [August 22, 2018, 4:26pm UTC](https://forums.losant.com/t/invalid-context/1085/2 "2018-08-22T16:26:36Z")

</div>

I don’t know exactly what you’re trying to accomplish, but here’s an example that uses both device tag and device ID context variables. It might be helpful in understanding how to use them.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/1X/f4c8a718b40a381f328cd929e04aaae556794eb7.png)

In this example, I’m using device tags to associate experience users to the devices they can access. Each device that a user can access has a tag with its key set to the experience user ID and the value simply set to `true`.

The `ctx.allDevices` tag context variable is then set to `{{experience.user.id}}`, which is automatically provided by Losant when an authenticated user requests a page. This will return all devices that have that user’s ID as a tag key and the value set to `true`.

The `ctx.currentDevice` device ID context variable is then provided by the URL the user accessed. The endpoint for this page looks like `/devices/{deviceId}/dashboard`. Losant automatically parses the `deviceId` URL parameter and makes it available at `{{request.params.deviceId}}`.

As a helpful debugging tool, if you ever want to just render out all available data, you can make a page and set the template to `<pre>{{jsonEncode . 2}}</pre>`. This will print all available fields that you can use in templates on your Experience Views.

---

<div class="post-metadata">

**Author:** ![paul\_wareham](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@paul\_wareham](https://forums.losant.com/u/paul_wareham)\
**Post date:** [August 22, 2018, 4:35pm UTC](https://forums.losant.com/t/invalid-context/1085/3 "2018-08-22T16:35:20Z")

</div>

Hi Brandon,

What I was attempting to do is pass down the user’s experience group and use that as a tag to filter devices they are permitted to see. That resulted in the error, but I have since reversed those testing changes but the error persists. I’ve gone back to only passing the deviceId which has always worked for me in the past. Below is the only context variable I am referencing.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/1X/f01b83dafe871e34aaf9654bc0a26357faccfc03.png)

However, that is triggering the error:  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/1X/373f0fb4ad1aa0831884e1ca55681a921b0571cd.png)

I figured that I should try to get back to where I started with a fully working site, before making another attempt to implement a tag context variable but I’ve gotten stuck here and I cannot see where my error might be. Is it possible I’ve corrupted something?

Thanks

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [August 22, 2018, 4:39pm UTC](https://forums.losant.com/t/invalid-context/1085/4 "2018-08-22T16:39:53Z")

</div>

Are there other context variables on that dashboard that are not being shown in your screenshot?

---

<div class="post-metadata">

**Author:** ![paul\_wareham](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@paul\_wareham](https://forums.losant.com/u/paul_wareham)\
**Post date:** [August 22, 2018, 4:43pm UTC](https://forums.losant.com/t/invalid-context/1085/5 "2018-08-22T16:43:49Z")

</div>

No, that’s what driving me a bit nuts.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/1X/2ca5baf706390e1516e2d9e9ee70a2ccd89c9c43.png)

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [August 22, 2018, 4:52pm UTC](https://forums.losant.com/t/invalid-context/1085/6 "2018-08-22T16:52:45Z")

</div>

It looks like the value you’re providing to the context variable is invalid (likely null or undefined). You can check this by inspecting your render log on the top-right of the page. When you request the page, a render log entry will be displayed. Check what’s actually in `pageData.data.params.deviceId`.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/1X/49cc8a85cd7781996e3d3ac1cea4f6f74605cece.png)

---

<div class="post-metadata">

**Author:** ![paul\_wareham](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@paul\_wareham](https://forums.losant.com/u/paul_wareham)\
**Post date:** [August 22, 2018, 5:19pm UTC](https://forums.losant.com/t/invalid-context/1085/7 "2018-08-22T17:19:10Z")

</div>

Yes that was true, it was empty although that never caused me such an error in the past - it just remain as an empty parameter and not be used.

However, I have now deleted the context variables from the Dashboard completely, so there are none. Yet the Invalid Context error message persists. I have flushed the cache and tried a different browser on a different device with the same result.

It almost seems like the platform is remembering a previous error associated with that page.

---

<div class="post-metadata">

**Author:** ![paul\_wareham](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@paul\_wareham](https://forums.losant.com/u/paul_wareham)\
**Post date:** [August 24, 2018, 9:03pm UTC](https://forums.losant.com/t/invalid-context/1085/8 "2018-08-24T21:03:07Z")

</div>

Hey Brandon,

On the context variable example you gave, I wondering if you could show the other half of the example that shows how the associated dashboard is configured with the ctx.allDevices tag?

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [August 25, 2018, 4:05am UTC](https://forums.losant.com/t/invalid-context/1085/9 "2018-08-25T04:05:13Z")

</div>

Sure thing. Here’s the dashboard settings:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/1X/f84a75f6de0f60d0ab2bce3be4a62bf62018bf90.png)

The expanded context variable is a device tag. In this example, I’m using tags to associate experience users with devices. The tag values are `experience_user_id=true`. This way I can query all devices by the experience user’s ID to know which ones they are allowed to view.

I then use the tag on a GPS History Block to view the current location of every device that user is allowed to see.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/1X/e4d95e9a04719254e46e11d9485d1a42f0698985.png)

So now, when any user logs in and views the experience dashboard page, their ID is passed as the device tag context variable and only their devices will be displayed.
