Warning!
This is a legacy document. The features described below are only usable within the classic-generation environment.
Currently, Betty Blocks offers faster and more advanced options that are available in next-gen. Before you start working on some new features in your application, consider doing it using the next-gen version. In particular, you might find it useful to check out Using the HTTPS action step and Setting your remote data source articles.
Good luck!
After reading this article you will know:
How to create a JSON Webservice that fetches one object.
Setting up the Webservice Endpoint
Create a new endpoint
Opening the Webservices page will give you an overview of all the Webservices present in your application. Here you’ll have to select the Example Webservice that was created for Fetching one object from a JSON response
In order to create an endpoint, you’ll have to follow the first few steps of the article fetching one object from a JSON response. But instead of using the comments path use the users path. It'll look something like the following:
The structure of users is as follows:
Again you should run the test and generate a Custom model, except it’ll be a little different this time. When you open the attributes of your custom model you’ll notice that there are multiple attributes that have a Custom model Kind.
These attributes are Custom models themselves, meaning that they contain multiple attributes.
Create a new Action
Opening the Actions page will give you an overview of all the Actions present in your application. Click on the New button located in the top left corner. Fill in the description and specify which model the Action is for. Again keep the trigger on Manual. Your form should look something like this:
Create an Http request
Select the Http request event option in the Kind dropdown. Select the right Webservice and Webservice endpoint. Insert the path variable from the variable browser. In this case, just use a static number(1) but you can also make it dynamic by using a variable. Last but not least you have to give the response a variable name for further processing. Your form should look something like this:
After you’ve created the Http request Action event you’ll have to create a new Action event. Create a Create Action event in order to create the record and save it into your Back Office. Select the Model that you want the record to be saved to, now you’ll have to assign every Comment property to the attributes of our Custom model. However, in comparison with HowTo fetch one object from JSON responses? You’ll have to create multiple Create Action events. The reason for this is that you have to create a Create Action event for every nested object.
You need to start with the deepest layer of your response, as it is needed in order to create the relations between the models. In order to create these relations, you will need to specify them in the Create Action event of the layer above. This should look something like this:
After you have done this for all the layers of the response you should end up with an Action that should look something like this:
Run the action
In order to run the Action, you’ll need to select the Action and click the Run button located in the top right corner of Betty Blocks. A popup will show, you’ll just have to click the execute button located in the bottom right of the popup. A success message should appear stating the custom model has been created.
Check the Back Office
In order to see the created records, you’ll have to direct yourself to the Grid page of the specific model in your Back Office. If the Action was successfully run then your Grid should look something like this: