{"id":271605,"date":"2025-07-22T05:35:22","date_gmt":"2025-07-22T05:35:22","guid":{"rendered":"https:\/\/www.revechat.com\/?post_type=help-center&#038;p=271605"},"modified":"2025-07-22T05:36:33","modified_gmt":"2025-07-22T05:36:33","slug":"introduction-to-js-api","status":"publish","type":"help-center","link":"https:\/\/www.revechat.com\/help-center\/introduction-to-js-api\/","title":{"rendered":"Introduction to JavaScript API"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p>REVE Chat\u2019s API allows you to customize the visitor experience dynamically by setting attributes like the visitor\u2019s name, email, or other details before starting a chat.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Basic API Setup<\/h2>\n\n\n\n<p>Before you can use any ReveChat API methods, you\u2019ll need to include and initialize the ReveChat widget on your website.<\/p>\n\n\n\n<p>Here\u2019s the basic snippet you should add to your webpage before the closing &lt;\/body> tag:<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-http\">&lt;script type=&quot;text\/javascript&quot;&gt;\n  window.$_REVECHAT_API || (function(d, w) {\n    var r = $_REVECHAT_API = function(c) { r._.push(c); };\n    w.__revechat_account = &quot;3577764&quot;; \/\/ Replace with your ReveChat account ID\n    w.__revechat_version = 2;\n    r._ = [];\n    var rc = d.createElement(&quot;script&quot;);\n    rc.type = &quot;text\/javascript&quot;;\n    rc.async = true;\n    rc.setAttribute(&#039;charset&#039;, &#039;utf-8&#039;);\n    rc.src = (document.location.protocol === &#039;https:&#039; ? &#039;https:\/\/&#039; : &#039;http:\/\/&#039;) +\n      &#039;static.revechat.com\/widget\/scripts\/new-livechat.js?&#039; + new Date().getTime();\n    var s = d.getElementsByTagName(&#039;script&#039;)[0];\n    s.parentNode.insertBefore(rc, s);\n  })(document, window);\n&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<p>This snippet loads the REVE Chat widget and makes the API available through <code>$_REVECHAT_API<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example: Set Visitor Name<\/h3>\n\n\n\n<p>Once the widget has loaded, you can set the visitor\u2019s name using the following code: <\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-http\">&lt;script type=&quot;text\/javascript&quot;&gt;\n  $_REVECHAT_API(function() {\n    $_REVECHAT_API.Form.Online.setName(&quot;John&quot;);\n  });\n&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<p>Make sure this script runs after the initialization snippet above.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Complete Example<\/h3>\n\n\n\n<p>Here\u2019s the full example with both the widget loader and the API call together: html Copy Edit<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-\">&lt;script type=&quot;text\/javascript&quot;&gt;\n  window.$_REVECHAT_API || (function(d, w) {\n    var r = $_REVECHAT_API = function(c) { r._.push(c); };\n    w.__revechat_account = &quot;3577764&quot;; \/\/ Replace with your ReveChat account ID\n    w.__revechat_version = 2;\n    r._ = [];\n    var rc = d.createElement(&quot;script&quot;);\n    rc.type = &quot;text\/javascript&quot;;\n    rc.async = true;\n    rc.setAttribute(&#039;charset&#039;, &#039;utf-8&#039;);\n    rc.src = (document.location.protocol === &#039;https:&#039; ? &#039;https:\/\/&#039; : &#039;http:\/\/&#039;) +\n      &#039;static.revechat.com\/widget\/scripts\/new-livechat.js?&#039; + new Date().getTime();\n    var s = d.getElementsByTagName(&#039;script&#039;)[0];\n    s.parentNode.insertBefore(rc, s);\n  })(document, window);\n\n\n  $_REVECHAT_API(function() {\n    $_REVECHAT_API.Form.Online.setName(&quot;John&quot;);\n  });\n&lt;\/script&gt;\n<\/code><\/pre>\n\n\n\n<p>Replace <code>&quot;John&quot;<\/code> with the dynamic name of your visitor if you want to set it programmatically (e.g., from your logged-in user\u2019s name).<\/p>\n\n\n\n<p>If you need further assistance or have any questions about using the API, our support team is here to help. Email us at: <a href=\"mailto:support@revechat.com\">support@revechat.com<\/a><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>REVE Chat\u2019s API allows you to customize the visitor experience dynamically by setting attributes like the visitor\u2019s name, email, or other details before starting a chat. Basic API Setup Before you can use any ReveChat API methods, you\u2019ll need to include and initialize the ReveChat widget on your website. Here\u2019s the basic snippet you should [&hellip;]<\/p>\n","protected":false},"author":43,"featured_media":0,"menu_order":125,"template":"","meta":{"_acf_changed":false,"footnotes":""},"help_center_type":[1816],"class_list":["post-271605","help-center","type-help-center","status-publish","hentry","help_center_type-javascript-api"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.revechat.com\/wp-json\/wp\/v2\/help-center\/271605","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.revechat.com\/wp-json\/wp\/v2\/help-center"}],"about":[{"href":"https:\/\/www.revechat.com\/wp-json\/wp\/v2\/types\/help-center"}],"author":[{"embeddable":true,"href":"https:\/\/www.revechat.com\/wp-json\/wp\/v2\/users\/43"}],"version-history":[{"count":2,"href":"https:\/\/www.revechat.com\/wp-json\/wp\/v2\/help-center\/271605\/revisions"}],"predecessor-version":[{"id":271614,"href":"https:\/\/www.revechat.com\/wp-json\/wp\/v2\/help-center\/271605\/revisions\/271614"}],"wp:attachment":[{"href":"https:\/\/www.revechat.com\/wp-json\/wp\/v2\/media?parent=271605"}],"wp:term":[{"taxonomy":"help_center_type","embeddable":true,"href":"https:\/\/www.revechat.com\/wp-json\/wp\/v2\/help_center_type?post=271605"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}