Scroll

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.

Note. All requests require Session Id URL parameter and basic request headers. In the following examples, headers are omitted for clarity.

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 yes (0) Minimum number of arguments for this function
MaxArgs integer yes (0) 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":     1,
  "MaxArgs":     1,
  "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": 0, "MaxArgs": 0, "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','MinArgs':1,'MaxArgs':1,'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": 1, "MaxArgs": 1, "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

Hidden Article Information

Article Author
Exago Development
created 2017-02-21 17:24:17 UTC
updated 2017-04-17 13:36:55 UTC

Labels
REST, API, Web Service, Functions,
Have more questions? Submit a request