Good morning all,
I'm trying to consume a wordpress API, using the instructions here.
Using the Consume REST API -> Add Single Method, and the URL 'https://askearl.co.uk/wp-json/wp/v2/posts', I've been able to get a positive response in the test API tab, clicked 'Copy to Response Body', and the data structure appears to list correctly in the tree. There is a Output Parameter called 'Response'. Data type = post list and it is set to recieve in 'Body.
I've then created a Server Action called 'GetBlogPosts', which runs the GetPosts API, and assigns GetPosts.Response.Current to the output variable BlogPostsResponse, which has the Data Type = Post.
It's here I get stuck though. The guide says to add a new action in 'screen preperation' to just run the GetBlogPosts Server Action...
I've tried creating a "Fetch data from other sources", but this seems to force another assign to output, which the guide doesn't refer to. I've also created a new client action, and added the Server action within it, but get lost in conflicting data types...
I'd very much appreciate some direction.Thank you
Leigh
The API response is different, Just because I am using a different URL while consuming REST API.
You just need to open the downloaded oml in service studio, publish it in your environment and open it in the browser.
Check the new OML. Where you can find the implementation.
Hi Leigh Rogers,
The Guide, you are following, is applicable for the Traditional Web. But you have created a reactive web app, That's why the Guide suggests you, put an action in screen preparation. But in reactive web, we do not have screen preparation. Anyway, you can do it even on the reactive web.
Use the Data action of the screen to run the API action, and the output of the data action should have the same data type as the consumed rest API data type.
1. Create Output parameter of data action with the same data type of API response has.
and assign the API response to the data action output variable.
Now you can use the output parameter Data Action anywhere on the screen to show data from API.
Let suppose you have to show Blog posts. Take the Table widget and show the Posts data.
Note- In Tradition web screen preparation can not keep consumed API directly. That's why in the guide, First they have created a Server action (GetBlogPost) where he called the API. But In Reactive web, you can directly call the API in data action so you have to do the same thing for the data action that you did for server action in Guide.
Check the uploaded oml.
Cheers,
Thank you so much for your detailed reply.I'm brand new to Outsystems, and regret that I've still not managed to get it to work...
I've opened your oml file and imported it into my app, changing the base url and url paths to my site. But I get this error.
When I compare the output of your REST response and mine, they are a bit different.
Yours starts
"
HTTP/1.1 200 OK Content-Type: application/json
(Show all headers)
{ "found": 7, "posts": [
Mine starts
HTTP/1.1 200 OK Content-Type: application/json; charset=UTF-8
[ { "id": 2689, "date": "2021-11-09T22:25:10", "date_gmt": "2021-11-09T22:25:10", "guid": { "rendered": "https://askearl.co.uk/?p=2689"
It looks like the structure of the data is different?How can I fix this?Thank you very much x
Hello.
I'll take the opportunity to promote my component Blogs Connector.
I did most Wordpress get operations there so you can take a look at it.