execute Custom query via rest service

benyamin jain asked on September 7, 2016 16:42

hi

How it is possible to execute Custom Query via Rest service?

any one can provide a sample?

at this time when i want to use rest for macro it always log security error in event log , event with global administrator credentials.

Correct Answer

Martin Hejtmanek answered on September 8, 2016 11:55

Hi, the security measures of the macros are still applied as anywhere else in the system when submitting a macro, so if you use macro that needs to check security, you would also have to provide it with proper signature, which would complicate things. And even if you could get the query text, you cannot execute query through macro unless you provide some custom method that would do that for you. You basically have two options:

  1. Use WebAPI instead of the REST, which I would recommend, as it is much more flexible for such custom calls, see https://docs.kentico.com/display/K9/Using+ASP.NET+Web+API+with+Kentico

  2. Or provide a custom macro method that you query through macro end point, this makes the macro simple enough (just the method call) to skip the default security check and leave it on your method. See https://docs.kentico.com/display/K9/Registering+custom+macro+methods Note that it may be harder for you to match the data format required by the REST implementation to properly serialize it, so I still recommend option 1 as easier way how to do that.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Trevor Fayas answered on September 7, 2016 17:38

You shouldn't have any problem in creating a REST service and performing any logic. I do something similar to start off an asynchronized task when a user logs in.

Can you provide some info on the security log error? I have a feeling it's not the ability to do this that's the issue, but an error in setting up the environment.

0 votesVote for this answer Mark as a Correct answer

benyamin jain answered on September 8, 2016 09:34

Hi this error loged when i want to execute Macro.

Security check of the expression 'Queries["customtable.SampleTable.deleteall"].QueryText' didn't pass. The expression was signed by user ''. Remove the signature and re-save the expression by a user with proper permissions.

as I know it is not possible to execute custom query using rest request , the suggested way is using Macro.

0 votesVote for this answer Mark as a Correct answer

Richard Sustek answered on September 8, 2016 11:55

How does the macro you are executing look like?

0 votesVote for this answer Mark as a Correct answer

benyamin jain answered on September 8, 2016 17:19

Richard Sustek

macro never get executed because of security considerations.

0 votesVote for this answer Mark as a Correct answer

benyamin jain answered on September 8, 2016 17:28

Martin Hejtmanek

Thank you for the solution , first , unfortunately i am using version 7 , the second is i am writing my test application before make consider more about solutions.

my windows app use rest API to connect my web application for data management.

By using rest i am forced to call rest multiple times.

for example to delete a record from one table and insert that record to another one.

However i found your suggestion better to use.

With Best Regards

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.