Customer / user API no longer returning meta box json
Support › MB REST API › Customer / user API no longer returning meta box jsonResolved
- This topic has 3 replies, 2 voices, and was last updated 2 years, 4 months ago by
Peter.
-
AuthorPosts
-
June 6, 2023 at 4:00 AM #42080
MadtownChris
ParticipantPreviously, we used the following code to retrieve JSON data from a user / WC customer via our custom rest route:
$rest_controller = new WC_REST_Customers_Controller(); $response = $rest_controller->prepare_item_for_response($user, $request); $response_data = $response->get_data(); $response->set_data($response_data); return $response;There's some more code but that's the basic bit. Until a few weeks (not sure how long) ago this returned our custom field group as a top-level item in the json. Something like what's shown below where field_group is the name of the field group and it contained all of the metabox data within that field group.
Now, we get nothing at all from the metabox data. We still get all the rest of the expected user/customer information. I suppose this could be a change in the WC_REST_Customers_Controller. But if you have made REST API changes, then perhaps this is related.
{... stuff ... "email": "[email protected]", "first_name": "Chris", "id": 110, "is_paying_customer": true, "field_group": [ "person": { "name": "dave" }, ... etc.. ] }We do pay for a license (not sure what email it's under - could be this one).
Thanks.
Chris
June 7, 2023 at 8:36 PM #42102Peter
ModeratorHello Chris,
Follow the documentation https://docs.metabox.io/extensions/mb-rest-api/
please check the Rest API URL and see if the custom fields display under themeta_boxkey. If yes, I think MB Rest API works properly.June 8, 2023 at 6:16 AM #42118MadtownChris
ParticipantIt turns out that previously, the API was sending back meta box data as meta_data like this:
"meta_data": [ { "id": "2", "key": "profile_dob", "value": "5/11/1989" }, { "id": "3", "key": "profile_gender", "value": "Male" } ]Now it sends it like this:
"meta_box": { "profile_dob": "5/11/1989", "profile_gender": "Male" }Although the second way would be much easier to handle, consumers of the data need to be updated which can be painful.
I worked around it at the server side by changing the response to suit the older style but that's not ideal. I'm curious that nobody noticed this since it would likely break clients.
June 8, 2023 at 10:28 PM #42127Peter
ModeratorHello,
I'm not sure what version of MB Rest API you used before but as far as I know, MB Rest API returns the field values under the
meta_boxkey for years. The keymeta_datamight come from another plugin that supports Rest API, not MB Rest API. -
AuthorPosts
- You must be logged in to reply to this topic.