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 New located on the top left corner of your screen
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.
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:
Click the + next to Endpoints
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:
Click Run test located in the top right corner of your Endpoint
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:
Click Generate custom model located at the top of your test response
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.
Open the Actions using the Builder Bar
Opening the Actions page will give you an overview of all the Actions present in your application
Create a new Action
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 + above End
+ 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:
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.
View 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 ran then your Grid should look something like this: