📬 Send data to a REST API

561

In this article, we explain:

  • how to send data to a third-party API using the REST API action in a Workflow
  • how to use no-code formulas to send this data
  • how to use the raw body option to send raw javascript data to an API

To be able to do API calls inside your workflows, be sure to activate the REST API plugin on your app.

Once added, a new action becomes available in your workflows, REST API Request :

By adding this action to a workflow, you can now configure the API request.

How to use nocode formulas to send data to an API

  1. Setup the HTTP method your API expects. There's no standard an API has to follow so you should check the API's docs. But 90% of the time, you can refer to this:
  • GET to fetch data from the API
  • POST to create or edit data in the API
  • PUT to create data in the API (less usual than POST)
  • PATCH to edit data in the API (less usual than POST)
  • DELETE to suppress data in the API (use with care!)
  • OPTIONS to get the API options (rarely used)

2. Copy/paste the API endpoint's URL. This field is bindable, so you can use variables and formulas here.

🔥 Pro Tip 🔥

Most APIs have the same domain for all their endpoints, so it's best practice in a Weweb app to store this endpoint in a variable, and use string concatenation to query a specific endpoint, like so 👇

3. Now, enter the fields your API expects. Those are the data you want to send to the API. Refer to the API docs to know what they are.

Fields are basically key/value pairs, where you typically bind the value to a Weweb variable to send dynamic data, like this example 👇

4. Then, you'll want to add headers to your API calls. Again, those are specific to your API. The main common one is the Authorization header, which tells your API who you are by using an access token:

5. Query string variables are the same as fields, but classicaly used for GET requests only (it's the variables you seem in an URL, after the question mark: https://www.myapi.com/my-endpoint?my-query-var=hello)

How to use the raw body option to send raw javascript data to an API

If you're a power user and your API expects a complex payload, you can use the raw body option to send an arbitrary data object you'll have to create.

It's particularly useful if your API expects an object with some nested objects inside. Example: