Open Navigation

Http Client Connector

make calls to any REST API
On This Page

Overview

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:

  • The Content-Type header is automatically set depending on the body provided, with application/x-www-form-urlencoded being set if none is selected. Additionally, the Content-Type of the request can be set/overwritten by explicitly specifying it in the header.
  • The Accept header is fixed to application/json, with a few exceptions. If the body is set to none, or the automatically detected Content-Type (dependent on the body) is either text/plain or application/x-www-form-urlencoded, then Accept is not set. Additionally, the Accept value of the request can be set/overwritten by explicitly specifying it in the header.
OperationDescription
GETSend a GET request
POSTSend a POST request
PUTSend a PUT request
PATCHSend a PATCH request
DELETESend a DELETE request
HEADSend a HEAD request

Authentication

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:

  • Query parameters

  • Headers

  • 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:

http-basic-auth

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.

Pagination

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. $.auth.access_token

slack-grab-token

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:

  1. Create a new Workflow with a Manual Trigger

  2. Add an Http Client as the next step

  3. Choose your previously configured Slack Auth as the Authentication, set the API Operation to POST and enter https://slack.com/api/chat.postMessage as the endpoint URL:

    http-client-slack-1

  4. Now you need to specify some query parameters:

    slack-http-params

    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:

    slack-http-debug

Was this article helpful?
Yes
No
On This Page