Http Client Connectormake calls to any REST API
The HTTP Client connector provides a way to manually make REST based requests to a specified URL. You can use the HTTP client to make calls to any REST API; it's useful for making calls to services that don't yet have a tray connector.
Our HTTP Client connector intelligently handles data to make things as simple, reliable and consistent as possible. Here's some of the measures we take:
Content-Typeheader is automatically set depending on the
bodyprovided, with application/x-www-form-urlencoded being set if none is selected. Additionally, the
Content-Typeof the request can be set/overwritten by explicitly specifying it in the
Acceptheader is fixed to application/json, with a few exceptions. If the
bodyis set to none, or the automatically detected
Content-Type(dependent on the body) is either text/plain or application/x-www-form-urlencoded, then
Acceptis not set. Additionally, the
Acceptvalue of the request can be set/overwritten by explicitly specifying it in the
|GET||Send a GET request|
|POST||Send a POST request|
|PUT||Send a PUT request|
|PATCH||Send a PATCH request|
|DELETE||Send a DELETE request|
|HEAD||Send a HEAD request|
The HTTP Client connector allows basic authentication.
It does not yet support OAuth. However if you have an OAuth-based service connector that has already been authenticated, you can re-use this to build some extra custom functionality for the service. Please see the section on this below.
To add a new authentication (for example a token) click Add Authentication then choose a name for your auth token. Enter your token. This auth token can then be used in your API call (for example, as a parameter) by including the path "$.auth.token_name".
Note: different APIs need to be authenticated in different ways, for example via:
Basic authentication (username & password)
Access tokens (OAuth)
To view settings related to the last two, open up the "advanced settings" for the properties and you'll see the following:
The best way to check that everything is running properly is to use a manual trigger to call your API and inspect the logs to see what messages are being passed back and forth. We also recommend using a service like Postman for exploring APIs.
Tray has a page limit of 1 MB. So calls to APIs may return errors if the body of the returned content is too large.
To prevent this happening, you should implement a pagination method which is appropriate to the type of API calls you are making.
Note on Using OAuth
If you have a service which uses OAuth that you have already authenticated to using its pre-built connector, you can re-use this OAuth in an http-client.
For example, if you have already used and authenticated with the pre-built Slack connector in a workflow, you can click 'Show Advanced Settings' and see what the config json path is for the OAuth token - i.e.
Having noted this config path, you can now create an http client connector for adding custom Slack API operations.
To test this out, you can try a quick setup which will post a message to a particular Slack channel:
Create a new Workflow with a Manual Trigger
Add an Http Client as the next step
Choose your previously configured Slack Auth as the Authentication, set the API Operation to POST and enter
https://slack.com/api/chat.postMessageas the endpoint URL:
Now you need to specify some query parameters:
As you can see you need to enter the Slack Channel ID (found in the url when you have selected a particular channel e.g.
https://acme.slack.com/messages/CE2DU9XSL/), the text for your message and the OAuth token config path.
Details on the accepted format of parameters for this Slack API are at https://api.slack.com/methods/chat.postMessage
Once you have finished, you can click 'Run Workflow Now' and the test message should be sent and you can check the debug info: