Functions are custom formulas that can be used in reports to manipulate data. Only custom functions can be edited, not the built-in functions.
NoteAll requests require a Session ID URL parameter and basic request headers. In the following document, headers are omitted in the interest of brevity.
Function JSON
Functions are represented as JSON objects with the following properties:
Name | Type | Writeable | 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
GET /rest/Functions
List all the functions in the current configuration. Output is an array of objects, each representing an individual function.
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
GET /rest/Functions/{Id}
Show the properties of the function specified by its Id.
Using curl
curl http://{webservice}/rest/functions/{Id}?sid={sid} -X GET
Example response
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
PATCH /rest/Functions/{Id}
Only supply the properties to be edited. Only custom functions can be edited.
Using curl
curl http://{webservice}/rest/Functions/{Id}?sid={sid} -X PATCH ^ -d "{'Namespaces':['WebReports.Api']}"
Example response
Status: 204 No Content
Delete Function
DELETE /rest/Functions/{Id}
Only custom functions can be deleted.
Using curl
curl http://{webservice}/rest/Functions/{Id}?sid={sid} -X DELETE
Example response
Status: 204 No Content