How do I update an XProfile “checkbox” type field via BuddyPress API?

I’m working on a mobile app to interface with a BuddyPress 9.0.0 website via the BP API. The website has some xprofile parent fields of the “checkbox” type, each with a set of “options” which the user can set to be true or false. For example, there is a parent called “Pets” under which the user can select one or more of the specified check boxes such as “Dog”, “Cat”, “Cow”, etc.

I am having trouble trying to update this type of “checkbox” field using Postman. The update works fine for fields of type “textbox” and “selectbox”, but doesn’t work for the “checkbox” type.

The endpoint is “/buddypress/v1/xprofile/field_id/data/user_id” (POST operation, here the field_id I am using is the id of the parent field)

The JSON in the body of my call is

{ “context” : “edit”, “value”: [“Dog”, “Cat”]}

As mentioned before, if I try the same post call with a field of type “textbox” or “selectbox”, it works fine, but if I post to a “checkbox” field it just clears the existing data and does not set it to the new values.

Here is a screenshot of Postman when trying to update a textbox field (successfully updates)

Here is a screenshot of Postman when trying to update a checkbox field (doesn't update, just clears the existing data instead)

Topic wp-api rest-api buddypress Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.