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:
pivot.customizeAPIRequest(customizeAPIRequestFunction)
.new Flexmonster({customizeAPIRequest: customizeAPIRequestFunction, ...})
.The customizeAPIRequestFunction
function, which has the following signature: customizeAPIRequestFunction(requestBody: Object): Object
. Data passed to customizeAPIRequestFunction
:
Parameter/Type | Description |
---|---|
requestBody Object | The object containing the request's body and through which the request can be customized. |
requestBody.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 report.dataSource.requestHeaders.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.
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.