question

Eugene Gold avatar image
Eugene Gold asked Eugene Gold published

Ring Central MMS API Not working in CRM Deluge

I am trying to send MMS using Ring Central MMS API in Zoho CRM, but it says bad request error when I use Content-Type = Multipart/Mixed that is mentioned in their API. I am unable to make request body. I have tried 2 codes, please anyone who has worked with this help me out.

Also when I use Content-Type = Application/json, it doesn't throw error but only plain text goes in MMS and file is not attached with MMS. Please anyone help me out ASAP.

========== Code - 1 ==========

leadDet = zoho.crm.getRecordById("Leads",3219374000000974287);

fname = "";

for each rcd in leadDet.get("MMS_Content")

{

fname = rcd.get("file_Name");

}

name = "";

name = name + ifnull(leadDet.get("First_Name"),"") + " ";

name = name + ifnull(leadDet.get("Last_Name"),"") + " ";

leadPhone = leadDet.get("Phone");

if(leadPhone != null && leadPhone != "")

{

info "In phone condition";

res3 = "";

res = leadPhone.remove("-");

res1 = res.remove("(");

res2 = res1.remove(")");

res3 = res2.remove("/");

info "PHONE: " + res3;

}

if(leadDet.get("Phone") != null && leadDet.get("Phone") != "")

{

// Getting lead MMS file

fileupload = leadDet.get("MMS_Content");

filelist = List();

file = "";

for each rec in fileupload

{

fileid = rec.get("attachment_Id");

file = invokeurl

[

url :" https://www.zohoapis.com/crm/v2/Leads/3219374000000974287/Attachments/" + fileid

type :GET

connection:"sign_conn"

];

info "File:" + file;

file.setparamName("file");

filelist.add(file);

// filelist.add(base64file);

}

// filelist.setparamName("attachments");

msg = "Test MMS Sep 9";

refresh_token = zoho.crm.getOrgVariable("mms_refresh_token");

//-------------- Genereate New Access Tokenm

url = "https://platform.devtest.ringcentral.com/restapi/oauth/token";

post_data = Map();

header = Map();

auth_code = "99nfVTJmQBGRBe6hnMB5Gw:45iWDpHLRgGvdEKcy7bXZgsHlZDplARxq_WTDPM6R-zA";

auth_code = zoho.encryption.base64Encode(auth_code);

//-------------- Set Post Data

post_data.put("refresh_token",refresh_token);

post_data.put("grant_type","refresh_token");

//-------------- Set Headers

header.put("Accept","application/json");

header.put("Content-Type","application/x-www-form-urlencoded");

header.put("Authorization","Basic " + auth_code);

//-------------- Get New Access Token

res = invokeurl

[

url :url

type :POST

parameters:post_data

headers:header

];

// info "Access Token: " + res;

if(res.get("access_token") != null)

{

access_token = res.get("access_token");

valueMap = Map();

//------------ Set Access token

valueMap.put("apiname","mms_access_token");

valueMap.put("value",access_token);

zoho.crm.invokeConnector("crm.set",valueMap);

//------------ Set Refresh token

valueMap = Map();

valueMap.put("apiname","mms_refresh_token");

valueMap.put("value",res.get("refresh_token"));

zoho.crm.invokeConnector("crm.set",valueMap);

//------------ Set Token Expire time

// New Token used to send MMS

to_iner = List();

to_map = Map();

header = Map();

data = Map();

from_map = Map();

to_number = res3;

header.put("Authorization","Bearer " + access_token);

header.put("Accept","application/json");

header.put("Content-Type","application/json");

//-------------- get main account info

url = "https://platform.devtest.ringcentral.com/restapi/v1.0/account/~";

res = invokeurl

[

url :url

type :GET

headers:header

];

// info "Main Account Info: " + res;

// info "To Number: " + to_number;

if(res.get("mainNumber") != null)

{

info "From: " + res.get("mainNumber");

// from_number = res.get("mainNumber");

// from_number = "+17372539331";

from_number = res.get("mainNumber");

// from_number = 3234739877;

//-------------- Send Ring SMS

mmsheader = Map();

mmsheader.put("authorization","Bearer " + access_token);

mmsheader.put("accept","application/json");

// mmsheader.put("Content-Type","application/json");

mmsheader.put("Content-Type","multipart/mixed");

eurl = "https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/mms";

from_map.put("phoneNumber",from_number);

to_map.put("phoneNumber",to_number);

to_iner.add(to_map);

data.put("from",from_map);

data.put("to",to_iner);

data.put("text",msg);

info "MAP:" + data;

// info "Files: " + filelist;

res1 = invokeurl

[

url :eurl

type :POST

parameters:data.toString()

headers:mmsheader

files:filelist

];

info "MMS Sent: " + res1;

// if(res.get("subject") != null && res.get("subject") != "")

// {

// // SMS Record

// smsRec = Map();

// smsRec.put("SMS_Content",res.get("subject"));

// smsRec.put("SMS_Status",res.get("direction"));

// smsRec.put("Lead_Phone",to_number);

// smsRec.put("Lead_Name",3219374000000974287);

// info zoho.crm.createRecord("SMS_History",smsRec);

// return "SMS Sent Successfully!";

// }

}

else

{

info "Main contact number is not found";

}

}

}

else

{

return "Phone number not found";

}

return "";

Request Body:

1631534139622.png


========= Code 2 ========


leadDet = zoho.crm.getRecordById("Leads",3219374000000974287);

fname = "";

for each rcd in leadDet.get("MMS_Content")

{

fname = rcd.get("file_Name");

}

name = "";

name = name + ifnull(leadDet.get("First_Name"),"") + " ";

name = name + ifnull(leadDet.get("Last_Name"),"") + " ";

leadPhone = leadDet.get("Phone");

if(leadPhone != null && leadPhone != "")

{

info "In phone condition";

res3 = "";

res = leadPhone.remove("-");

res1 = res.remove("(");

res2 = res1.remove(")");

res3 = res2.remove("/");

info "PHONE: " + res3;

}

if(leadDet.get("Phone") != null && leadDet.get("Phone") != "")

{

// Getting lead MMS file

fileupload = leadDet.get("MMS_Content");

filelist = List();

file = "";

for each rec in fileupload

{

fileid = rec.get("attachment_Id");

file = invokeurl

[

url :" https://www.zohoapis.com/crm/v2/Leads/3219374000000974287/Attachments/" + fileid

type :GET

connection:"sign_conn"

];

info "File:" + file;

file.setparamName("file");

base64file = zoho.encryption.base64Encode(file);

filelist.add("data:image/jpg;name="+file+";base64,"+base64file);

// filelist.add(base64file);

}

// filelist.setparamName("attachments");

msg = "Test MMS Sep 9";

refresh_token = zoho.crm.getOrgVariable("mms_refresh_token");

//-------------- Genereate New Access Tokenm

url = "https://platform.devtest.ringcentral.com/restapi/oauth/token";

post_data = Map();

header = Map();

auth_code = "99nfVTJmQBGRBe6hnMB5Gw:45iWDpHLRgGvdEKcy7bXZgsHlZDplARxq_WTDPM6R-zA";

auth_code = zoho.encryption.base64Encode(auth_code);

//-------------- Set Post Data

post_data.put("refresh_token",refresh_token);

post_data.put("grant_type","refresh_token");

//-------------- Set Headers

header.put("Accept","application/json");

header.put("Content-Type","application/x-www-form-urlencoded");

header.put("Authorization","Basic " + auth_code);

//-------------- Get New Access Token

res = invokeurl

[

url :url

type :POST

parameters:post_data

headers:header

];

info "Access Token: " + res;

if(res.get("access_token") != null)

{

access_token = res.get("access_token");

valueMap = Map();

//------------ Set Access token

valueMap.put("apiname","mms_access_token");

valueMap.put("value",access_token);

zoho.crm.invokeConnector("crm.set",valueMap);

//------------ Set Refresh token

valueMap = Map();

valueMap.put("apiname","mms_refresh_token");

valueMap.put("value",res.get("refresh_token"));

zoho.crm.invokeConnector("crm.set",valueMap);

//------------ Set Token Expire time

// New Token used to send MMS

to_iner = List();

to_map = Map();

header = Map();

data = Map();

from_map = Map();

to_number = res3;

header.put("Authorization","Bearer " + access_token);

header.put("Accept","application/json");

header.put("Content-Type","application/json");

//-------------- get main account info

url = "https://platform.devtest.ringcentral.com/restapi/v1.0/account/~";

res = invokeurl

[

url :url

type :GET

headers:header

];

info "Main Account Info: " + res;

info "To Number: " + to_number;

if(res.get("mainNumber") != null)

{

info "From: " + res.get("mainNumber");

// from_number = res.get("mainNumber");

// from_number = "+17372539331";

from_number = res.get("mainNumber");

// from_number = 3234739877;

//-------------- Send Ring SMS

mmsheader = Map();

mmsheader.put("authorization","Bearer " + access_token);

mmsheader.put("accept","application/json");

// mmsheader.put("Content-Type","application/json");

// mmsheader.put("Content-Disposition", "attachment;filename="+file+"");

mmsheader.put("Content-Type","multipart/mixed");

eurl = "https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/~/mms";

from_map.put("phoneNumber",from_number);

to_map.put("phoneNumber",to_number);

to_iner.add(to_map);

data.put("from",from_map);

data.put("to",to_iner);

data.put("text",msg);

data.put("attachments", filelist);

info "MAP:" + data;

info "Files: " + filelist;

res1 = invokeurl

[

url :eurl

type :POST

parameters:data.toString()

headers:mmsheader

];

info "MMS Sent: " + res1;

// if(res.get("subject") != null && res.get("subject") != "")

// {

// // SMS Record

// smsRec = Map();

// smsRec.put("SMS_Content",res.get("subject"));

// smsRec.put("SMS_Status",res.get("direction"));

// smsRec.put("Lead_Phone",to_number);

// smsRec.put("Lead_Name",3219374000000974287);

// info zoho.crm.createRecord("SMS_History",smsRec);

// return "SMS Sent Successfully!";

// }

}

else

{

info "Main contact number is not found";

}

}

}

else

{

return "Phone number not found";

}

return "";

1631534250144.png


rest api
1631534139622.png (125.9 KiB)
1631534250144.png (186.4 KiB)
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

0 Answers

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys