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 nested objects
Setting up the JSON webservice
Create a new webservice
Opening the Webservices page will give you an overview of all the webservices present in your application.
Click on the +New button located in the top left corner. A form will appear, where additional settings can be set. More information about webservices can be found here: Webservice reference.
Configure the webservice
Specify a Name and Host for the webservice, as these are required in order to create a webservice. Select the right Protocol for your webservice. Change both the Request and Response Content-Type to JSON. Your form should look something like this:
Configure endpoint
Click on the +
button located next to the endpoints button in order to start creating an endpoint for your webservice. A form will appear, where additional settings can be set.
Specify a Name and Path for the Webservice, as these are required in order to create an Endpoint. Create a new Path Variable named comment_id, and insert this variable into your path using the Insert variable button. Your form should look something like this:
Test run
Click on the Run test button located in the top right corner. A popup will show where you'll have to fill in a comment_id. Press the Run test button after you’ve filled in the id in order to start the test. You should get a response page that looks something like this:
Genertate custom model
Click on the Generate custom model button located at the top of your response page. A success message should appear stating the custom model has been created.
Click on the OK button. You’ll be directed to the WebserviceEndpoint page where you’ll find a new button. The Custom model button will take you to the page of the just created Custom model. You’ll have the option to rename the Custom model to your own liking.
Create 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. A form will appear, where additional settings can be set. More information about Actions can be found here: Action reference.
Specify a Description, as this is required in order to create an Action. Select the right Model for your Action. Keep the trigger on Manual. Your form should look something like this:
Click the +
button located above the End
of your action to create a new Action event.
Select the Http request event option in the Kind dropdown. Select the Webservice and Webservice endpoint that you want to use for the action. 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 property to the attributes of our Custom model. Your form 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 your 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: