Skip Navigation

[Closed] How can we modify toolset-meta fields via the API?

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 3 replies, has 3 voices.

Last updated by Christopher Amirian 1 year, 8 months ago.

Assisted by: Christopher Amirian.

Author
Posts
#2696978

We're trying to automate the transfer of data from Hubspot to WordPress via Zapier. We've created "partners" in our WordPress app, which we create by posting to:

hidden link

We're passing the data in the request like this:

"data": {
"title": "title",
"content": "content",
"meta": {
"_seopress_titles_title": "testing meta field"
},
"toolset-meta": {
"partners": {
"partner-name": {
"type": "textfield",
"raw": "Joe Smith"
}
}
}
}

Everything will get updated except for the toolset-meta fields, that will return in the response as:

"toolset-meta": {
"field-group-for-partners-2": [],
"partners": {
"partner-name": {
"type": "textfield",
"raw": ""
}
}

Do we need to do something special to make these fields writable via the API?

We tried using register_meta, but, that obviously just makes identically named fields become writable in the meta hash, but doesn't allow us to modify the values in toolset-meta.

#2697002

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

The REST API add-on for Types is used to expose the formatted values of Types custom fields to REST read requests.

Types custom fields are regular custom fields, i.e. stored in wp_postmeta, accessible via the normal WordPress functions such as update_post_meta and get_post_meta, with one proviso: the meta_key is the Types field slug with a 'wpcf-' prefix (e.g. a 'priority' custom field is stored with a meta_key of 'wpcf-priority).

Many fields which are stored as simple text. Some have formatting options when they are output by types shortcodes (or, now, using blocks), e.g. to output a date field in a specified date format.

The fields are always accessible (and writable) in the same way as standard post meta, including when using the REST API, so if you need to update custom fields via REST, that's the way to go.

#2697177

When testing I don't see any of the wpcf- prefixed keys coming back, do we need to register them?

For example, to update the value "partner-name" would we have to do something like this:

register_meta('post', 'wpcf-partner-name', array(
'object_subtype' => 'partner',
'show_in_rest' => true,
'single' => true,
'type' => 'string',
'auth_callback' => function() {
return current_user_can('edit_posts');
}
));

#2697288

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

The Toolset custom fields are exactly like WordPress default ones, so if for the default custom fields you will need the register_meta then for Toolset fields you also need that.

Here is our official documentation for REST API:

https://toolset.com/documentation/programmer-reference/toolset-integration-with-the-rest-api/

Thanks.

The topic ‘[Closed] How can we modify toolset-meta fields via the API?’ is closed to new replies.