Hi there
Christopher asked me to step in here and help.
The previous sandbox site has expired, so I created a new one to demonstrate what is involved to enable updating Toolset custom fields via REST API POST requests.
Most of what is involved is uses vanilla WordPress REST API concepts, but there are a couple of things particular to Toolset that I will highlight.
First, to re-iterate, the Toolset REST API integration relates only to retrieving custom fields (formatted), not for updating them. To update custom fields you will be using the regular WordPress REST API routes, working with raw field values (as stored in wp_postmeta).
One thing to be aware of is that Toolset custom fields are stored in wp_postmeta with a 'wpcf-' prefix, which you will need to use in the REST API, so if you had a custom field with a slug of 'priority' then its metakey would be 'wpcf-priority'.
When you create custom fields in Toolset they are not registered as being available in the REST API by default, and so you must update the settings for the fields you want to expose to the REST API via the WordPress function register_meta.
Use this link to log in to the new sandbox site: hidden link
I have registered a custom post type "Things", and added two custom fields to it: "choices" and "text-address".
Go to Toolset > Settings > Custom Code and you will see there is an active code snippet which updates the options for these two post types using the register_meta function to make them available in the REST API (and also to specify the fields would only have a single value).
Here's the code for the "choices" custom field:
// Register custom fields as available in REST API
register_meta(
'post',
'wpcf-choices', // meta key of Types custom fields includes a wpcf- prefix
[ 'show_in_rest' => true,
'single' => true
]
);
You can check the REST API is working (use whatever tool suites; I tested with the online test tool reqbin.com) with a simple GET request such as to this endpoint:
<em><u>hidden link</u></em>
That should return JSON data for the "Something" post (post ID 15).
To make a POST request to a similar route to update post data it is necessary to make authenticated requests.
For the purposes of testing I added a Basic Auth plugin to the site so that you can make requests with the username and password of an admin user. For testing I added such as user to this site: otgsuser / otgspass.
You can then make an authenticated POST request where the post body includes the data to be updated, like so:
{"meta": {
"wpcf-choices": "2",
"wpcf-text-address":"2 Main Street\nThe City\nNowhereland\n"
}}
That will update the "choices" field value to "2". Choices is a select custom field, where the option with value 2 has a label "Second choice".
The "text-address" field is a multiline text field.
You can see in the screenshot me making a request to update post 18 ("Nothing") to provide values for the custom fields, and the response shows that the post has been updated with those values.
The only point in the above that is specific to Toolset is the 'wpcf-' prefix used for custom field meta keys, but don't forget to update the custom field options to show_in_rest using the register_meta WordPress function.