0

I can send Twilio SMS messages or no content-variable WhatsApp Messages on Oracle APEX using APEX_WEB_SERVICE.MAKE_REST_REQUEST

But when I try to add some parameters and send whatsapp messages with content templates, i get this error everytime.

Response:
{"code":21656,"message":"The Content Variables parameter is invalid.","more_info":"https://www.twilio.com/docs/errors/21656","status":400}

Statement processed.

0.28 seconds

My code block is below;

DECLARE
  l_url        VARCHAR2(4000) := 'https://api.twilio.com/2010-04-01/Accounts/ACXXXX/Messages.json';
  l_username   VARCHAR2(100) := 'ACXXXX';
  l_password   VARCHAR2(100) := 'edXXX';
  l_clob       CLOB;
BEGIN
  -- Send POST request using APEX_WEB_SERVICE
  l_clob := APEX_WEB_SERVICE.MAKE_REST_REQUEST(
    p_url         => l_url,
    p_http_method => 'POST',
    p_username    => l_username,
    p_password    => l_password,
    p_parm_name   => APEX_UTIL.STRING_TO_TABLE('To,From,ContentSid,ContentVariables', ','),
    p_parm_value  => APEX_UTIL.STRING_TO_TABLE(
                      'whatsapp:+905554443322,whatsapp:+905553332211,HX5f23e0b8005cb01e555a3887d17,{"1":"Mustafa Turhan","2":"0d039dea3bf260bda8951e63"}', ','
                    )
  );

  -- Log response
  DBMS_OUTPUT.put_line('Response:');
  DBMS_OUTPUT.put_line(DBMS_LOB.SUBSTR(l_clob, 4000, 1));

EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.put_line('Error: ' || SQLERRM);
END;

I've tried every syntax that comes to my mind but nothing worked. Successful request on Postman is here, see screenshot

4
  • the "{"1":"Mustafa Turhan","2":"0d039dea3bf260bda8951e63"}" subpart contains a comma on which you don't want to split. Commented May 20 at 10:45
  • i'm sorry, where? if you mean that comma between 2 parameters, it is needed by twilio Commented May 20 at 10:55
  • Yes they are needed by the syntax but when you use APEX_UTIL.STRING_TO_TABLE splitting on ',' then the internal comma comes into play and the result of the splitting is NOT what you expect: whatsapp:+905554443322, whatsapp:+905553332211, HX5f23e0b8005cb01e555a3887d17, {"1":"Mustafa Turhan" and "2":"0d039dea3bf260bda8951e63"}. Commented May 20 at 11:41
  • Yes, you were right. I changed commas with / then json worked. Thanks a lot! Commented May 20 at 12:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.