How run post api json request using function
Hi, i want to send whatsapp message using z-api service, they provide api to send messages. I whant execute it in workflow rule, inside functions.
They have api code example in javascript:
- var settings = {
- "async": true,
- "crossDomain": true,
- "url": "https://api.z-api.io/instances/MY_WHATSAPP/token/MY_TOKEN/send-text",
- "method": "POST",
- "headers": {
- "client-token": "{{security-token}}"
- },
- "processData": false,
- "data": "{\"phone\": \"5511999998888\", \"message\": \"Welcome to *Z-API*\"}"
- }
$.ajax(settings).done(
- function (response) {
- console.log(response);
});
- });
Asked chat gpt to convert it to deluge, ouptut was
- // Set the API URL
- url = "https://api.z-api.io/instances/YOUR_INSTANCE/token/YOUR_TOKEN/send-text";
- // Create an instance of HTTP client
- httpClient = new com.zoho.crm.library.restclient.HttpClient();
- // Set the request method as POST
- method = "POST";
- // Set the request headers
- headers = map();
- headers.put("content-type", "application/json");
- headers.put("client-token", "{{security-token}}");
- // Set the request parameters
- body = "{\"phone\": \"5511999998888\", \"message\": \"Welcome to *Z-API*\"}";
- // Send the request
- response = httpClient.post(url, method, headers, body);
- // Check the response
- info response.toString();
Tried test it, but it not works, give syntax error, see message: yntax error. Expecting executeshellscript task,expression,invokeurl task or 'invokeintegration'. Found 'com'. Line Number: 5
Somebody know how to solve?