Skip to main content
Version: 8.0

Handle the response of an external web service

Level: beginner

@creatio-devkit/common includes the sdk.HttpClientService service that sends HTTP requests.

To handle the response of an external web service:

  1. Add the dependencies. Instructions: Display the value of a system variable (similarly to step 2). Instead of the sdk.SysValuesService service, use the sdk.HttpClientService service that sends HTTP requests.

  2. Add an attribute. Instructions: Set up the field display condition (step 2).

  3. Bind an attribute to the label. Instructions: Set up the field display condition (similarly to step 3). Instead of the visible property, use the caption property that handles the text displayed in the element.

  4. Implement the base request handler.

    1. Go to the handlers schema section.

    2. Add a custom implementation of the crt.HandlerViewModelInitRequest base request handler.

      1. Create an instance of the HTTP client from @creatio-devkit/common.
      2. Specify the URL to retrieve required data. If a web service request is sent using a non-absolute path (without https:// or http:// prefixes), this is a request to an internal Creatio web service. In this case, Creatio automatically adds the address of the current app to the link.
      3. Send a GET request.
      4. Retrieve required data from the response and specify data in the corresponding attribute.

    View an example of a crt.HandleViewModelInitRequest request handler that sends a request to the https://SomeUrl web service, receives the someValue parameter from the response body, and specifies the parameter in the SomeAttribute attribute, below.

    handlers schema section
    handlers: /**SCHEMA_HANDLERS*/[
    {
    request: "crt.HandleViewModelInitRequest",
    /* Custom implementation of a system request handler. */
    handler: async (request, next) => {
    /* Create an instance of the HTTP client from "@creatio-devkit/common." */
    const httpClientService = new sdk.HttpClientService();
    /* Specify the URL to retrieve required data. */
    const endpoint = "https://SomeUrl";
    /* Send a GET request. The HTTP client converts the response body from JSON to a JS object automatically. */
    const response = await httpClientService.get(endpoint);
    /* Retrieve the "someValue" parameter from the response body and specify it in the "SomeAttribute" attribute. */
    request.$context.SomeAttribute = response.body.someValue;
    /* Call the next handler if it exists and return its result. */
    return next?.handle(request);
    }
    }
    ]/**SCHEMA_HANDLERS*/,

See also

Freedom UI page customization basics

Customize fields (Freedom UI)