Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

We offer Canvas offers a generic REST API controller, which app, which will allow you to connect to any REST API without using a dedicated app on Canvas.

Info

In general we recommend that you use dedicated apps instead of the generic REST app; if the API you are connecting to is already supported on Canvas with a dedicated app, you should use that instead of the REST app.

Canvas has built-in support for a wide range of apps, with ready-made blocks and simplified APIs. We are also working continuously to extend support to new apps and to add new blocks. If you would like to request support for a new app, please get in touch with us.

The generic REST API app can be found in the app list, with the other supported apps:

...

The following fields need to be filled out for authentication:

...

Image RemovedYou will find a selection of ready-made blocks for various use cases:

...

How to make requests

Here you see an example of a GET request made via the REST API app:

...

An example of a POST request, with data being sent via the “data” field:

...

Info

Regarding default headers:

If no “Content-Type” header is provided in the request, the backend will set it by default to “application/json”, except for GET requests which will instead have an “Accept” header set to “application/json” by default.

Info

Regarding URL encoded requests:

If you are using header “Content-Type” set to "application/x-www-form-urlencoded" then the “data” field can be used to send the parameters. The entries in “data” are expected to have “Name” and “Value” fields, which will be used to set the parameters for the outgoing request.

Full list of available fields for the request object:

Code Block
languagejs
    let request = {
      "verb": "POST", //currently supported HTTP verbs are GET, POST, PUT, PATCH, and DELETE
      "requestUrl": "/myendpoint" //only the last part (i.e. the endpoint) is needed here, as the base url comes from the app you registered
      "parseResponse": true, //try to automatically parse the response as json, xml, or csv
      "responseCodes": [200], //expected response codes, which will not trigger an exception
      "headers": [
          { "key" : "Accept", "value" : "application/json" }, 
          { "key" : "Content-Type", "value" : "application/vnd.api+json" }],
      "cookies": [
          { "key" : "CookieName1", "value" : "CookieValue1" }, 
          { "key" : "CookieName2", "value" : "CookieValue2" }],
      "data": {"myField": myValue }, //the data to send, as request body
      "csvHeaders": false,
      "csvSeparator": ";",
      "csvResponse": false,
      "removeXMLBOM": false,
      "returnCookies": false, //include the cookie in the response
      "encoding": "UTF8",
      "baseURL": //not in use, as the base URL comes from the stored app credentials
      "successCode": 200
    }

Parameters for the ‘rest/request’ endpoint:

Code Block
languagejs
await api.post('rest/request', request, trustCertificate, isoFormatJsonDates)
  • “request” is the request object, as described above

  • “trustCertificate” is a boolean which can be used to ignore SSL certificate errors. Defaults to false.

  • “isoFormatJsonDates” is a boolean which can be used to ensure that date formatted strings are not parsed to a date type, but are instead read as strings. Defaults to true.