Hi. I have on-premise Squidex installation with a Angular / .NET Core UI using Content API.
I’m trying to implement a functionality which would increment a counter on content in CMS
with every opening its representation in UI. As I read in documentation, “Query script is
executed whenever a content item is queried with the API”, so I tried to create something
like this:
var pop = ctx.data.popularity.iv;
ctx.data.popularity.iv = pop + 1;
replace();
where ‘popularity’ is a field on schema type Number, but it doesn’t seem to work -
meaning, that ‘popularity’ field doesn’t get changed. What am I doing wrong?
Can really Query script react on such “querying” content item through API or am I getting it wrong?
Maybe there is a better way to record number of content items reads through API?
It works totally fine for me. My query is exactly like yours.
Which token do you use in postman? The token from the UI is your personal access token that has the information that it is used by the API. So you have to use the token from the clients page.
Go to Settings -> Clients -> Connect -> Connect manually.
Yes, in Postman I’m using token taken from: Settings -> Clients -> Connect -> Connect manually
Just to clarify - when I perform query using Postman (with a token like above), to GET data from
specific item in Squidex CMS, the Query (in Scripts) should be executed and, in your example,
writes number (‘42’) to the field ‘number’ on specific content item? Do I get it right??
For me, it still doesn’t work. I’m curious about the topic of tokens in general - you mentioned that
“The token from the UI is your personal access token” - in the front-end part of our software
(using the API), we also use a token from: Settings -> Clients -> Connect -> Connect manually.
Isn’t that correct?