Skip Navigation

[Resolved] CPT / Custom fields not available in 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.

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)

This topic contains 3 replies, has 3 voices.

Last updated by Minesh 1 year, 9 months ago.

Assisted by: Minesh.

Author
Posts
#2656147
Screenshot 2023-10-24 at 09.13.23.png
Screenshot 2023-10-24 at 09.12.35.png

Tell us what you are trying to do?

I am trying to connect Worpress CPT and Zapier. First step is to make CPTs / Custom fields created with Toolset available in the API. When I call a CPT post in the API I get the error message: "rest_post_invalid_id" and "status: 404" (see attachment). Default WP post types work fine in the API.

Exposure to API is checked in Toolset settings.

eg:

WP default post type: hidden link
Toolset post type: hidden link

Is there any documentation that you are following?

Yes, this --> https://toolset.com/documentation/programmer-reference/toolset-integration-with-the-rest-api/ and this --> https://toolset.com/forums/topic/zapier-cpt-access/

Is there a similar example that we can see?

Same with hidden link

What is the link to your site?

hidden link

#2656243

Nigel
Supporter

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

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

Hi there

Toolset post types and custom fields operate as normal WordPress post types and post meta and can be retrieved using the normal REST API routes.

The extra layer of Toolset integration with the REST API is to add a special endpoint to retrieve formatted custom field values (the same as if you output the field using a shortcode or block) rather than the raw values stored in wp_postmeta, which is what the normal WordPress REST API routes return.

There is nothing special required to access custom posts of a post type registered with Toolset (other than having the REST API option enabled for the post type, which it is by default).

The problem appears to be that you are trying to retrieve custom posts via the /posts route, but that is for standard WordPress posts. You should use the route for your post type (e.g. /books for a book post type), as described here:

https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-rest-api-support-for-custom-content-types/

#2656769

Hi Nigel,

Thanks for clarifying! It works fine after registering the CPT as described in the url you provided.

However, in Zapier - although I see the CPT in the list - none of the fields are available. I guess there must be an issue on Zapier's side since CPTs and custom fields should be available as long as the post types are accessible in the REST API?

Thank you for you help!

- Thomas

#2656801

Minesh
Supporter

Languages: English (English )

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

Have you already enable the "REST API" support to expose the toolset-meta with post type from:
=> Toolset => Settings => Custom Content tab => enable the checkbox "Expose custom fields managed by Types for posts, users, and terms through the REST API" from REST API section

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

If that does not help then I see that with the following reference ticket user shared the information that there is some issue with Zapier:
- https://toolset.com/forums/topic/zapier-cpt-access/#post-2631845

#2658217

I am in touch with Zapier support as it seems there is an issue when it comes to accessing CPT's in WordPress actions.