How do I dynamically create a group and embed it on my site?

This article requires developer knowledge.

Find a parameter unique for each group

Every group you create needs to have a unique ID (GUID) attached to it. So if you are dynamically creating a group, each group must have a unique ID which you can use.

Use the Restful API to create a group

You can use our Restful API to create a new group. A sample code is:

curl --request POST \
  --url 'https://api.cometondemand.net/api/v2/createUser?UID=UID&name=name' \
  --header 'api-key: api-key'

Embed the group

You can Embed the group using the following code:

<script>
  var chat_appid = 'XXXXX';
  var chat_groupid = 'XXXXX';

  var chat_height = '350px';
  var chat_width = '420px';

    document.write('<div id="cometchat_embed_synergy_container" style="width:'+chat_width+';height:'+chat_height+';max-width:100%;border:1px solid #CCCCCC;border-radius:5px;overflow:hidden;"></div>';

  (function() {
    document.getElementsByTagName("head")[0].appendChild(css);
    var js = document.createElement('script'); js.type = 'text/javascript'; js.src = 'https://fast.cometondemand.net/'+chat_appid+'x_xchatx_xcorex_xembedcode.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(js, s);
  })();

var iframeObj = {};iframeObj.module="synergy";iframeObj.style="min-height:"+chat_height+";min-width:"+chat_width+";";iframeObj.width=chat_width.replace('px','');iframeObj.height=chat_height.replace('px','');iframeObj.src='https://'+chat_appid+'.cometondemand.net/cometchat_embedded.php?guid='+chat_groupid; if(typeof(addEmbedIframe)=="function"){addEmbedIframe(iframeObj);}
</script>

To learn more, visit our Restful API and our Developer Documentation.