Home › Toolset Professional Support › [Resolved] What does the json request look like to update custom field values?
Problem:
How to add or edit Toolset custom fields via REST API?
Solution:
Toolset custom fields use the native WordPress methods and you would do the same steps like you want to edit a native WordPress custom field.
The only difference is that in the native WordPress functions you should add the "wpcf-" prefix to the Toolset custom fields names.
Relevant Documentation:
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 23 replies, has 3 voices.
Last updated by Christopher Amirian 1 year, 6 months ago.
Assisted by: Christopher Amirian.
Tell us what you are trying to do? I am trying to figure out what the json should look like to update custom fields.
Is there any documentation that you are following?
I am referencing this post here:
https://toolset.com/forums/topic/update-post-cuszom-fields-with-rest-api/#post-1430893
And documentation here:
https://toolset.com/documentation/programmer-reference/toolset-integration-with-the-rest-api/?utm_source=plugin&utm_campaign=types&utm_medium=gui&utm_term=rest-api-integration
Is there a similar example that we can see? This is from my last attempt at guessing the json format:
{
"status": "publish",
"title": "The Salvation Army College for Officer Training Eastern Territory",
"toolset-meta": {
"institutions-custom-fields": {
"wpcf-address":{
"raw":"99999 Lafayette Avenue"
}
}
}
}
What is the link to your site?
hidden link
Hi there,
The field name should not have the wpcf prefix in the JSON File:
Each property of this object is named by custom field slugs and not meta_keys. This means that they do not contain the wpcf prefix
The field misses the "type" entry in JSON which is mandatory.
You can refer to the JSON code mentioned in the documentation you referenced:
Thanks.
Hi Christopher,
Thank you for the response, I made the changes you mentioned and tried again but did not have success. Here's my latest JSON request..
{
"id":5495,
"status": "publish",
"title": "The Salvation Army College for Officer Training Eastern Territory",
"type" : "institution",
"toolset-meta": {
"institutions-custom-fields": {
"address":{
"type":"textfield",
"raw":"99999 Lafayette Avenue"
}
}
}
}
Should "institutions-custom-fields" be the name of the Post Type (the name of the post type is Institutions) or the Custom Field Group (the name of the group is Institutions Custom Fields)?
Hi there,
The custom post type should not be used under Toolset meta as it is not related to Toolset in this scenario. Toolset uses Custom Post type functions of original WordPress, so whatever you do to retrieve the custom post type is what you already do with native WordPress.
The only thing Toolset does is to add an additional field called "toolset-meta" which will list the custom field groups that are assigned to that specific post which is retrieved by WordPress and the fields inside them.
So for your scenario:
"toolset-meta": { "institutions-custom-fields": { "address":{ "type":"textfield", "raw":"99999 Lafayette Avenue" } } }
"institutions-custom-fields" is the name of the Field Group.
"address" is the slug of the field inside that field group
"textfield" is the type of that field
"raw" is the value of that field
I suggest that you pick a post and see the result of the rest API of that post to see exactly what Toolset prints, instead of adding the data, check the output of data to see what should be the correct format on your scenario.
Thanks.
Hi Christopher,
Thank you for the response. Here is a little more insight into what we are trying to do. We are trying to integrate the Insitution fields in WordPress with matching fields in our Salesforce.com instance. The way that the relationship needs to work is when Institution information is updated in Salesforce.com, we then want that information to flow into WordPress. So in the JSON above, if the Address of an institution changes in Salesforce.com, then we want to update that address for the same institution in WordPress.
Is this possible?
When you say "pick a post", are you referring to the endpoint url? If so, do you have any suggestions in mind?
Would you be able to join a Zoom meeting to help us work through this?
Hi there,
That requirement is well beyond the scope of our support and is considered a customization you can find the qualified list of developers to hire here:
https://toolset.com/contractors/
I hope you understand.
Hi Christopher,
Thank you for the response. We are currently developing the solution. The format of the JSON request to update the fields in WordPress is what we are trying to figure out. If you can help at all there it would be much appreciated.
Hi there,
As mentioned the best way to see what should be the correct JOSON, is to actually see what is generated by WordPress itself for a page.
So like the method below that yu would use normally to get the WordPress post information:
https://stackoverflow.com/questions/67423073/how-to-get-particular-posts-detail-via-wp-rest-api
There you will see the correct format of the JSON. Use a post that you already applied Toolset fields to it and added some values to see what JSON correct format is.
Then you can use the same format for the other parts of your development process.
Thanks.
Hi Christopher, I do have the JSON response and it looks exactly like the JSON you provided above. When I utilize that exact format, the non-toolset fields are updated correctly, and nothing happens to the toolset custom fields. There are no errors thrown, but the data is not updated. Here's the example, and when the JSON is returned from the call, it looks exactly like this but the Raw attribute remains blank, and the field is blank as well.
POST:
{
"id":5682,
"status": "publish",
"title": "Fifth Institution",
"toolset-meta": {
"institutions-custom-fields": {
"address":{
"type":"textfield",
"raw":"a"
}
}
}
}
RESPONSE:
{
"id": 5682,
"date": "2023-10-18T11:58:56",
"date_gmt": "2023-10-18T18:58:56",
"guid": {
"rendered": "hidden link",
"raw": "hidden link"
},
"modified": "2023-10-25T12:47:49",
"modified_gmt": "2023-10-25T19:47:49",
"password": "",
"slug": "5682",
"status": "publish",
"type": "institution",
"link": "hidden link",
"title": {
"raw": "Fifth Institution",
"rendered": "Fifth Institution"
},
"comment_status": "0",
"ping_status": "closed",
"template": "",
"permalink_template": "hidden link",
"generated_slug": "fifth-institution",
"cp_meta_data": {
"_wpv_contains_gutenberg_views": [
""
],
"_fusion": [
"a:0:{}"
],
"_edit_lock": [
"1697745222:298"
]
},
"yoast_head": "<!-- This site is optimized with the Yoast SEO plugin v21.2 - hidden link -->\n<title>Fifth Institution - ACCJC</title>\n<!-- Admin only notice: this page does not show a meta description because it does not have one, either write it for this page specifically or go into the [Yoast SEO - Settings] menu and set up a template. -->\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" />\n<link rel=\"canonical\" href=\"hidden link\" />\n<meta property=\"og:locale\" content=\"en_US\" />\n<meta property=\"og:type\" content=\"article\" />\n<meta property=\"og:title\" content=\"Fifth Institution - ACCJC\" />\n<meta property=\"og:url\" content=\"hidden link\" />\n<meta property=\"og:site_name\" content=\"ACCJC\" />\n<meta property=\"article:modified_time\" content=\"2023-10-25T19:47:49+00:00\" />\n<meta name=\"twitter:card\" content=\"summary_large_image\" />\n<script type=\"application/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"hidden link\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"hidden link\",\"url\":\"hidden link\",\"name\":\"Fifth Institution - ACCJC\",\"isPartOf\":{\"@id\":\"hidden link\"},\"datePublished\":\"2023-10-18T18:58:56+00:00\",\"dateModified\":\"2023-10-25T19:47:49+00:00\",\"breadcrumb\":{\"@id\":\"hidden link\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"hidden link\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"hidden link\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"hidden link\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Institutions\",\"item\":\"hidden link\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Fifth Institution\"}]},{\"@type\":\"WebSite\",\"@id\":\"hidden link\",\"url\":\"hidden link\",\"name\":\"ACCJC\",\"description\":\"Accrediting Commission for Community and Junior Colleges\",\"publisher\":{\"@id\":\"hidden link\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"hidden link{search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"hidden link\",\"name\":\"ACCJC - Accrediting Commission for Community and Junior Colleges\",\"url\":\"hidden link\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"hidden link\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"ACCJC - Accrediting Commission for Community and Junior Colleges\"},\"image\":{\"@id\":\"hidden link\"}}]}</script>\n<!-- / Yoast SEO plugin. -->",
"yoast_head_json": {
"title": "Fifth Institution - ACCJC",
"robots": {
"index": "index",
"follow": "follow",
"max-snippet": "max-snippet:-1",
"max-image-preview": "max-image-preview:large",
"max-video-preview": "max-video-preview:-1"
},
"canonical": "hidden link",
"og_locale": "en_US",
"og_type": "article",
"og_title": "Fifth Institution - ACCJC",
"og_url": "hidden link",
"og_site_name": "ACCJC",
"article_modified_time": "2023-10-25T19:47:49+00:00",
"twitter_card": "summary_large_image",
"schema": {
"@context": "hidden link",
"@graph": [
{
"@type": "WebPage",
"@id": "hidden link",
"url": "hidden link",
"name": "Fifth Institution - ACCJC",
"isPartOf": {
"@id": "hidden link"
},
"datePublished": "2023-10-18T18:58:56+00:00",
"dateModified": "2023-10-25T19:47:49+00:00",
"breadcrumb": {
"@id": "hidden link"
},
"inLanguage": "en-US",
"potentialAction": [
{
"@type": "ReadAction",
"target": [
"hidden link"
]
}
]
},
{
"@type": "BreadcrumbList",
"@id": "hidden link",
"itemListElement": [
{
"@type": "ListItem",
"position": 1,
"name": "Home",
"item": "hidden link"
},
{
"@type": "ListItem",
"position": 2,
"name": "Institutions",
"item": "hidden link"
},
{
"@type": "ListItem",
"position": 3,
"name": "Fifth Institution"
}
]
},
{
"@type": "WebSite",
"@id": "hidden link",
"url": "hidden link",
"name": "ACCJC",
"description": "Accrediting Commission for Community and Junior Colleges",
"publisher": {
"@id": "hidden link"
},
"potentialAction": [
{
"@type": "SearchAction",
"target": {
"@type": "EntryPoint",
"urlTemplate": "hidden link{search_term_string}"
},
"query-input": "required name=search_term_string"
}
],
"inLanguage": "en-US"
},
{
"@type": "Organization",
"@id": "hidden link",
"name": "ACCJC - Accrediting Commission for Community and Junior Colleges",
"url": "hidden link",
"logo": {
"@type": "ImageObject",
"inLanguage": "en-US",
"@id": "hidden link",
"url": "",
"contentUrl": "",
"caption": "ACCJC - Accrediting Commission for Community and Junior Colleges"
},
"image": {
"@id": "hidden link"
}
}
]
}
},
"toolset-meta": {
"field-group-for-institutions-2": [],
"field-group-for-institutions": [],
"institutions-custom-fields": {
"college": {
"type": "textfield",
"raw": ""
},
"president-title-update": {
"type": "textfield",
"raw": ""
},
"president-name": {
"type": "textfield",
"raw": ""
},
"address": {
"type": "textfield",
"raw": ""
},
"city": {
"type": "textfield",
"raw": ""
},
"state": {
"type": "textfield",
"raw": ""
},
"zip": {
"type": "textfield",
"raw": ""
},
"phone": {
"type": "phone",
"raw": ""
},
"fax": {
"type": "phone",
"raw": ""
},
"website": {
"type": "url",
"raw": ""
},
"public-private": {
"type": "select",
"raw": ""
},
"system": {
"type": "textfield",
"raw": ""
},
"current-accreditation": {
"type": "textfield",
"raw": ""
},
"initial-accreditation": {
"type": "numeric",
"raw": ""
},
"last-comprehensive-review": {
"type": "numeric",
"raw": ""
},
"next-comprehensive-review": {
"type": "numeric",
"raw": ""
},
"calendar": {
"type": "select",
"raw": ""
},
"total-enrollment": {
"type": "textfield",
"raw": ""
},
"programmatic-accreditation": {
"type": "textarea",
"raw": ""
},
"degrees-single-line": {
"type": "textfield",
"raw": ""
},
"staff-liaison": {
"type": "textfield",
"raw": ""
},
"additional-campuses": {
"type": "wysiwyg",
"raw": ""
},
"action-letter": {
"type": "file",
"raw": "",
"attachment_id": null
},
"statement-of-accredited-status": {
"type": "file",
"raw": "",
"attachment_id": null
},
"public-disclosure-notice": {
"type": "file",
"raw": "",
"attachment_id": null
},
"student-achievement-data": {
"type": "url",
"raw": ""
},
"federal-college-scorecard": {
"type": "url",
"raw": ""
},
"participates-in-title-iv-federal-student-aid-programs": {
"type": "url",
"raw": ""
},
"participates-in-title-iv-federal-student-aid-program": {
"type": "textfield",
"raw": ""
}
}
},
"_links": {
"self": [
{
"href": "hidden link"
}
],
"collection": [
{
"href": "hidden link"
}
],
"about": [
{
"href": "hidden link"
}
],
"replies": [
{
"embeddable": true,
"href": "hidden link"
}
],
"wp:attachment": [
{
"href": "hidden link"
}
],
"wp:action-publish": [
{
"href": "hidden link"
}
],
"wp:action-unfiltered-html": [
{
"href": "hidden link"
}
],
"curies": [
{
"name": "wp",
"href": "hidden link{rel}",
"templated": true
}
]
}
}
Can someone please respond to my last post? Thanks ahead of time!
Hi there,
Would you please replicate the issue on the clean installation below so I can report this?
Meanwhile I am going to double check with the second-tier support if it is possible to do as the way you mentioned which is updating JSON.
hidden link
You can add the code to the functions.php of the theme.
Thanks
Hi Christopher,
I do not see the functions.php file under the selected theme twentytwentythree so I am unable to update it. Can you assist?
Hi there,
I changed the theme and you can add the code there as it has functions.php file now.
Thanks.
Hi Christopher,
I updated the functions.php in the environment above. Everything should be replicated now also including Post Types, Field Groups and Fields. Is there a way to connect to the environment via Postman to test?
Hi there,
Sorry for the late reply, usually you should be able to use the Postman. I checked and for example the endpoint below works ok for a simple post of the hello world that is now on the website:
hidden link
For the institutions custom post it depends on how you developed the endpoint, so you can use that URL in the postman.
Thanks.