Forum Discussion

PerihanKamel's avatar
PerihanKamel
Contributor
4 years ago

How can we make calls as admin in javascript?

Hello everyone,

Question:

Some APIs are called using FreeMarker by restadmin or restbuilder using .admin(true) so how can we achieve the same functionality using javascript?

Background:
We want to create message using javascript for saving user comments to a forum. However, the user doesn't usually have the permission to add message to the forum.

 

Thanks in advance,

Perihan Kamel

 

  • Hi PerihanKamel,

    In this situation wouldn't it make sense to instead pass what will become the message body via Ajax to a custom endpoint and then leverage the restadmin directive within the endpoint to create the message?

    That's what seems the most straightforward to me but maybe I'm not understanding the full context.

    (Of course, if the user doesn't have access to the destination forum then I'm not sure if the API call will be successful or if it'll return with a permissions-related error even when using the restadmin directive.  If it is the latter, then you may need to create the message with a service account as the author that does have access to that location, if that makes sense.)

    Thanks!
    Jeff

    Edit: Clarification in last paragraph