Invalid Context

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?

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.

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.

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.

However, that is triggering the error:
image

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

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

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

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.

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.

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?

Sure thing. Here’s the dashboard settings:

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.

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.