REST API Update field
-
Hello guys,
I have a question according to the REST API for updating a cmb2 field value.This is the code for the registration of he field and the box:
$cmb = new_cmb2_box( array( 'id' => 'hd-object-viewer-mb', 'title' => __( '3D View Scene', 'hd-3d-viewer' ), 'object_types' => array( 'hd-object-viewer' ), 'context' => 'normal', 'priority' => 'high', 'show_names' => true, 'show_in_rest' => true ) ); $cmb->add_field( array( 'name' => 'Test Text Area', 'desc' => 'This is the json data', 'id' => 'hd-object-viewer-mb-scene-json', 'type' => 'textarea', 'sanitization_cb' => false, 'escape_cb' => false, ) );
I registerd my CPT like this:
register_post_type( 'hd-object-viewer', array( 'label' => __( '3D View', 'hd-3d-viewer' ), 'description' => 'Recipe custom post type.', 'public' => true, 'exclude_from_search' => true, 'show_in_rest' => true, 'supports' => array( 'title' ), 'menu_icon' => 'dashicons-admin-site', ) );
I now want to update the field via the REST API. When i make a GET Request to /wp-json/cmb2/v1/boxes/hd-object-viewer-mb/fields/hd-object-viewer-mb-scene-json i get the field back (so the field is registered in the API)
But when i do a POST request to the same URL i get an error:{ "code": "cmb2_rest_no_field_by_id_error", "message": "No field found by that id.", "data": { "status": 403 } }
My POST body is:
{ "object_id": 49, "value": "other value test", "object_type": "post" }
I also tried it with the “
hd-object-viewer
” (CPT) object_type which results in the same error.What is the object_id anyways. I considered it as the post id, maybe this is not correct.
For Authentication i used a Application password with my admin User, so i am pretty sure i am authenticated at it would say otherwise. Maybe i don’t have the permission to change the metafield, which would be weird as this is the application password for the admin user.
Any help would be appreciated.
Thanks in Advance.
- The topic ‘REST API Update field’ is closed to new replies.