REST — Functions
Functions are custom formulas that can be used in reports to manipulate data. Only custom functions can be edited, not the built-in functions.
All requests require a Session Id URL parameter and basic request headers. In the following topic, headers are omitted in the interest of brevity.
Function JSON
Functions are represented as JSON objects with the following properties:
Name | Type | Writable | Description |
---|---|---|---|
Id | string | required-create | The unique Id of this function |
Description | string | yes | The description of this function |
MinArgs | integer | no | (Deprecated in v2017.2) Minimum number of arguments for this function |
MaxArgs | integer | no | (Deprecated in v2017.2) Maximum number of arguments for this function |
Language | enum | yes | Code Language |
Namespaces | array of strings | yes | Namespaces for this function |
References | array of strings | yes | References for this function |
ProgramCode | string | yes | Function code |
IsCustom | Boolean | no | Whether this is a custom function |
Example
{ "Id": "DayOfWeek", "Description": "Returns the day of the week as a string given a date value", "MinArgs": null, "MaxArgs": null, "Language": "cs", "Namespaces": [], "References": ["System.dll"], "ProgramCode": "return System.Convert.ToDateTime(args[0].ToString());", "IsCustom": true }
List Functions
List all the functions in the current configuration. Output is an array of objects, each representing an individual function.
GET /rest/Functions
Name | Type | Description |
---|---|---|
Id | string | The unique Id of this function |
Available parameters
Name | Type | Description |
---|---|---|
filter | string | Possible values: custom – Return only custom functions. |
Using curl
curl http://{webservice}/rest/Functions?sid={sid} -X GET
Example response
Status: 200 OK [ { "Id": "Today" }, { "Id": "Tomorrow" }, ... ]
Show Function
Example response
Show the properties of the function specified by its Id.
GET /rest/Functions/{Id}
Using curl
curl http://{webservice}/rest/Functions/{Id}?sid={sid} -X GET
Status: 200 OK { "Id": "Today", "Description": "", "MinArgs": null, "MaxArgs": null, "Language": "cs", "Namespaces": [], "References": [], "ProgramCode": "return sessionInfo.Today;", "IsCustom": true }
Create Function
POST /rest/Functions
Using curl
curl http://{webservice}/rest/Functions?sid={sid} -X POST ^ -d @customFunction.txt
customFunction.txt
{ "Id":"DayOfWeek", "Description":"Returns the day of the week as a string given a date value", "References":[ "System.dll" ], "ProgramCode":"return System.Convert.ToDateTime(args[0].ToString());" }
Example response
Status: 201 Created Location: /{webservice}/rest/Functions/DayOfWeek { "Id": "DayOfWeek", "Description": "Returns the day of the week as a string given a date value", "MinArgs": null, "MaxArgs": null, "Language": "cs", "Namespaces": [], "References": ["System.dll"], "ProgramCode": "return System.Convert.ToDateTime(args[0].ToString());", "IsCustom": true }
Edit Function
Only supply the properties to be edited. Only custom functions can be edited.
PATCH /rest/Functions/{Id}
Using curl
curl http://{webservice}/rest/Functions/{Id}?sid={sid} -X PATCH ^ -d "{'Namespaces':['WebReports.Api']}"
Example response
Status: 204 No Content
Delete Function
Only custom functions can be deleted.
DELETE /rest/Functions/{Id}
Using curl
curl http://{webservice}/rest/Functions/{Id}?sid={sid} -X DELETE
Example response
Status: 204 No Content