Official Content

This document explains how to insert new data using a Business Component exposed as a Rest web service in GeneXus.

First, see the basic guidelines:

1. How are the Rest services called in GeneXus?

Use the HttpClient data type.

2. Which HTTP method is used to insert new data?

The HTTP method used for inserting new data is the HTTP POST method.

3. How are the parameters going to be passed in the call?

All the parameters for inserting new data using the BC (except the PK parameters) need to be included in the body of the HTTP request. The message body should be in JSON format and contains the structure of the Business Component as it comes when it makes an HTTP GET.

The easiest way to build the body with the correct format is by defining a Structured Data Type (SDT) object based on the BC structure and using the method to format it to a valid JSON string.

That JSON string needs to be added to the body of the HTTP request before executing the POST to the service.

4. Which is the URL format to execute the POST?

<server uri>/rest/<module>/<bc name>/<param1>,<param2>,..,<paramN>


      Is the compound Primary Key.

If the Primary Key is autonumbered, just use 0 in the URL.


Consider the Product Business Component Transaction that is exposed as a Rest web service, as shown in the figure below:


In this example, you want to insert a new Product, whose ProductId is 5.

Sample code

You have defined a ProductSDT Structured Data Type based on the Product structure, as shown in the figure below:


Then, the code would be as follows:

&httpclient.Host= &server
&httpclient.Port = &port
&httpclient.BaseUrl = &urlbase

&productSDT.ProductName = "Samsung Galaxy"
&productSDT.ProductPrice = 22


if &httpclient.StatusCode = 201
    msg("Data successfully added")
   msg("There was an error retrieving the data: " + &httpclient.StatusCode.ToString())

Download the sample from Sample insert data using a Rest BC

  • Do not forget to add the 'content-type:application/json' header.
  • If more than one parameter should be passed in the URL (a compound PK), they need to be separated by commas.
  • If the service URI is http://localhost/TestRESTFullGX.NetEnvironment/rest/Product, the BASE URL is: /TestRESTFullGX.NetEnvironment/rest/
  • Error handling is managed by querying the HTTP Status Code after the invocation.

See Also

Business Components as Rest web services in GeneXus

Last update: November 2023 | © GeneXus. All rights reserved. GeneXus Powered by Globant