Home  >   FAQs   >  What is Vtiger REST API method to write server scripts?
FAQs in this section

What is Vtiger REST API method to write server scripts?

Table of Contents
Vtiger REST API and webservice methods (vtap.macro.ws)
  • Vtiger’s REST API and webservice methods are available for CRM operations like create, update, delete, etc.
  • Authentication details are not needed. Methods handle it internally.
  • Parameters required vary depending on the method called.
  • Parameters expected are similar to REST API methods.
  • All methods are asynchronous and return a promise, therefore it must be used with await.
  • The provided methods are as below - 
    • Describe (vtap.macro.ws.describe) - Method to get module’s describe. This expects a single parameter elementType which is the module name for which describe is requested.
Example
var describe = await vtap.macro.ws.describe(‘Contacts’);
 
  • List Types (vtap.macro.ws.listtypes)  - Method to get a list of modules by field types. This method expects a single parameter fieldTypeList. If you want to get the list of modules having email or phone type fields, then pass field types as array. If you want to get the list of modules by single field type, you can pass the field type as array or string. If you want to get all modules list, you can skip passing this parameter value or pass as NULL.
Example
var list = await vtap.macro.ws.listtypes([‘email’, ‘phone’]);
 
  • Retrieve (vtap.macro.ws.retrieve) - Method to fetch a CRM record data. This method expects a single parameter id which is the record id in webservice format.
Example
var record = await vtap.macro.ws.retrieve(‘4x1234’);
 
  • Create (vtap.macro.ws.create) - Method to create a record in CRM. This method expects 2 parameters. elementType is the name of the module for which the record needs to be created and element is the record data object.
Example
var response = await vtap.macro.ws.create(‘Contacts’, {
firstname: ‘Jack’,
lastname: ‘Daniel’,
email: jack.d@company.com,
mobile: +1-1234-XXXXXXXX’,
assigned_user_id: ‘19x1’
});
 
  • Update (vtap.macro.ws.update) - Method to update a record in CRM. This method expects a single parameter element which is a JSON object containing all field values of the record.
Example
var response = await vtap.macro.ws.update({
id: ‘4x1234’,
firstname: ‘Jack’,
lastname: ‘Daniel’,
email: jack.daniel@company.com,
mobile: +1-234-XXX-XXXXXX’,
assigned_user_id: ‘19x6’
});
 
  • Revise (vtap.macro.ws.revise) - Method to revise a CRM record data. This method expects a single parameter element which is a JSON object containing record id and field values which need to be updated.
Example
var response = await vtap.macro.ws.revise({
id: ‘4x1234’,
secondaryemail: jackd01@mail.com,
phone: +1-5612-XXX-XXXXXXX’
});
 
  • Delete (vtap.macro.ws.delete) - Method to delete a record in CRM. This method expects a single parameter id which is the id of record to be deleted.
Example
var response = await vtap.macro.ws.delete(‘4x1234’);
 
  • Query (vtap.macro.ws.query) - Method to fetch CRM records using the query string. This method expects a single parameter query i.e. query string.
Example
var result = await vtap.macro.ws.query(“SELECT * FROM Contacts WHERE email != ORDER BY createdtime DESC LIMIT 10);
 
  • API (vtap.macro.ws.api) - Method to invoke other REST API methods which are not listed above. Vtiger’s REST API supports multiple APIs (reference). If you want to use any other API for which method is not listed above, you can use the following method (This method expects 3 parameters) - 
    • requestMethod - API request type (GET or POST).
    • API - Request API name (retrieve_related, query_related, add_related, reopen, converlead, etc)
    • Parameters - Object containing API request parameters
Example
var result = await vtap.macro.ws.api(‘GET’, ‘retrieve_related’, {
id: ‘6x2345’,
relatedLabel: ‘Potentials’,
relatedType: ‘Potentials’
});


 
Constraints:
  • Like HTTP request methods, rest API methods are also asynchronous. To wait for the promise, use await. Listening for promises using .then() is not supported.
  • To get the API error, use try-catch. In case parameters are missing or because of other reasons, the API call fails, it will be available as an error in the catch section.
Was this FAQ helpful?
0  out of  0  found this helpful.
Comments 0
Be the first to comment
© Copyright 2023 Vtiger. All rights reserved.