How to use API key in AJAX call?

The key piece of info that I want is whether the user is a group owner or not of the group. This information is returned by the Json API. So when a user goes to a particular page, I want to send a call to the API to get back information about a group, which in the basic response includes whether the user logged into the client is an owner.

This seems like a straight forward implementation of the API. It seems, however, that this operation requires an API key, but the method that I’ve used so far is not working.

I don’t think that creating a separate plug-in or theme component is required here, as this operation is one of the basic ones the Json API provides.

Curious if there is a way to use the API with a key that wouldn’t expose the key (ie, what would be the standard/best practice way to use the API).

EDIT: If for some reason this is not appropriate for the API call, then yes it would have to get serialized. Does anyone have working code for that? I understand that there is an add_to_serializer method, but I haven’t gotten the syntax to quite work, and have struggled to find working examples of method.

1 Like