HTTP request methods (vtap.macro.http)
- Methods include sending requests and receiving responses.
- Two parameters for all methods -
- URL (mandatory)
- Options (optional, for additional request details like headers, query strings, request body, form data, etc).
- Methods are asynchronous and return a promise, therefore it must be used with await.
- The provided methods are as below -
- GET (vtap.macro.http.get)
Example
var response = await vtap.macro.http.get(‘https://www.mywebsite.com’, { headers: { Authorization: ‘XXXXXXXXXXXXXXXXXX’ }, qs: { key1: ‘Value1’, key2: ‘Value2’ } }); |
POST (vtap.macro.http.post)
Example
var response = await vtap.macro.http.post(‘https://www.mywebsite.com’, { headers: { CUSTOM_HEADER_KEY: ‘HEADER VALUE’ }, body: { key1: ‘Value 1’, key2: ‘Value 2’ }, json: true }); |
PUT (vtap.macro.http.put)
Example
PATCH (vtap.macro.http.patch)
Example
| var response = await vtap.macro.http.patch(‘https://www/mywebsite.com’); |
DELETE (vtap.macro.http.delete)
Example
Constraints:
- Only HTTPS URLs with valid SSL certificates are allowed for sending requests.
- Insecure URLs, direct IPs (e.g., 127.0.0.1), and localhost are not permitted.
- Requests to any Vtiger’s domain are restricted, except for the instance URL where the code is executed.
- To handle request failures, use try-catch blocks.
- Place requests inside try blocks, and catch any errors for troubleshooting.
- Use try-catch to handle failed webservice requests.
- Place the requests inside the try block.
- If a request fails, the error will be available in the catch section for troubleshooting.