Skip to:
Content

BuddyPress.org

Opened 4 months ago

Closed 3 months ago

#8537 closed defect (bug) (fixed)

Updating profile fields of type "Checkbox" using BuddyPress API not working

Reported by: niftythree Owned by: espellcaste
Milestone: 10.0.0 Priority: normal
Severity: normal Version: 9.0.0
Component: REST API Keywords:
Cc:

Description

I’m working on a mobile app to interface with a BuddyPress 9.0.0 website via the BP API. The website has some profile 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 field of check boxes called “Pets” under which the user can select one or more of the specified check boxes such as “Dog”, “Cat”, “Cow”, etc.

I'm trying to update these fields 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)

A sample of the JSON in the body of my call is

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

As mentioned, 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.

Steps to reproduce;

  • Log into WP dashboard as admin
  • Navigate to Users > Profile Fields
  • Add a new field using the "Add New Field" button
  • From the Type category, choose "Checkboxes"
  • Create a few check boxes, and save
  • Use Postman to log into the website
  • Try and set any of the newly created check boxes using the “/buddypress/v1/xprofile/<field_id>/data/<user_id>” endpoint (ref. BP API documentation for more info).

Here is a screenshot of Postman when trying to update a "textbox" field (successfully updates) https://i.stack.imgur.com/XZgZH.png

Here is a screenshot of Postman when trying to update a "checkbox" field (doesn't update, just clears the existing data instead) https://i.stack.imgur.com/zz5Uu.png

Change History (10)

#1 @niftythree
4 months ago

  • Summary changed from BuddyPress API not setting to BuddyPress API issue setting fields of type "Checkbox"

#2 @niftythree
4 months ago

  • Summary changed from BuddyPress API issue setting fields of type "Checkbox" to Setting profile fields of type "Checkbox" via BP API not working

#3 @niftythree
4 months ago

  • Summary changed from Setting profile fields of type "Checkbox" via BP API not working to Updating profile fields of type "Checkbox" using BuddyPress API not working

#4 @espellcaste
4 months ago

  • Milestone changed from Awaiting Review to 10.0.0
  • Owner set to espellcaste
  • Status changed from new to assigned

Tks for the ticket and for the steps. I'm gonna try to replicate that.

#5 @niftythree
4 months ago

Thank you @espellcaste!

#6 @espellcaste
4 months ago

I was able to confirm this issue and have a patch incoming. :)

#7 follow-up: @espellcaste
4 months ago

@niftythree I have a patch ready.

Would you mind testing it, https://github.com/buddypress/BP-REST/pull/420?

#8 in reply to: ↑ 7 @niftythree
4 months ago

Replying to espellcaste:

@niftythree I have a patch ready.

Would you mind testing it, https://github.com/buddypress/BP-REST/pull/420?

Thanks for following this up @espellcaste. Unfortunately we're new at working with the source of WordPress/BuddyPress so I'm not sure how to test this (is there a guide you could point us to?). We'll take your word that it works!

#10 @espellcaste
3 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

The code was merged at the BP REST API plugin, https://github.com/buddypress/BP-REST/pull/420, and will be bundled together with BuddyPress 10.0.0.

Resolving ticket! :)

Note: See TracTickets for help on using tickets.