Title: REST API Update field
Last modified: August 30, 2023

---

# REST API Update field

 *  Resolved [Julian Holzmayer](https://wordpress.org/support/users/julholdroid/)
 * (@julholdroid)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/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:
 *     ```wp-block-code
       $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:
 *     ```wp-block-code
       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:
 *     ```wp-block-code
       {
           "code": "cmb2_rest_no_field_by_id_error",
           "message": "No field found by that id.",
           "data": {
               "status": 403
           }
       }
       ```
   
 * My POST body is:
 *     ```wp-block-code
       {
           "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.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [Justin Sternberg](https://wordpress.org/support/users/jtsternberg/)
 * (@jtsternberg)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/rest-api-update-field/#post-17012458)
 * See the REST API docs. It covers these routes and what the object_type is. If
   you still run into issues, let us know. 
   [https://github.com/CMB2/CMB2/wiki/REST-API#routes](https://github.com/CMB2/CMB2/wiki/REST-API#routes)
 *  Plugin Author [Justin Sternberg](https://wordpress.org/support/users/jtsternberg/)
 * (@jtsternberg)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/rest-api-update-field/#post-17012471)
 * Sorry, one last look at your payload and it looks correct except that you’re 
   passing in the body instead of query args. Try following the recommendation in
   the docs with the query args.
 *  Thread Starter [Julian Holzmayer](https://wordpress.org/support/users/julholdroid/)
 * (@julholdroid)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/rest-api-update-field/#post-17012649)
 * Thanks you for your reply.
 * Unfortunately i still get the same error, making a POST Request without any body
   to this route: 
   /wp-json/cmb2/v1/boxes/hd-object-viewer-mb/fields/hd-object-viewer-
   mb-scene-json?object_id=49&value=other&object_type=postI use Postman to make 
   the request and the id of the post where i want to change the metafield is 49.
 * For Authtentication i created a application password for the admin user and passed
   it with Basic Auth like mentioned [here](https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/#basic-authentication-with-application-passwords)
   in the request
 * Ah and by the way i use:
    - WP: 6.3.1
    - CMB2 installed via composer inside my own plugin: “cmb2/cmb2”: “^2.10”
 *  -  This reply was modified 2 years, 9 months ago by [Julian Holzmayer](https://wordpress.org/support/users/julholdroid/).
    -  This reply was modified 2 years, 9 months ago by [Julian Holzmayer](https://wordpress.org/support/users/julholdroid/).
    -  This reply was modified 2 years, 9 months ago by [Julian Holzmayer](https://wordpress.org/support/users/julholdroid/).
 *  Plugin Author [Justin Sternberg](https://wordpress.org/support/users/jtsternberg/)
 * (@jtsternberg)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/rest-api-update-field/#post-17016713)
 * When testing this in my API app, Insomnia, I was seeing this same behavior (the
   POST request not updating the field). It turned out it was because I was using
   the wrong url (in my case `http` instead of `https` and the server was doing 
   a redirect and changing to a `GET`).
   See screenshot here: [https://a.supportally.com/i/hBDQ9a](https://a.supportally.com/i/hBDQ9a)
   Check to see if you’re experiencing the same.
 * You could also add some logging to your server to see what the request method
   is when it lands there. E.g.
   `error_log( '$_SERVER[REQUEST_METHOD]: ' . print_r(
   $_SERVER['REQUEST_METHOD'], true ) );`
 *  Thread Starter [Julian Holzmayer](https://wordpress.org/support/users/julholdroid/)
 * (@julholdroid)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/rest-api-update-field/#post-17016860)
 * Hello Justin, this did’t solve my problem (there was no redirect at my request
   happening. So the method allways was POST).
 * As my plugin’s use case changed I don’t need the REST API anymore.
 * But thank you anyway for looking into the problem.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘REST API Update field’ is closed to new replies.

 * ![](https://ps.w.org/cmb2/assets/icon.svg?rev=2866672)
 * [CMB2](https://wordpress.org/plugins/cmb2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cmb2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cmb2/)
 * [Active Topics](https://wordpress.org/support/plugin/cmb2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cmb2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cmb2/reviews/)

## Tags

 * [rest](https://wordpress.org/support/topic-tag/rest/)
 * [update](https://wordpress.org/support/topic-tag/update/)

 * 5 replies
 * 2 participants
 * Last reply from: [Julian Holzmayer](https://wordpress.org/support/users/julholdroid/)
 * Last activity: [2 years, 9 months ago](https://wordpress.org/support/topic/rest-api-update-field/#post-17016860)
 * Status: resolved