Custom Fields
Re-Envisioned
Support MB REST API Expected Behavior on Incorrect Keys during POST requests

  • Creator
    Topic
  • #28953
    Austin Passy
    Participant

    I noticed that if an incorrect key is sent to a post or custom post type (in the meta_box object) that (in our case got removed before we finalized our Schema) a fatal error is thrown.

    This happens in MB_Rest_API::update_post_meta since rwmb_get_registry( 'field' )->get( $field_id, $object->post_type ) in the array loop is false and there for throws the error when passed to $this->update_value( $field, $value, $object->ID ).

    In the JSON spec it refers to returning an error response for invalid parameters: https://jsonapi.org/examples/#error-objects-invalid-query-parameters

    Would like to discuss options, as I continue to investigate from my side as well.

    The following would be the example curl (where we removed removedKey):
    curl --location --request POST 'https://wp.test/wp-json/wp/v2/customPostType' \
    --header 'Accept: */*' \
    --header 'Accept-Encoding: gzip, deflate, br' \
    --header 'Cache-Control: no-cache' \
    --header 'Connection: keep-alive' \
    --header 'Content-Type: application/json' \
    --header 'Authorization: Basic SOMEKEY' \
    --data-raw '{
    "title": "Testing",
    "meta_box": {
    "removedKey": true,
    "requiredEquipment": [],
    "recommendedEquipment": []
    },
    "status": "publish"
    }'
    <code></code>

Viewing 1 replies (of 1 total)
  • Author
    Replies
  • #28977
    Long Nguyen
    Moderator

    Hi Austin,

    Thank you for your feedback.

    I will inform the development team to check this case and get back to you if I have any information.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.