AppGyver & WordPress API - Global Parameters

Hi,

I’ve created a data resources using “/wp-json/wp/v2/posts”, with the associated website as the source. I’m using a Global Parameter in an effort to reduce the number of results being returned from the API.

The global parameter is _fields - and I’m using it like this: ?_fields=content.rendered, which is added to the Relative path section of Get Collection (GET). The test is good, and the schema created from that is one object “content” with one property “rendered”.

The issue with this data resource, I think, is that the API returns an array of rendered content (10 to be exact). I only need item “0” in that array. When I add this data variable to the app so that I can bind the HTML renderer (beta) component to content 0, the data variable is not available as an option to select.

I also tried using a formula: data.WeeklyUpdateContent1.content.rendered on the HTML renderer (beta) component, but this does not render the HTML. Nothing happens.

Are there tutorials that show how to work with the WordPress API in AppGyver, or does anyone see where I might have missed a step?

Thanks,

1 Like

:grinning: I was able to resolve this issue by using /wp-json/wp/v2/posts?_fields= in the Base Resource URL, still using content.rendered in the Relative Path, but adding a 0 in the Get Record (GET) Resource Key Path. I then set the data variable to “Single data record”, and was able to select the first rendered content block for the HTML Renderer component.

:frowning_face: I was not able to replicate this solution for the post’s featured image however. It’s important to note that I’m using a different WP Global Parameter for the featured image: _embed, used like so: /wp-json/wp/v2/posts?_embed

When trying to bind a data variable to the Image component, I am unable to select the “source_url” key, because it is hidden in a list (wp:featuredmedia) that I cannot access:

Because I know that the schema is there, I tried using the following formula: data.WeeklyUpdateImage1._embedded["wp:featuredmedia"].media_details.sizes.medium_large.source_url But this does not resolve the issue.

Could something be off with the formula, or perhaps I missed a step?

Thanks

Oh, I forgot to show the error messages for the formula after saving and going back in:

And here is the schema in question (most of it anyway, there is a few others to drill down into):

Thanks!

:grinning_face_with_smiling_eyes: Solved the featured image issue by modifying the previous formula to data.WeeklyUpdateImage1._embedded["wp:featuredmedia"]["0"].source_url. The validator states “Should use a number to access a list item instead of text type”, but it still works.

I wonder if there is a better way to write that formula so that it validates 100%? If not, I guess we’re good for now.

Thanks

1 Like

Hi, where did you get information on how to do it with wordpress? I have looked for a tutorial and I have not found anything on how to implement the wordpress api in appgyver

Hi. Sure thing, happy to help. Here are my starting points for the WP API:

Hope this helps!

1 Like

Hello, there I am clear with wordpress, the issue is how to integrate it in appgyver, do you know if there will be any video tutorial on how to integrate appgyver

I have not come across any such tutorials, but the WP REST API works like most other API data resources in AppGyver. Once you add the WP site in question as a data resource in Composer Pro, you can then test it and set schema for it, as well as data variables for either a single data record, or a collection of data records… depending on your needs. With those steps in place, you can begin the process of binding your components to that data.

2 Likes

hi @Anthony_Williamson so i have also be trying similar to see if i can connect wordpress api with appgyver, luckily i was able to do so, however, for everytime that i pass the json data to app variable, i can seem to be able to preview it in my app using single record. but if i select collection of data in app variable, my app renders fine.
let me break it down


this is my data variables i created


this is the api working fine on both appgyver and the preview screen


nothing the title page. if i bind the title to the data variable, i cant seem to see the proview. i dont know what i have done wrong.
please help

1 Like