{"id":11988,"date":"2019-06-21T14:19:19","date_gmt":"2019-06-21T11:19:19","guid":{"rendered":"https:\/\/trueconf.com\/blog\/?p=11988"},"modified":"2022-11-16T11:40:09","modified_gmt":"2022-11-16T08:40:09","slug":"how-to-use-trueconf-api-to-make-video-calls-from-the-website","status":"publish","type":"post","link":"https:\/\/trueconf.com/blog\/knowledge-base\/how-to-use-trueconf-api-to-make-video-calls-from-the-website","title":{"rendered":"How to Use TrueConf API to Make Video Calls from the Website"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">With<\/span> <a href=\"https:\/\/trueconf.com\/products\/server\/video-conferencing-server.html\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">TrueConf Server<\/span><\/a><span style=\"font-weight: 400;\"> API, you can create a click-to-call widget to make instant video calls from your website.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">This widget allows your website guests to call their managers for a personal video consultation at any time. They don\u2019t need to fill out any contact forms \u2014 just type in the name.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Adding the widget to your website is easy. Install TrueConf Server to get started<\/span><\/p>\n<div class=\"center\" style=\"text-align: center; padding: 10px;\"><a class=\"btn light-blue darken-2 waves-effect\" href=\"https:\/\/trueconf.com\/downloads\/trueconf-server\/\" target=\"_blank\" rel=\"noopener\">Download for Free<\/a><\/div>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">You won\u2019t spend<\/span><a href=\"https:\/\/trueconf.com\/blog\/knowledge-base\/get-video-conferencing-system-15-minutes.html\" target=\"_blank\" rel=\"noopener\"> <span style=\"font-weight: 400;\">more than 15 minutes<\/span><\/a><span style=\"font-weight: 400;\"> setting up the server.<\/span><!--more--><\/p>\n<h2 id=\"how-to-interact\" style=\"text-align: justify;\"><span style=\"font-weight: 400;\">How to Interact with API<\/span><\/h2>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">You can access TrueConf Server API via OAuth 2.0. For more information, please refer to<\/span><a href=\"https:\/\/docs.trueconf.com\/server\/en\/admin\/web-config#oauth2\" target=\"_blank\" rel=\"noopener\"> <span style=\"font-weight: 400;\">TrueConf Server documentation<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">TrueConf Server API is accessed through HTTP requests sent to the server.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The server sends back replies as JSON objects.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">A list of TrueConf Server API-based functions can be found below:<\/span><\/p>\n<p style=\"text-align: center;\"><a id=\"sbtn\" class=\"btn_green btn_download big_text\" href=\"https:\/\/developers.trueconf.com\/api\/server\/\" target=\"_blank\" rel=\"noopener noreferrer\">API Documentation<\/a><\/p>\n<h2 id=\"how-to-add-widget\"><span style=\"font-weight: 400;\">How to Add the Widget<\/span><\/h2>\n<p style=\"text-align: justify;\"><b>Step 1:<\/b><span style=\"font-weight: 400;\"> Make a <a href=\"https:\/\/trueconf.com\/features\/modes\/videocall.html\" target=\"_blank\" rel=\"noopener\">video call<\/a> to TrueConf Server through API requests. For this purpose, you should create a conference with two participants (one of them is your website manager).<\/span><\/p>\n<p><b>Step 2:<\/b><span style=\"font-weight: 400;\"> Get HTML code of your widget in TrueConf Server control panel.<\/span><\/p>\n<p><b>Step 3:<\/b><span style=\"font-weight: 400;\"> Add the widget to your website.<\/span><\/p>\n<p><b>Step 4:<\/b> Delete the conference after its ending.<\/p>\n<h2 id=\"how-to-use-api\"><span style=\"font-weight: 400;\">Creating and setting up a conference using API<\/span><\/h2>\n<h3><span style=\"font-weight: 400;\">TrueConf Server Setup<\/span><\/h3>\n<ol>\n<li><span style=\"font-weight: 400;\"> Configure the server to<\/span><a href=\"https:\/\/trueconf.com\/blog\/knowledge-base\/adjust-https-trueconf-server.html\" target=\"_blank\" rel=\"noopener\"> <span style=\"font-weight: 400;\">support HTTPS connections<\/span><\/a><\/li>\n<li><span style=\"font-weight: 400;\"> Add your website manager as a<\/span><a href=\"https:\/\/trueconf.com\/blog\/knowledge-base\/get-video-conferencing-system-15-minutes.html#add\" target=\"_blank\" rel=\"noopener\"> <span style=\"font-weight: 400;\">server user<\/span><\/a><span style=\"font-weight: 400;\"> to let them receive video calls from guests<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Create an <a href=\"https:\/\/trueconf.com\/blog\/knowledge-base\/how-to-get-started-with-trueconf-api.html#Step_1_Creating_OAuth_Application\" target=\"_blank\" rel=\"noopener\">OAuth 2.0 application.<\/a><\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Let\u2019s get started!<\/span><\/p>\n<h3 id=\"how-to-use-tcs-api\"><span style=\"font-weight: 400;\">How to Use TrueConf API<\/span><\/h3>\n<ol>\n<li>Obtain an API access token<\/li>\n<li style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Create a conference by using<\/span> <a href=\"https:\/\/developers.trueconf.com\/api\/server\/#api-Conferences-CreateConference\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Conferences<\/span><\/a><span style=\"font-weight: 400;\"> method and set the following parameters:<\/span><\/li>\n<\/ol>\n<ul style=\"text-align: justify;\">\n<li style=\"font-weight: 400;\"><code>\"schedule\":{\"type\":\"-1\"}<\/code><span style=\"font-weight: 400;\"> \u2014 <\/span><span style=\"font-weight: 400;\">without schedules<\/span><\/li>\n<li style=\"font-weight: 400;\"><code>\"max_participants\": 2<\/code><span style=\"font-weight: 400;\"> \u2014<\/span> <span style=\"font-weight: 400;\">for two participants<\/span><\/li>\n<li style=\"font-weight: 400;\"><code>\"allow_guests\": true<\/code> \u2013 the ability to invite<a href=\"https:\/\/trueconf.com\/blog\/wiki\/online-user-guest\" target=\"_blank\" rel=\"noopener\"> guests<\/a>.<\/li>\n<\/ul>\n<div class=\"marked_note marked_note--warning\">To connect guest users to the video conferences hosted on TrueConf Server, you need to add the <b>Public conferences<\/b> extension to your licence. To learn more about it, <a href=\"https:\/\/trueconf.com\/company\/contacts.html\" target=\"_blank\" rel=\"noopener\">contact us<\/a>.<\/div>\n<ul style=\"text-align: justify;\">\n<li style=\"font-weight: 400;\"><code>\"auto_invite\": 1<\/code><span style=\"font-weight: 400;\"> \u2014<\/span> automatic invitation of participants if any participant (including a guest) joins the conference. This parameter also can have values:\n<ul>\n<li>0 \u2013 do not send invitations (default value);<\/li>\n<li>2 \u2013 send invitations only if invited participants joins the conference.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Appoint your website manager as the<\/span><a href=\"https:\/\/trueconf.com\/blog\/wiki\/owner\" target=\"_blank\" rel=\"noopener\"> <span style=\"font-weight: 400;\">conference owner<\/span><\/a><span style=\"font-weight: 400;\"> and indicate their<\/span><a href=\"https:\/\/trueconf.com\/blog\/knowledge-base\/trueconf-id.html\" target=\"_blank\" rel=\"noopener\"> <span style=\"font-weight: 400;\">TrueConf Server username<\/span><\/a><span style=\"font-weight: 400;\">, e.g., <\/span><code>\"owner\":\"george\"<\/code><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">The following examples of TrueConf Server API requests are intended to be used with<\/span><a href=\"https:\/\/en.wikipedia.org\/wiki\/CURL\" target=\"_blank\" rel=\"noopener\"> <span style=\"font-weight: 400;\">cURL.<\/span><\/a><\/p>\n<div class=\"marked_note\">To handle requests, you can also use <a href=\"https:\/\/www.getpostman.com\/downloads\/\" target=\"_blank\" rel=\"noopener\">Postman<\/a> software, as described in the article about the introduction to TrueConf API.<\/div>\n<pre class=\"lang:default decode:true\">curl --request POST \\\r\n--url 'https:\/\/server.company.com\/api\/v3.1\/conferences?access_token=5a8212f4a2dcec763e3eeb8ca2dc78e1a6005be2' \\\r\n--header 'Content-Type: application\/json' \\\r\n--data '{ \"topic\": \"My Conference\", \"type\":0, \"auto_invite\": 1, \"max_participants\": 2, \"schedule\":{\"type\":\"-1\"}, \"owner\":\"george\"}, \"allow_guests\": true'<\/pre>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">If the conference has been successfully created, the server sends back a<\/span><a href=\"https:\/\/developers.trueconf.com\/api\/server\/#api-Objects-Conference\" target=\"_blank\" rel=\"noopener\"> <span style=\"font-weight: 400;\">reply with the conference data.<\/span><\/a><\/p>\n<pre class=\"lang:default decode:true \">{\r\n  \"id\": \"0560438410\",\r\n  \"type\": 0,\r\n  \"topic\": \"My Conference\",\r\n  \"owner\": \"george@server.company.com\",\r\n  \"description\": \"\",\r\n  \"max_podiums\": 2,\r\n  \"max_participants\": 2,\r\n  \"schedule\": {\r\n    \"type\": -1\r\n  },\r\n  \"invitations\": [],\r\n  \"url\": \"https:\/\/server.company.com\/c\/0560438410\",\r\n  \"webclient_url\": \"https:\/\/server.company.com\/webrtc\/0560438410\",\r\n  \"allow_guests\": true,\r\n  \"allow_guests_message\": true,\r\n  \"allow_guests_audio_video\": true,\r\n  \"auto_invite\": 1,\r\n  \"state\": \"stopped\"\r\n}<\/pre>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Save the <\/span><a href=\"https:\/\/trueconf.com\/blog\/wiki\/conference-id\" target=\"_blank\" rel=\"noopener\">ID <\/a><span style=\"font-weight: 400;\">parameter of<\/span><a href=\"https:\/\/trueconf.com\/blog\/wiki\/conference-page\" target=\"_blank\" rel=\"noopener\"> your conference page.<\/a><\/p>\n<ol style=\"text-align: justify;\" start=\"3\">\n<li><span style=\"font-weight: 400;\"> Add your website manager as a participant of the conference you have created (previously you have appointed them as the conference owner) by using\u00a0<\/span><a href=\"https:\/\/developers.trueconf.com\/api\/server\/#api-Conferences_Invitations-AddInvitation\" target=\"_blank\" rel=\"noopener\"> <span style=\"font-weight: 400;\">Conferences_Invitations<\/span><\/a><span style=\"font-weight: 400;\"> method. In <\/span><code>$conference_id<\/code><span style=\"font-weight: 400;\">, indicate <\/span><code>id<\/code><span style=\"font-weight: 400;\"> given in the previous paragraph.<\/span><\/li>\n<\/ol>\n<pre class=\"lang:default decode:true\">curl --request POST \\\r\n--url 'https:\/\/server.company.com\/api\/v3.1\/conferences\/0560438410\/invitations?access_token=5a8212f4a2dcec763e3eeb8ca2dc78e1a6005be2' \\\r\n --header 'Content-Type: application\/json' \\\r\n --data '{\"id\":\"george\"}'\r\n\r\n<\/pre>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">In response, the server sends back<\/span><a href=\"https:\/\/developers.trueconf.com\/api\/server\/#api-Objects-Invitation\" target=\"_blank\" rel=\"noopener\"> <span style=\"font-weight: 400;\">the object that contains data on the participant you have added.<\/span><\/a><\/p>\n<pre class=\"lang:default decode:true\">{\r\n    \"invitation\": {\r\n        \"id\": \"george\",\r\n        \"uid\": \"george@server.company.com\",\r\n        \"avatar\": null,\r\n        \"login_name\": \"george\",\r\n        \"email\": \"george@company.com\",\r\n        \"display_name\": \"Georgiy Jakovlev\",\r\n        \"first_name\": \"\",\r\n        \"last_name\": \"\",\r\n        \"company\": \"\",\r\n        \"groups\": [\r\n            {\r\n                \"id\": \"0002\",\r\n                \"display_name\": \"operators\",\r\n                \"rights\": []\r\n            }\r\n        ],\r\n        \"mobile_phone\": \"\",\r\n        \"work_phone\": \"\",\r\n        \"home_phone\": \"\",\r\n        \"is_active\": 1,\r\n        \"status\": 1,\r\n        \"is_owner\": 1,\r\n        \"type\": \"user\"\r\n    }\r\n}\r\n\r\n<\/pre>\n<ol start=\"4\">\n<li>To connect to the conference by-passing the authorization page, obtain login data from <a href=\"https:\/\/developers.trueconf.com\/api\/server\/#api-Software_Clients-GetClientList\" target=\"_blank\" rel=\"noopener\">Software_Clients &#8211; Get Client List<\/a>:<\/li>\n<\/ol>\n<pre class=\"lang:default decode:true\">curl --request GET \\\r\n--url 'https:\/\/server.company.com\/api\/v3.1\/software\/clients?call_id=0560438410'<\/pre>\n<p>The response will contain a JSON object with the list of all applications for connecting to a conference, including\u00a0 <code>\"name\": \"TrueConf Web\"<\/code> JSON object and login data to connect via WebRTC:<\/p>\n<pre class=\"lang:default decode:true\">{\r\n\u00a0\u00a0\u00a0\u00a0\"clients\": [\r\n\u00a0\u00a0\u00a0\u00a0...\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"name\": \"TrueConf Web\",\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"type\": \"web\",\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"platform\": \"webrtc\",\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"download_url\": \"\",\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"download_urls\": null,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"market_url\": \"\",\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"web_url\": \"https:\/\/server.company.com\/webrtc\/0560438410#login=*guest*guest&amp;token=$28e23b726661ddd12bcaebeae3f626c71*1576493428*30eb00e80f3068ff43236ffa5baaa557&amp;lang=auto\",\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\"iframe\": \"&lt;iframe src=\\\"https:\/\/server.company.com\/webrtc\/0560438410#login=*guest*guest&amp;token=$28e23b726661ddd12bcaebeae3f626c71*1576493428*30eb00e80f3068ff43236ffa5baaa557&amp;lang=auto\\\" allowfullscreen=\\\"allowfullscreen\\\" allow=\\\"microphone; camera; autoplay\\\" &gt;&lt;\\\\iframe&gt;\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0\u00a0]\r\n\u00a0\u00a0\u00a0\u00a0...\r\n}<\/pre>\n<p>Save the <code>web_url<\/code> parameter.<\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Well done!<\/span><\/p>\n<div class=\"marked_note\">You can make a test call via TrueConf Server API on <a href=\"https:\/\/trueconf.com\/blog\/knowledge-base\/how-to-test-trueconf-server-api.html\" target=\"_blank\" rel=\"noopener\">our website.<\/a><\/div>\n<h2 id=\"to-the-website\" style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Add the Widget to the Website<\/span><\/h2>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Use HTML code template of your widget which is available in TrueConf Server control panel<\/span><a href=\"https:\/\/trueconf.com\/blog\/knowledge-base\/embedding-trueconf-video-conferencing-into-your-website.html\" target=\"_blank\" rel=\"noopener\"> <span style=\"font-weight: 400;\">as shown in our article<\/span><\/a><span style=\"font-weight: 400;\">. Add <\/span><code>url<\/code><span style=\"font-weight: 400;\"> from the object with conference data you have previously received to <\/span><code>src<\/code><span style=\"font-weight: 400;\"> parameter.<\/span><\/p>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Once your website guest joins the conference via the widget, TrueConf Server automatically sends an invitation to the website manager (<\/span><code>auto_invite<\/code><span style=\"font-weight: 400;\"> parameter).<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Tracking widget events<\/span><\/h2>\n<p>The widget can send notifications about events and errors using <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Window\/postMessage\" target=\"_blank\" rel=\"noopener\">postMessage technology<\/a>. It will also send the following messages:<\/p>\n<ul>\n<li><code>notSupported<\/code> \u2013the browser does not meet requirements of the widget<\/li>\n<li><code>connectionFail<\/code> \u2013 a user could not connect to the server<\/li>\n<li><code>loginFail<\/code> \u2013 a user could not log in<\/li>\n<li><code>callFail<\/code> \u2013 a user could not join the conference<\/li>\n<li><code>hangUp<\/code> \u2013 a user hung up (left the conference)<\/li>\n<li><code>remoteHangUp<\/code>\u2013 a user was removed from the conference, e.g., by the moderator<\/li>\n<li><code>logout<\/code>\u2013 a user logged out<\/li>\n<li><code>connectionClosed<\/code>\u2013\u00a0 the user disconnected from the server.<\/li>\n<\/ul>\n<p>You can use such notifications for tracking the moment of conference ending, e.g.,\u00a0 <b>hangUp<\/b> or <b>remoteHangUp<\/b>.<\/p>\n<div class=\"marked_note marked_note--warning\">Start tracking messages before embedding the widget into your website; otherwise you may miss them.<\/div>\n<div>\n<h2><span style=\"font-weight: 400;\">Deleting a conference<\/span><\/h2>\n<ol>\n<li>You can only delete the conference that has already been ended. When you receive the message about the call ending, end the conference with the help of <a href=\"https:\/\/developers.trueconf.com\/api\/server\/#api-Conferences-StopConference\" target=\"_blank\" rel=\"noopener\">Conferences \u2013 Stop Conference<\/a> method:<\/li>\n<\/ol>\n<pre class=\"lang:default decode:true \">curl --request POST \\\r\n--url 'https:\/\/server.company.com\/api\/v3.1\/conferences\/0560438410\/stop?access_token=5a8212f4a2dcec763e3eeb8ca2dc78e1a6005be2'<\/pre>\n<p>In response, you receive a notification about the conference ending<\/p>\n<pre class=\"lang:default decode:true \">{\r\n\u00a0\u00a0\u00a0\u00a0\"state\": \"stopped\"\r\n}<\/pre>\n<ol>\n<li value=\"2\">Delete a conference with the help of <a href=\"https:\/\/developers.trueconf.com\/api\/server\/#api-Conferences-DeleteConference\" target=\"_blank\" rel=\"noopener\">Conferences \u2013 Delete Conference<\/a> method:<\/li>\n<\/ol>\n<pre class=\"lang:default decode:true \">curl --request DELETE \\\r\n--url 'https:\/\/server.company.com\/api\/v3.1\/conferences\/0560438410?access_token=5a8212f4a2dcec763e3eeb8ca2dc78e1a6005be2'<\/pre>\n<p>The answer request will contain the ID of the ended conference.<\/p>\n<pre class=\"lang:default decode:true \">{\r\n\u00a0\u00a0\u00a0\u00a0\"id\": \"0560438410\"\r\n}<\/pre>\n<\/div>\n<p style=\"text-align: justify;\"><span style=\"font-weight: 400;\">Happy video conferencing!<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>With TrueConf Server API, you can create a click-to-call widget to make instant video calls from your website. This widget allows your website guests to call their managers for a personal video consultation at any time. They don\u2019t need to fill out any contact forms \u2014 just type in the name. Adding the widget to [&hellip;]<\/p>\n","protected":false},"author":45,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[260],"tags":[246],"class_list":["post-11988","post","type-post","status-publish","format-standard","hentry","category-knowledge-base","tag-api-and-sdk","wpautop"],"_links":{"self":[{"href":"https:\/\/trueconf.com/blog\/wp-json\/wp\/v2\/posts\/11988","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trueconf.com/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trueconf.com/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trueconf.com/blog\/wp-json\/wp\/v2\/users\/45"}],"replies":[{"embeddable":true,"href":"https:\/\/trueconf.com/blog\/wp-json\/wp\/v2\/comments?post=11988"}],"version-history":[{"count":22,"href":"https:\/\/trueconf.com/blog\/wp-json\/wp\/v2\/posts\/11988\/revisions"}],"predecessor-version":[{"id":22464,"href":"https:\/\/trueconf.com/blog\/wp-json\/wp\/v2\/posts\/11988\/revisions\/22464"}],"wp:attachment":[{"href":"https:\/\/trueconf.com/blog\/wp-json\/wp\/v2\/media?parent=11988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trueconf.com/blog\/wp-json\/wp\/v2\/categories?post=11988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trueconf.com/blog\/wp-json\/wp\/v2\/tags?post=11988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}