Get Free Trial
API reference
Table of contents

customizeAPIRequest

customizeAPIRequest(customizeAPIRequestFunction: Function)

[starting from version: 2.8]

This API call allows customizing the request before it is sent to a server. Only for "api" data source type.

customizeAPIRequest can be defined in two ways:

  1. As a regular API call: flexmonster.customizeAPIRequest(customizeAPIRequestFunction).
  2. As an initialization parameter: new Flexmonster({customizeAPIRequest: customizeAPIRequestFunction, ...}).

Parameters

  • customizeAPIRequestFunction – Function. It has the following signature: customizeAPIRequestFunction(requestBody: Object): Object.
    Data passed to customizeAPIRequestFunction:
    • requestBody – Object. The object containing the request’s body and through which the request can be customized. Has the following properties:
      • requestHeaders – Object. Allows you to add custom request headers. This object consists of "key": "value" pairs, where "key" is a header’s name and “value” is its value. The requestHeaders object is either empty or contains the request headers added in the DataSourceObject in the report. After customization, Flexmonster adds the contents of requestHeaders to the headers of the request. Changes made in requestBody are added to the request’s body.
    The customizeAPIRequestFunction function must return requestBody, the changed object with new or updated request headers. If requestBody is null, custom request headers will not be added to the request.
    If the customizeAPIRequestFunction is set to null, no customization is applied.

Example

Adding custom request headers:

function customizeAPIRequestFunction(req) {
    req.requestHeaders = {
        "customHeader1": "This is the first custom request header",
        "customHeader2": "This is the second custom request header"
    };
    console.log(req);
    return req;
}

Check out a live sample on JSFiddle.