Customer / user API no longer returning meta box json

Support MB REST API Customer / user API no longer returning meta box jsonResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #42080
    MadtownChrisMadtownChris
    Participant

    Previously, 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

    #42102
    PeterPeter
    Moderator

    Hello 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 the meta_box key. If yes, I think MB Rest API works properly.

    #42118
    MadtownChrisMadtownChris
    Participant

    It 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.

    #42127
    PeterPeter
    Moderator

    Hello,

    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_box key for years. The key meta_data might come from another plugin that supports Rest API, not MB Rest API.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.