How run post api json request using function

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:

  1. var settings = {
  2. "async": true,
  3. "crossDomain": true,
  4. "url": "https://api.z-api.io/instances/MY_WHATSAPP/token/MY_TOKEN/send-text",
  5. "method": "POST",
  6. "headers": {
  7. "client-token": "{{security-token}}"
  8. },
  9. "processData": false,
  10. "data": "{\"phone\": \"5511999998888\", \"message\": \"Welcome to *Z-API*\"}"
  11. } $.ajax(settings).done(
  12. function (response) {
  13. console.log(response); });
  14. });

Asked chat gpt to convert it to deluge, ouptut was

  1. // Set the API URL
  2. url = "https://api.z-api.io/instances/YOUR_INSTANCE/token/YOUR_TOKEN/send-text";

  3. // Create an instance of HTTP client
  4. httpClient = new com.zoho.crm.library.restclient.HttpClient();

  5. // Set the request method as POST
  6. method = "POST";

  7. // Set the request headers
  8. headers = map();
  9. headers.put("content-type", "application/json");
  10. headers.put("client-token", "{{security-token}}");

  11. // Set the request parameters
  12. body = "{\"phone\": \"5511999998888\", \"message\": \"Welcome to *Z-API*\"}";

  13. // Send the request
  14. response = httpClient.post(url, method, headers, body);

  15. // Check the response
  16. 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?

here is documentation to send message: https://developer.z-api.io/en/message/send-message-text