Introduction

Using the Rest API block you can connect your business tools (CRM, CMS, APIs, etc) to the chatflow. The REST API can be used either to pass data from the Morph.ai platform to your tools and vice-versa.


Possible use-cases:

  1. Fetching user profile from the business's CRM, using the user's phone number.
  2. Passing collected input to your business API for validation. 
  3. Fetching the current status of the user's application.

Usage

You can use this block to make REST API calls.





OptionDescription
TypeChoose the method/type of call you want to make. Supported types: GET, POST, PUT, DELETE
URLThe URL/address of the API endpoint. You can also use dynamic properties in the path params as it showed in the above image.
HeadersAdd header key and value. You can add multiple headers. Also, you can use dynamic properties in the value.
Query ParamsUsing this you can add query params. These will be appended to the API endpoint while making the call. It's better to specify query params here instead of the URL to keep it clean. Just like headers, you can also use dynamic parameters in the value of query params.
Body ParamsJust like query params, you can specify body params. These params will be sent in the body of the request. You can also use dynamic parameters in the value.
Follow redirectsCheck it to follow redirects while making the API call. The redirect will be followed only if the HTTP 301 Moved Permanently code is received.
Ignore errorCheck it to continue to the next block in the conversation in case of error while making the API call. If this is not checked then the conversation will stop on error.

{{API Response}}

The response received from the server will be stored in this property.


Just type {{ (double curly braces) to use dynamic properties.


FAQs

1. How to use API Response?

If the response of the API is plain text then you can use the {{API Response}} property directly in the message. But if the response is complex and structured (JSON/XML) then you can use the Code block to parse the response. The attached link also contains an example code to parse a JSON response.


2. How to identify if the API call is complete successfully or failed?

To detect success/failure, first, you should check the Ignore error option. Then you can check if the {{API Response}} property exists or not. In case of success, the {{API Response}} property will be set and if you put a branch after Rest API block with condition {{API Response}} exists, then it will return true.



3. How to make more complex API calls?

You might not be able to make complex API calls using the REST API block. The REST API block is designed to be easy and can be used to make/call simple APIs. For any complex use-case, you can use the Code block. The attached link also contains an example code to make API calls.