Skip Navigation

[Resolved] Using Custom Fields with REST API

This thread is resolved. Here is a description of the problem and solution.

Problem:
Using Custom Fields with REST API - User custom field do not expose to REST API

Solution:
Toolset Types version 3.4.10 that contains the official fix for this issue.

Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/toolset-integration-with-the-rest-api/

100% of people find this useful.

This support ticket is created 3 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Tagged: 

This topic contains 9 replies, has 2 voices.

Last updated by malcolmF-2 2 years, 10 months ago.

Assisted by: Minesh.

Author
Posts
#1922835

I want to use a remote system to create users in wordpress and I want to be able to use a UUID that is stored in a Custom Field in user_meta. The remote system allows me to pass curl commands to wordpress.

Toolset allows me to create the custom user field called "uuid." I can access the field in Profile and edit it. I can find it in the user_meta table, named "wpcf-uuid."

However, I cannot pass data into when I create a user. The command below works to create a user but it does not create a user_meta record. I've seen information online that suggests I have to use register_meta() to be able to access custom fields using REST API.

Is this necessary? Does toolset automatically register fields?
If not, where should I register this? Also, when do I register it?
Is the syntax I'm using below correct?

curl --user 'user:password' -X POST "hidden link" \
-H "Content-Type: application/json" \
-d "{\"email\":\"peo@mailinator.com\",\"first_name\":\"Peo\",\"last_name\":\"thaaba\",\"meta\":{\"wpcf-uuid\":\"E54AF95C-CC35-462C-A058-561D6CE3C108\"},\"name\":\"peo thaaba\",\"nickname\":\"1822345\",\"password\":\"A5B8128F-7\",\"slug\":\"1822345\",\"username\":\"1822345\"}"

#1922925

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Toolset integration with REST API is limited and offers the GET callback where custom fields are exposed to REST API callback response:
=> https://toolset.com/documentation/programmer-reference/toolset-integration-with-the-rest-api/

You will require to define the endpoint to register the update callback function for the user meth.

Please check the following related link:
- https://wordpress.stackexchange.com/questions/338134/updating-custom-wordpress-user-meta-field-via-rest-api

Please note that this is custom code and that is beyond the scope of our support policy. If you are not sure how to do it, please consult with pro REST API devs. You can even contact Toolset Certified contractors:
=> https://toolset.com/contractors/

#1924661

Thanks for the pointer to the settings. I've modified the settings and I see that there is a toolset-meta element in the response shown below and trimmed for readability. Please keep reading as I don't want custom code support. I simply want to know how to utilise Toolset.

$ curl --user 'user:password' -X POST "<em><u>hidden link</u></em>" \
     -H "Content-Type: application/json" \
     -d "{\"email\":\"masoeu@mailinator.com\",\"first_name\":\"Peo\",\"last_name\":\"thaaba\",\"meta\":{\"wpcf-uuid\":\"E54AF95C-CC35-462C-A058-561D6CE3C108\"},\"name\":\"peo thaaba\",\"nickname\":\"1822345\",\"password\":\"A5B8128F-7\",\"slug\":\"1822345\",\"username\":\"1822345\"}"

{"id":20, ...
"meta":[],
"toolset-meta":{"requiredclientdata":{"uuid":{"type":"textfield","raw":""}}}, ...
}

When I target the GET endpoint for the newly created user the meta and toolset-meta arrays are empty.

$ curl --user 'user:password' "<em><u>hidden link</u></em>"
{"id":20,"name":"peo thaaba",...,"meta":[],"toolset-meta":[],...}

I got the impression that using the Toolset settings for REST-API was sufficient to expose the meta-fields to the REST API? Isn't that what is said at this URL?
=> https://toolset.com/documentation/programmer-reference/toolset-integration-with-the-rest-api/

I have three questions now.

1. Having turned the Toolset settings for REST-API on, is it still necessary to register meta fields?
2. If Toolset outputs meta field groups in a special toolset-meta element, should we also be targeting toolset-meta when we are generating data?
3. Do you have documentation around this, or at the very least, documentation of the Toolset code base that you can point me to?

#1928107

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Based on my tests, It seems to me that Toolset REST API integration is limited to post custom fields only.

Please allow me to consult our Devs and I'll get in touch with you as soon as I know more.

#1928717

Thanks for the update Minesh.

I would like the ability to expose user custom fields to REST API. I'm looking forward to the reply from DEV.

#1929443

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Based on my testing, I found that user custom fields are not exposed to REST API response.

I've escalated the issue to our next level support. please hold on for further updates. I will keep you posted as soon as I know more.

#1930355

Thanks for testing and confirming. I'm glad that we're both seeing the same result.

#1930779

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I'll get in touch with you as soon as I know more. Please hold on for further updates.

#2058037

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

We just release Toolset Types version 3.4.10 that contains the official fix for this issue.

We always recommend running your site with the latest stable release plugin version and try to resolve your issue.

*** Please make a FULL BACKUP of your database and website.***
Could you please update ALL Toolset plugins to it's latest officially released version. You can download the latest plugin release from your accounts page:
=> https://toolset.com/account/downloads/

#2059055

This is a really nice tweak for the Types plugin. It makes the product more complete and easier to use.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.