Skip to content
  • There are no suggestions because the search field is empty.

Using the Format endpoint result step

In this article, we'll dive into a small use case explaining how the step works.

After reading this article, you’ll know how to:

  • Use the Format endpoint result step in actions

  • Give a proper response to your users

Getting started

Install the Format endpoint result step from the Block Store. You can read more about installing blocks in this article. To test the action step, we recommend using an API platform such as Postman.

Format endpoint result step is a useful tool for providing feedback (response) to your users. For example, when you send a POST request to an action (endpoint) in Betty Blocks, it is beneficial to receive feedback such as the status code, headers, and body.

Did the request process as expected (200), or did something go wrong (500)? In the headers, you can specify the content type like JSON. In the body, you could return the record that we created based on the requests input. You can define all of this yourself in the action step.

A prerequisite to follow along would be already to have an employee model with the following properties:

downloads.intercomcdn.comio936803377a92f8743df606f7c5ef5cb46image
 

Creating a schema model

A good use case to understand how this action step works would be to create an employee record via a POST request using Postman. For that, we'll first need to create a schema model in Betty Blocks. Call it something like RequestSchema and add the following properties:

downloads.intercomcdn.comio934928325f364ad6163f6e07bf2431d1eimage
 

These variables are needed to work with the Format endpoint result step. We'll use this schema model in the action we'll create next.

Add the schema model to your action

Create a new action, the first thing we'll do is add a request variable in the start step, to make sure our newly created schema model can be read in the action like so:

downloads.intercomcdn.comio93682817819a9c44bf0ce36751cec0fb7image
 

Select the newly created schema model here. Before we continue with the next steps of this action, let's dive into the request that this action is going to process.

Creating the request

For this use case, we'll create the POST request that will be sent to our action. The URL needed to make a POST for the format endpoint result step requires an app-identifier, this is the name of your application. The UUID of your application and the action ID of your action (the string of letters and numbers after /actions/ are in the URL when you have an action open).

downloads.intercomcdn.comio9369785464f3940e7b06be8ccd87ac53dimage
 

<app-identifier>.betty.app/api/runtime/<app-uuid>/action/<action-id>

Example of URL that we'll use in this case:

obsidian.betty.app/api/runtime/32d9eb0140ea4a06a141f3b4a99bc48e/action/cabdd9dec91743dc9ae130daceff06c7

Assuming that you're using Postman, make sure to set the method to POST:

downloads.intercomcdn.comio9349622746678f8ed01f474b009b5c405image
 

Now select the body tab followed by the raw checkbox, this allows us to select JSON in the dropdown that appears.

downloads.intercomcdn.comio9349661559cac132fe0500f676a91ebe5image
 

We can now specify the actual data that we want to submit. This should be a new employee according to the properties within the employee model.

downloads.intercomcdn.comio9367472250affac613bad1312558a3e1dimage
 

With our POST request ready to go let's continue with the action that will process this data.

Continuing with the action

When you install the Format result endpoint step, you'll notice that a second step is also added namely the JSONPath step. This is the step that will chop the request we created using Postman apart and transform it into bits that we can use in our action. It will make more sense in a second.

Drag the JSONPath step on the canvas, select the request variable we created earlier, the data in our request is within the body so make sure to select that here.

downloads.intercomcdn.comio936741693fd85850a0bacbb20fd59d6f4image
 

The first property in our request is the name, the path is as follows: $.name the output type is plain text, and give the result of this a name like so:

downloads.intercomcdn.comio936742916269f6131e8babe1777bb14f0image
 

If you want to learn more about the syntax of JSON path then make sure to check out this GitHub page.

Let's do the above for email and date of birth as well.

 
downloads.intercomcdn.comio9367437599e81ef94537440f4a7ef039bimage

With the bits of data that we can work with in place, we can create a new employee record based on the values we retrieve from the request. Drag a Create step in our action and configure it like this:

downloads.intercomcdn.comio936745327bc82119f973fbbc36417816dimage
 

Now we can configure the Format endpoint result. What we'll return to the user making the request is the newly created employee and a status code. For the step to work properly, we also need to define the headers, so in our example, we need to specify that the content type is JSON just like the image below:

downloads.intercomcdn.comio9367462604b663e44c76f20de6d0b1793image
 

Give the result variable the name response and add it to the Finish step. The action that we created looks like this now that we're finished.

downloads.intercomcdn.comio93607061806c2ae727b284b83554ab55dimage
 

Sending a request

To verify if everything is working as intended, let's send the Postman request we set up earlier. If you still have Postman, open the tab and press the Send button to pass the data of the new employee to the action we just created.

downloads.intercomcdn.comio93678499448175a28407ac6f51f77b801image
 

If everything is working as we expect, then we should see the data that we set up in our Format endpoint result step.

downloads.intercomcdn.comio936787607694f65d6b44f5c74d36d068bimage
 

And as expected, that's our new employee Chuck. We can confirm it even further by creating a page in our application to see if Chuck shows up among previously added colleagues.

downloads.intercomcdn.comio936790820fff0f63c233ace4b4ace39aeimage
 

As we can see in the image above, he shows up here as well.

Retrieving information

As a bonus, let's also create an action that retrieves the data from our employees. Copy the ID of the action as we did with the POST request and change the Postman request URL so that it calls this new action.

Creating the request

Next within Postman, we don't need the body tab anymore instead, when we want to retrieve information (GET), we specify this in the request URL. It means we'll work with the path variable instead of the body. So on top of changing the action ID, we need to add a bit more data namely '/employees/id' where ID is the ID of the employee you want to see the data of.

If we want to see the data from Chuck (ID 8), the URL will look something like this:

obsidian.betty.app/api/runtime/32d9eb0140ea4a06a141f3b4a99bc48e/action/4e740000d2064b3f8148afceddd5b44e/employees/8

The /employees/ part isn't strictly necessary but it's a best practice to create your URLs this way. We could also simply just have /8 and still retrieve Chuck's data but the other way makes the URL more readable.

Creating the action

All right in the action, like before, create an input variable of the type object and call it request.

downloads.intercomcdn.comio93703008812bcebcb1398a0b9468625abimage
 

Next up, we'll use the JSONPath step again, this time since we're not using body but path select that from the request.

downloads.intercomcdn.comio9370319777144207d35875e878d74c844image
 

The JSONPath is a bit different since we're using a more readable URL meaning we retrieve both 'employees', and 'id' in our request. This means we need the second item (the ID), hence we're using $[1]. If our URL was just /8 without /employees/ then $[0] would suffice. Read more about this on the following GitHub page.

Regardless, using the JSONPath step the result will now contain the ID of our employee. To return the object of the employee, we'll need to use the Format endpoints result step. Drag it on the canvas and go to the variable tab (next to the options tab). Create a new object using a filter as follows:

downloads.intercomcdn.comio937040791a025a44fa59f60012e668a2cimage
 

This will contain the data of the employee with whatever ID we specify in our GET request. We can now give this object back in the body of the Format result endpoint like this:

downloads.intercomcdn.comio937042651bb45c65d30835bddc7bce3a2image
 

Add the response to the Finish step.

downloads.intercomcdn.comio9370444848c299796125af680403c4f4cimage
 

Sending the request

Let's get back to Postman and send the request to this new action to see if we retrieve the data of our employee.

downloads.intercomcdn.comio9370474258bfc49d0d84b743a7d7c7e73image
 

And there we go, we can see the data of Chuck:

downloads.intercomcdn.comio937048408f66536e749dd4fb2813e1fcfimage
 

If instead of 8, we'd change the ID to 2 we'd see the data of Jerry!

 

Anyways, these small examples made sense enabling you to use these steps in your use cases. Happy building!