VTAP blog feature image

Getting Started with VTAP API Designer – Part 2

Previously, in our Vtiger Application Platform (VTAP) blog series, we discussed how to customize the Vtiger interface and bring in custom buttons and widgets to cater to specific business needs. This is just one capability that the platform offers. VTAP empowers you with many such features that help you:
  • Create a custom REST API
  • Connect to other applications that have REST API available
  • Connect to OAuth enabled applications
In this blog, I will discuss how we can create a custom REST API. First, let me talk a little bit about Vtiger REST APIs. It can be accessed with the below endpoint, which will be specific to your CRM instance.
For Example,https://your_instance.odx.vtiger.com/restapi/v1/vtiger/default If you are aware of the Vtiger Rest API, then you can skip the section below. To know about accessible modules, you can use the listtypes API. Here is a screenshot of how you can access the API using the postman client.

listtypes API

Vtiger already provides a standard set of APIs, but with the new API Designer tool, you can now write your very own custom REST APIs.

API Designer
The API Designer provides a workbench for developers to develop HTTP-based APIs that can be exposed to the VTAP Javascript APIs or the external application for easy integration. APIs can be defined using VADL specifications. API access needs user authorization and follows standard record access configuration made within the CRM. The API Designer provides IDE to write custom APIs. If you write a custom REST API for a particular module, you need to name the API and select the module.
Sub-image-2
We have defined Vtiger Application Definition Language (VADL), which is based on XML syntax to enable novice administrators or developers to define API without programming expertise. VADL allows you to:
  • Define CURD
    • APIs (Create, Update, Retrieve, Delete) on entity modules
    • Invoke HTTP based (REST / SOAP) endpoint through (GET/POST/PUT/DELETE) methods
      • With Authentication (Basic / Bearer token-based)
    • Accept request parameters and bind as API inputs

Let’s take an example of creating a custom REST API that will search for Contacts matching the email domain. We will add a new API with the name ‘fetch_email_contact’ and select the Contacts module

Code-sub-image-1

All the definitions are placed inside an API node with standard HTTP type (get, post, put, and delete). Since we are fetching data from CRM, we will use select nodes and pass module names. We will have fields that need to be fetched inside the records node and any filter conditions inside the where node. We support different types of conditions like equal, not equals, like, greater than, less than, etc.
Above is a simple example, which can also be achieved using the existing query REST API.The real power becomes apparent when you combine multiple APIs into one.
Consider this example. You update a record if it exists or create one if it does not exist. If you use an existing API, it will need multiple calls to perform these operations. But when you use the API Designer, you can combine these operations into a single API call.

Code-sub-image-2

In the above example, we are placing the definition inside the upsert node. This comprises the update and create node, which will update a record if it exists or create a record if it does not exist. To identify the record that needs to be updated, you can use the where to filter and find relevant entries. At the end of the definition, the return node will send back defined fields to the client. You can save and publish these APIs to make them available for external applications as well as internal VTAP Javascript.

Accessing a custom API published through the API Designer
  • To access any custom API published through API Designer, you will need to use the below endpoint.
  • https://your_instance.odx.vtiger.com/restapi/vtap/api/API_NAME?PARAMETERS
  • API_NAME should be replaced with the name given to the API. Also, ensure you are using the appropriate HTTP type and credentials(username and access key) to access it.
Accessing a recently created fetch_email_contact API using postman
  • To access a recently created fetch_email_contact API using postman, you should use the below.
  • https://your_instance.odx.vtiger.com/restapi/vtap/api/fetch_email_contact?domain=%vtiger.com%
Note : https://your_instance.odx.vtiger.com/restapi/v1/ApiDesigner/api/fetch_email_contact?domain=%vtiger.com% is deprecated.
Sub-image-3 (1)

These APIs can be accessed internally in Module Designer using VTAP Javascript API VTAP.CustomApi.Get to display inside a widget or custom pages in the Vtiger user interface.

Code-sub-image-3

To conclude, we saw how the API Designer tool allows you to write custom REST APIs and use them internally and in other applications to consume CRM data seamlessly. For any other queries, please send an email to platform@vtiger.com. Sign up for the developer edition here.
Copyright 2021 Vtiger | Privacy | Policy & Legal Center