<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Making Requests</title><link>https://community.telligent.com/community/11/w/developer-training/63122/making-requests</link><description /><dc:language>en-US</dc:language><generator>14.0.0.586 14</generator><item><title>Making Requests</title><link>https://community.telligent.com/community/11/w/developer-training/63122/making-requests</link><pubDate>Tue, 04 Aug 2020 18:15:22 GMT</pubDate><guid isPermaLink="false">739289b7-6a34-4a50-b03c-31adb488a8a4</guid><dc:creator>Former Member</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/63122/making-requests#comments</comments><description>Current Revision posted to Developer Training by Former Member on 08/04/2020 18:15:22&lt;br /&gt;
&lt;div class="content"&gt;
&lt;p&gt;The following guide is meant to provide a basic understanding of making REST requests using the Verint Community REST API. &amp;nbsp;We recommend always making requests over HTTPS. &amp;nbsp;To prevent authentication headers and data&amp;nbsp;from being intercepted, it is recommended to always use &lt;a title="HTTPS" href="https://en.wikipedia.org/wiki/HTTPS"&gt;HTTPS&lt;/a&gt;&amp;nbsp;to authenticate with your Verint Community website.&lt;/p&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;h3&gt;&lt;a name="get"&gt;&lt;/a&gt;GET&lt;/h3&gt;
&lt;p&gt;GET requests are used to request a LIST of entities or to SHOW details for one entity. A GET request is the simplest HTTP method. In this kind of request, all data is passed in the URL. The easiest way to understand a GET request is by comparing it to what happens when you type a URL into the address bar of your browser and click &lt;strong&gt;Go&lt;/strong&gt;: Your browser makes a GET request to that URL, retrieves the results returned by the Web site, and displays the results to you. A GET request sent to a Web service works the same way, except the request is usually performed via code.&lt;/p&gt;
&lt;p&gt;Sample SHOW user request using the [[api-documentation:Show User REST Endpoint|Show User REST Endpoint]].&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(&amp;quot;https://myverintcommunitysite.com/api.ashx/v2/{0}.json&amp;quot;,
    &amp;quot;username&amp;quot; // Username of the user we are returning
    ) as HttpWebRequest;
request.Method = &amp;quot;GET&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;
&lt;h3&gt;&lt;a name="post"&gt;&lt;/a&gt;POST&lt;/h3&gt;
&lt;p&gt;POST requests are translated as CREATE requests. Unlike GET requests, HTTP POST requests contain their data in the body of the request. If you have ever submitted a form online, you have probably submitted an HTTP POST request. You can&amp;#39;t create a POST request to a Web service directly from your browser without using a form, code, or browser plug-in.&lt;/p&gt;
&lt;p&gt;The easiest way to demonstrate a POST request is by using a little bit of C# code. The following code snippet demonstrates submitting a POST request to the Verint Community platform&amp;#39;s v2 Web services &lt;span style="font-family:courier new,courier;"&gt;Users &lt;/span&gt;endpoint. Performing the POST with the accompanying data to the &lt;span style="font-family:courier new,courier;"&gt;Users &lt;/span&gt;endpoint will CREATE a new user:&lt;/p&gt;
&lt;p&gt;Sample POST&amp;nbsp;request&amp;nbsp;using the&amp;nbsp;[[api-documentation:Create User REST Endpoint|Create User REST Endpoint]].&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(&amp;quot;https://myverintcommunitysite.com/api.ashx/v2/users.json&amp;quot;) as HttpWebRequest;
request.Method = &amp;quot;POST&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);
request.ContentType = &amp;quot;application/x-www-form-urlencoded&amp;quot;;

var data = string.Format(&amp;quot;Username={0}&amp;amp;Password={1}&amp;amp;PrivateEmail={2}&amp;quot;, 
    &amp;quot;username&amp;quot;, // Username of the user we are creating
    &amp;quot;password&amp;quot;, // Password of the user we are creating
    &amp;quot;username@mysite.com&amp;quot; // Private email address of the user we are creating
    );
byte[] bytes = Encoding.UTF8.GetBytes(data);

var requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;
&lt;h3&gt;&lt;a name="put"&gt;&lt;/a&gt;PUT&lt;/h3&gt;
&lt;p&gt;PUT requests are translated as UPDATE request. Like a &lt;a href="#post"&gt;POST&lt;/a&gt; request, a PUT request&amp;#39;s data is included within the message body. Performing a PUT request is very similar to performing a POST request. To update a user with an ID of 2132, you would perform a PUT request using code similar to the POST example above to the &lt;span style="font-family:courier new,courier;"&gt;http://localhost/api.ashx/v2/users/2132.xml&lt;/span&gt; endpoint.&lt;/p&gt;
&lt;p class="tdocs-note"&gt;&lt;strong&gt;&lt;a name="note-put"&gt;&lt;/a&gt;&lt;/strong&gt;Some Web servers, including IIS, disable PUT and DELETE requests by default for security purposes. For this reason the Verint Community platform&amp;#39;s v2 Web services provides overloads of the POST method for &lt;a href="#put"&gt;PUT&lt;/a&gt;&amp;nbsp;operations that allow you to perform PUT- like functions by making a &lt;a href="#post"&gt;POST&lt;/a&gt; request with a custom HTTP header of &lt;span style="font-family:courier new,courier;"&gt;Rest-Method: PUT&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Sample PUT request using the [[api-documentation:Update User REST Endpoint|Update User REST Endpoint]].&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(string.Format(&amp;quot;https://myverintcommunitysite.com/api.ashx/v2/users/{0}.json&amp;quot;, 
    &amp;quot;username&amp;quot; // Username of the user we are updating
    )) as HttpWebRequest;
request.Method = &amp;quot;POST&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);
request.Headers.Add(&amp;quot;Rest-Method&amp;quot;, &amp;quot;PUT&amp;quot;);
request.ContentType = &amp;quot;application/x-www-form-urlencoded&amp;quot;;

// We are only updating the users Private Email
var data = string.Format(&amp;quot;PrivateEmail={0}&amp;quot;, &amp;quot;username.updated@mysite.com&amp;quot;);
byte[] bytes = Encoding.UTF8.GetBytes(data);

var requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;
&lt;h3&gt;&lt;a name="delete"&gt;&lt;/a&gt;DELETE&lt;/h3&gt;
&lt;p&gt;Used for DELETE requests. If you make a DELETE request to &lt;span style="font-family:courier new,courier;"&gt;http://localhost/api.ashx/v2/users/2132.xml&lt;/span&gt;, you are asking that the user with ID 2132 be removed.&lt;/p&gt;
&lt;p class="tdocs-note"&gt;&lt;strong&gt;&lt;a name="note-delete"&gt;&lt;/a&gt;&lt;/strong&gt;Some Web servers, including IIS, disable PUT and DELETE requests by default for security purposes. For this reason the Verint Community platform&amp;#39;s v2 Web services provides overloads of the POST method for &lt;a href="#put"&gt;DELETE&lt;/a&gt; operations that allow you to perform DELETE-like functions by making a &lt;a href="#post"&gt;POST&lt;/a&gt; request with a custom HTTP header of &lt;span style="font-family:courier new,courier;"&gt;Rest-Method: DELETE&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Sample DELETE user request using the [[api-documentation:Delete User REST Endpoint|Delete User REST Endpoint]].&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(string.Format(&amp;quot;https://myverintcommunitysite.com/api.ashx/v2/users/{0}.xml?includetypes=true&amp;quot;, 
    &amp;quot;username&amp;quot; // Username of the user we are deleting
    )) as HttpWebRequest;
request.Method = &amp;quot;POST&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);
request.Headers.Add(&amp;quot;Rest-Method&amp;quot;, &amp;quot;DELETE&amp;quot;);
request.ContentLength = 0;

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;
&lt;h3&gt;&lt;a id="Using_the_Batch_REST_Endpoint" name="Using_the_Batch_REST_Endpoint"&gt;&lt;/a&gt;Using the Batch REST Endpoint&lt;/h3&gt;
&lt;p&gt;The [[api-documentation:Batch Batching REST Endpoint|BATCH REST Endpoint]]&amp;nbsp;can be used to make a series of REST request in a batch. &amp;nbsp;Up to 100 requests can be made in one batch request. &amp;nbsp;The batch request can also be set to run sequential. &amp;nbsp;When running sequential if one request fails, the remaining requests will not be executed. &amp;nbsp;Using this endpoint can offer performance by reducing the number of hops between the external application and Verint Community as well as by allowing requests to run simultaneously.&lt;/p&gt;
&lt;p&gt;The following sample uses the BATCH REST endpoint to create both a user and a group in one request.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(&amp;quot;https://myverintcommunitysite.com/api.ashx/v2/batch.json&amp;quot;) as HttpWebRequest;
request.Method = &amp;quot;POST&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);
request.ContentType = &amp;quot;application/x-www-form-urlencoded&amp;quot;;

var userData = string.Format(&amp;quot;Username={0}&amp;amp;Password={1}&amp;amp;PrivateEmail={2}&amp;quot;, 
    &amp;quot;username&amp;quot;, // Username of the user we are creating
    &amp;quot;password&amp;quot;, // Password of the user we are creating
    &amp;quot;username@mysite.com&amp;quot;); //Private email addres of the user we are creating

var groupData = string.Format(&amp;quot;Name={0}&amp;amp;GroupType={1}&amp;quot;, 
    &amp;quot;name&amp;quot;, // Name of the group we are creating
    &amp;quot;Joinless&amp;quot;); // Type of group we are creating

var batchData =
    string.Format(
        &amp;quot;_REQUEST_0_URL={0}&amp;amp;_REQUEST_0_METHOD={1}&amp;amp;_REQUEST_0_DATA={2}&amp;amp;_REQUEST_1_URL={3}&amp;amp;_REQUEST_1_METHOD={4}&amp;amp;_REQUEST_1_DATA={5}&amp;quot;,
        HttpUtility.UrlEncode(&amp;quot;~/api.ashx/v2/users.json&amp;quot;), 
        &amp;quot;POST&amp;quot;, 
        HttpUtility.UrlEncode(userData), 
        HttpUtility.UrlEncode(&amp;quot;~/api.ashx/v2/groups.json&amp;quot;), 
        &amp;quot;POST&amp;quot;, 
        HttpUtility.UrlEncode(groupData));

byte[] bytes = Encoding.UTF8.GetBytes(batchData);

var requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Using the above sample, the request&amp;nbsp;can be made to run&amp;nbsp;sequentially but adding the &lt;code&gt;&amp;amp;Sequential=true &lt;/code&gt;to the batchData querystring.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;var batchData =
string.Format(
    &amp;quot;_REQUEST_0_URL={0}&amp;amp;_REQUEST_0_METHOD={1}&amp;amp;_REQUEST_0_DATA={2}&amp;amp;_REQUEST_1_URL={3}&amp;amp;_REQUEST_1_METHOD={4}&amp;amp;_REQUEST_1_DATA={5}&amp;amp;Sequential=true&amp;quot;,
    HttpUtility.UrlEncode(&amp;quot;~/api.ashx/v2/users.json&amp;quot;), 
    &amp;quot;POST&amp;quot;, 
    HttpUtility.UrlEncode(userData), 
    HttpUtility.UrlEncode(&amp;quot;~/api.ashx/v2/groups.json&amp;quot;), 
    &amp;quot;POST&amp;quot;, 
    HttpUtility.UrlEncode(groupData));&lt;/pre&gt;&lt;/p&gt;
&lt;h3&gt;&lt;a id="Using_the_Scripting_REST_Endpoint" name="Using_the_Scripting_REST_Endpoint"&gt;&lt;/a&gt;Using the Scripting REST Endpoint&lt;/h3&gt;
&lt;p&gt;The [[api-documentation:Scripting REST Endpoints|Scripting REST Endpoint]]&amp;nbsp;is used to execute widgets through REST. &amp;nbsp;The&amp;nbsp;code sample is the widget used&amp;nbsp;in&amp;nbsp;the sample GET and POST requests. &amp;nbsp;The Scripting REST Endpoint offers performance advantages of &amp;nbsp;being able to make multiple API calls in one REST API call. &amp;nbsp;It also allows you to reduce the size of the HTTP response by only including fields you really need. &amp;nbsp;It also allows for responses&amp;nbsp;to be pre-rendered and can return any data type it wants:&amp;nbsp;HTML, CSV, XML, JSON, etc.&lt;/p&gt;
&lt;h4&gt;&lt;a id="GET" name="GET"&gt;&lt;/a&gt;GET&lt;/h4&gt;
&lt;p&gt;Create a new widget by going to Administration &amp;gt; Interface &amp;gt; Widgets. &amp;nbsp;Once the widget is created you will be shown the overview page where you can click the Show Details link to grab the Widget ID value that will be used with your Scripting REST Endpoint. &amp;nbsp;To learn more about widgets, see the [[Widgets]]&amp;nbsp;portion of this guide. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;The following sample widget accepts the QueryString parameters&amp;nbsp;ContentId and ContentTypeId&amp;nbsp;and will return a JSON&amp;nbsp;response which will include all comments along with any likes on the comments themselves for the ContentId and ContentTypeId passed in.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="velocity"&gt;$core_v2_page.SetContentType(&amp;#39;application/json&amp;#39;)

#set ($ContentId = $core_v2_utility.ParseGuid($core_v2_page.GetQueryStringValue(&amp;#39;ContentId&amp;#39;)))
#set ($ContentTypeId = $core_v2_utility.ParseGuid($core_v2_page.GetQueryStringValue(&amp;#39;ContentTypeId&amp;#39;)))

#if (!$core_v2_page.IsPost &amp;amp;&amp;amp; $ContentId &amp;amp;&amp;amp; $ContentTypeId)
#set($comments = $core_v2_comments.List(&amp;quot;%{ContentId = $ContentId, ContentTypeId = $ContentTypeId}&amp;quot;))
    {&amp;quot;Comments&amp;quot;: [
        #foreach($comment in $comments)
            #before
                {
            #each
            &amp;quot;Comment&amp;quot;:{
                #set($likes = $core_v2_like.List(&amp;quot;%{ContentId = $comment.CommentId, ContentTypeId = $core_v2_comments.ContentTypeId}&amp;quot;))
                #if ($likes.HasErrors())
    		        $core_v2_page.SendJsonError($likes.Errors)
    		    #else
                    &amp;quot;ContentId&amp;quot;: &amp;quot;$comment.ContentId&amp;quot;,&amp;quot;ContentTypeId&amp;quot;: &amp;quot;$comment.ContentTypeId&amp;quot;,&amp;quot;Body&amp;quot;: &amp;quot;$comment.Body&amp;quot;,&amp;quot;UserId&amp;quot;: &amp;quot;$comment.UserId&amp;quot;,&amp;quot;Likes&amp;quot;: [
                            #foreach($like in $likes)
                                #before
                                {
                                #each
                                    &amp;quot;Like&amp;quot;:{&amp;quot;UserId&amp;quot;:&amp;quot;$like.UserId&amp;quot;,&amp;quot;CreatedDate&amp;quot;:&amp;quot;$like.CreatedDate&amp;quot;}
                                #after
                                }
                            #end
                            ]
            #after
                }
                #end
            }
        #end
    ]}
#end&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The following sample GET request calls the sample widget using the Scripted REST Endpoint. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(string.Format(&amp;quot;https://mytelligentcommunitysite.com/api.ashx/v2/scripted?Id={0}&amp;amp;ContentId={1}&amp;amp;ContentTypeId={2}&amp;quot;, 
    &amp;quot;709a35f5-150e-443a-8483-4907a3efec60&amp;quot;, //Widget ID of the widget we are calling
    &amp;quot;BC21522C-39D8-4020-B14A-DA623B9F2C64&amp;quot;, //ContentId of the item we are trying to retrieve comments on
    &amp;quot;6B577B8C-0470-4E20-9D29-B6772BF67243&amp;quot; //ContentTypeId of the item we are trying to retrieve comments on
    )) as HttpWebRequest;
request.Method = &amp;quot;GET&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);
request.ContentType = &amp;quot;application/x-www-form-urlencoded&amp;quot;;

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;
&lt;h4&gt;&lt;a id="POST" name="POST"&gt;&lt;/a&gt;POST&lt;/h4&gt;
&lt;p&gt;Create a new widget by going to Administration &amp;gt; Interface &amp;gt; Widgets. &amp;nbsp;Once the widget is created you will be shown the overview page where you can click the Show Details link to grab the Widget ID value that will be used with your Scripting REST Endpoint. &amp;nbsp;To learn more about widgets, see the [[Widgets]]&amp;nbsp;portion of this guide. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;The following sample widget accepts the QueryString parameters&amp;nbsp;ContentId and ContentTypeId&amp;nbsp;and create a like on the associated content. &amp;nbsp;The response will be return as JSON.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="velocity"&gt;$core_v2_page.SetContentType(&amp;#39;application/json&amp;#39;)

#set ($ContentId = $core_v2_utility.ParseGuid($core_v2_page.GetQueryStringValue(&amp;#39;ContentId&amp;#39;)))
#set ($ContentTypeId = $core_v2_utility.ParseGuid($core_v2_page.GetQueryStringValue(&amp;#39;ContentTypeId&amp;#39;)))

#if ($core_v2_page.IsPost &amp;amp;&amp;amp; $ContentId &amp;amp;&amp;amp; $ContentTypeId)
    #set($likeResponse = $core_v2_like.Create($ContentId, $ContentTypeId))
    {&amp;quot;Like&amp;quot;: {&amp;quot;UserId&amp;quot;:&amp;quot;$likeResponse.UserId&amp;quot;,&amp;quot;ContentId&amp;quot;:&amp;quot;$likeResponse.ContentId&amp;quot;,&amp;quot;CreatedDate&amp;quot;:&amp;quot;$likeResponse.CreatedDate&amp;quot;}}
#end&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The following sample POST&amp;nbsp;request calls the sample widget using the Scripted REST Endpoint. &amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(string.Format(&amp;quot;https://mytelligentcommunitysite.com/api.ashx/v2/scripted?Id={0}&amp;amp;ContentId={1}&amp;amp;ContentTypeId={2}&amp;quot;,
    &amp;quot;9127c3e9-813c-429e-84a0-743bbd414c24&amp;quot;, //Widget ID of the widget we are calling
    &amp;quot;BC21522C-39D8-4020-B14A-DA623B9F2C64&amp;quot;, //ContentId of the item we are creating a like on
    &amp;quot;6B577B8C-0470-4E20-9D29-B6772BF67243&amp;quot; //ContentTypeId of the item we are creating a like on
   )) as HttpWebRequest;
request.Method = &amp;quot;POST&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);
request.ContentLength = 0;

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item><item><title>Making Requests</title><link>https://community.telligent.com/community/11/w/developer-training/63122/making-requests/revision/2</link><pubDate>Tue, 04 Aug 2020 18:14:10 GMT</pubDate><guid isPermaLink="false">739289b7-6a34-4a50-b03c-31adb488a8a4</guid><dc:creator>Former Member</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/63122/making-requests#comments</comments><description>Revision 2 posted to Developer Training by Former Member on 08/04/2020 18:14:10&lt;br /&gt;
&lt;div class="content"&gt;
&lt;p&gt;The following guide is meant to provide a basic understanding of making REST requests using the Verint Community REST API. &amp;nbsp;We recommend always making requests over HTTPS. &amp;nbsp;To prevent authentication headers and data&amp;nbsp;from being intercepted, it is recommended to always use &lt;a title="HTTPS" href="https://en.wikipedia.org/wiki/HTTPS"&gt;HTTPS&lt;/a&gt;&amp;nbsp;to authenticate with your Verint Community website.&lt;/p&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;h3&gt;&lt;a name="get"&gt;&lt;/a&gt;GET&lt;/h3&gt;
&lt;p&gt;GET requests are used to request a LIST of entities or to SHOW details for one entity. A GET request is the simplest HTTP method. In this kind of request, all data is passed in the URL. The easiest way to understand a GET request is by comparing it to what happens when you type a URL into the address bar of your browser and click &lt;strong&gt;Go&lt;/strong&gt;: Your browser makes a GET request to that URL, retrieves the results returned by the Web site, and displays the results to you. A GET request sent to a Web service works the same way, except the request is usually performed via code.&lt;/p&gt;
&lt;p&gt;Sample SHOW user request using the [[api-documentation:Show User REST Endpoint|Show User REST Endpoint]].&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(&amp;quot;https://mytelligentcommunitysite.com/api.ashx/v2/{0}.json&amp;quot;,
    &amp;quot;username&amp;quot; // Username of the user we are returning
    ) as HttpWebRequest;
request.Method = &amp;quot;GET&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;
&lt;h3&gt;&lt;a name="post"&gt;&lt;/a&gt;POST&lt;/h3&gt;
&lt;p&gt;POST requests are translated as CREATE requests. Unlike GET requests, HTTP POST requests contain their data in the body of the request. If you have ever submitted a form online, you have probably submitted an HTTP POST request. You can&amp;#39;t create a POST request to a Web service directly from your browser without using a form, code, or browser plug-in.&lt;/p&gt;
&lt;p&gt;The easiest way to demonstrate a POST request is by using a little bit of C# code. The following code snippet demonstrates submitting a POST request to the Verint Community platform&amp;#39;s v2 Web services &lt;span style="font-family:courier new,courier;"&gt;Users &lt;/span&gt;endpoint. Performing the POST with the accompanying data to the &lt;span style="font-family:courier new,courier;"&gt;Users &lt;/span&gt;endpoint will CREATE a new user:&lt;/p&gt;
&lt;p&gt;Sample POST&amp;nbsp;request&amp;nbsp;using the&amp;nbsp;[[api-documentation:Create User REST Endpoint|Create User REST Endpoint]].&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(&amp;quot;https://mytelligentcommunitysite.com/api.ashx/v2/users.json&amp;quot;) as HttpWebRequest;
request.Method = &amp;quot;POST&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);
request.ContentType = &amp;quot;application/x-www-form-urlencoded&amp;quot;;

var data = string.Format(&amp;quot;Username={0}&amp;amp;Password={1}&amp;amp;PrivateEmail={2}&amp;quot;, 
    &amp;quot;username&amp;quot;, // Username of the user we are creating
    &amp;quot;password&amp;quot;, // Password of the user we are creating
    &amp;quot;username@mysite.com&amp;quot; // Private email address of the user we are creating
    );
byte[] bytes = Encoding.UTF8.GetBytes(data);

var requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;
&lt;h3&gt;&lt;a name="put"&gt;&lt;/a&gt;PUT&lt;/h3&gt;
&lt;p&gt;PUT requests are translated as UPDATE request. Like a &lt;a href="#post"&gt;POST&lt;/a&gt; request, a PUT request&amp;#39;s data is included within the message body. Performing a PUT request is very similar to performing a POST request. To update a user with an ID of 2132, you would perform a PUT request using code similar to the POST example above to the &lt;span style="font-family:courier new,courier;"&gt;http://localhost/api.ashx/v2/users/2132.xml&lt;/span&gt; endpoint.&lt;/p&gt;
&lt;p class="tdocs-note"&gt;&lt;strong&gt;&lt;a name="note-put"&gt;&lt;/a&gt;&lt;/strong&gt;Some Web servers, including IIS, disable PUT and DELETE requests by default for security purposes. For this reason the Verint Community platform&amp;#39;s v2 Web services provides overloads of the POST method for &lt;a href="#put"&gt;PUT&lt;/a&gt;&amp;nbsp;operations that allow you to perform PUT- like functions by making a &lt;a href="#post"&gt;POST&lt;/a&gt; request with a custom HTTP header of &lt;span style="font-family:courier new,courier;"&gt;Rest-Method: PUT&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Sample PUT request using the [[api-documentation:Update User REST Endpoint|Update User REST Endpoint]].&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(string.Format(&amp;quot;https://mytelligentcommunitysite.com/api.ashx/v2/users/{0}.json&amp;quot;, 
    &amp;quot;username&amp;quot; // Username of the user we are updating
    )) as HttpWebRequest;
request.Method = &amp;quot;POST&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);
request.Headers.Add(&amp;quot;Rest-Method&amp;quot;, &amp;quot;PUT&amp;quot;);
request.ContentType = &amp;quot;application/x-www-form-urlencoded&amp;quot;;

// We are only updating the users Private Email
var data = string.Format(&amp;quot;PrivateEmail={0}&amp;quot;, &amp;quot;username.updated@mysite.com&amp;quot;);
byte[] bytes = Encoding.UTF8.GetBytes(data);

var requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;
&lt;h3&gt;&lt;a name="delete"&gt;&lt;/a&gt;DELETE&lt;/h3&gt;
&lt;p&gt;Used for DELETE requests. If you make a DELETE request to &lt;span style="font-family:courier new,courier;"&gt;http://localhost/api.ashx/v2/users/2132.xml&lt;/span&gt;, you are asking that the user with ID 2132 be removed.&lt;/p&gt;
&lt;p class="tdocs-note"&gt;&lt;strong&gt;&lt;a name="note-delete"&gt;&lt;/a&gt;&lt;/strong&gt;Some Web servers, including IIS, disable PUT and DELETE requests by default for security purposes. For this reason the Verint Community platform&amp;#39;s v2 Web services provides overloads of the POST method for &lt;a href="#put"&gt;DELETE&lt;/a&gt; operations that allow you to perform DELETE-like functions by making a &lt;a href="#post"&gt;POST&lt;/a&gt; request with a custom HTTP header of &lt;span style="font-family:courier new,courier;"&gt;Rest-Method: DELETE&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Sample DELETE user request using the [[api-documentation:Delete User REST Endpoint|Delete User REST Endpoint]].&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(string.Format(&amp;quot;https://mytelligentcommunitysite.com/api.ashx/v2/users/{0}.xml?includetypes=true&amp;quot;, 
    &amp;quot;username&amp;quot; // Username of the user we are deleting
    )) as HttpWebRequest;
request.Method = &amp;quot;POST&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);
request.Headers.Add(&amp;quot;Rest-Method&amp;quot;, &amp;quot;DELETE&amp;quot;);
request.ContentLength = 0;

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;
&lt;h3&gt;&lt;a id="Using_the_Batch_REST_Endpoint" name="Using_the_Batch_REST_Endpoint"&gt;&lt;/a&gt;Using the Batch REST Endpoint&lt;/h3&gt;
&lt;p&gt;The [[api-documentation:Batch Batching REST Endpoint|BATCH REST Endpoint]]&amp;nbsp;can be used to make a series of REST request in a batch. &amp;nbsp;Up to 100 requests can be made in one batch request. &amp;nbsp;The batch request can also be set to run sequential. &amp;nbsp;When running sequential if one request fails, the remaining requests will not be executed. &amp;nbsp;Using this endpoint can offer performance by reducing the number of hops between the external application and Verint Community as well as by allowing requests to run simultaneously.&lt;/p&gt;
&lt;p&gt;The following sample uses the BATCH REST endpoint to create both a user and a group in one request.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(&amp;quot;https://mytelligentcommunitysite.com/api.ashx/v2/batch.json&amp;quot;) as HttpWebRequest;
request.Method = &amp;quot;POST&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);
request.ContentType = &amp;quot;application/x-www-form-urlencoded&amp;quot;;

var userData = string.Format(&amp;quot;Username={0}&amp;amp;Password={1}&amp;amp;PrivateEmail={2}&amp;quot;, 
    &amp;quot;username&amp;quot;, // Username of the user we are creating
    &amp;quot;password&amp;quot;, // Password of the user we are creating
    &amp;quot;username@mysite.com&amp;quot;); //Private email addres of the user we are creating

var groupData = string.Format(&amp;quot;Name={0}&amp;amp;GroupType={1}&amp;quot;, 
    &amp;quot;name&amp;quot;, // Name of the group we are creating
    &amp;quot;Joinless&amp;quot;); // Type of group we are creating

var batchData =
    string.Format(
        &amp;quot;_REQUEST_0_URL={0}&amp;amp;_REQUEST_0_METHOD={1}&amp;amp;_REQUEST_0_DATA={2}&amp;amp;_REQUEST_1_URL={3}&amp;amp;_REQUEST_1_METHOD={4}&amp;amp;_REQUEST_1_DATA={5}&amp;quot;,
        HttpUtility.UrlEncode(&amp;quot;~/api.ashx/v2/users.json&amp;quot;), 
        &amp;quot;POST&amp;quot;, 
        HttpUtility.UrlEncode(userData), 
        HttpUtility.UrlEncode(&amp;quot;~/api.ashx/v2/groups.json&amp;quot;), 
        &amp;quot;POST&amp;quot;, 
        HttpUtility.UrlEncode(groupData));

byte[] bytes = Encoding.UTF8.GetBytes(batchData);

var requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Using the above sample, the request&amp;nbsp;can be made to run&amp;nbsp;sequentially but adding the &lt;code&gt;&amp;amp;Sequential=true &lt;/code&gt;to the batchData querystring.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;var batchData =
string.Format(
    &amp;quot;_REQUEST_0_URL={0}&amp;amp;_REQUEST_0_METHOD={1}&amp;amp;_REQUEST_0_DATA={2}&amp;amp;_REQUEST_1_URL={3}&amp;amp;_REQUEST_1_METHOD={4}&amp;amp;_REQUEST_1_DATA={5}&amp;amp;Sequential=true&amp;quot;,
    HttpUtility.UrlEncode(&amp;quot;~/api.ashx/v2/users.json&amp;quot;), 
    &amp;quot;POST&amp;quot;, 
    HttpUtility.UrlEncode(userData), 
    HttpUtility.UrlEncode(&amp;quot;~/api.ashx/v2/groups.json&amp;quot;), 
    &amp;quot;POST&amp;quot;, 
    HttpUtility.UrlEncode(groupData));&lt;/pre&gt;&lt;/p&gt;
&lt;h3&gt;&lt;a id="Using_the_Scripting_REST_Endpoint" name="Using_the_Scripting_REST_Endpoint"&gt;&lt;/a&gt;Using the Scripting REST Endpoint&lt;/h3&gt;
&lt;p&gt;The [[api-documentation:Scripting REST Endpoints|Scripting REST Endpoint]]&amp;nbsp;is used to execute widgets through REST. &amp;nbsp;The&amp;nbsp;code sample is the widget used&amp;nbsp;in&amp;nbsp;the sample GET and POST requests. &amp;nbsp;The Scripting REST Endpoint offers performance advantages of &amp;nbsp;being able to make multiple API calls in one REST API call. &amp;nbsp;It also allows you to reduce the size of the HTTP response by only including fields you really need. &amp;nbsp;It also allows for responses&amp;nbsp;to be pre-rendered and can return any data type it wants:&amp;nbsp;HTML, CSV, XML, JSON, etc.&lt;/p&gt;
&lt;h4&gt;&lt;a id="GET" name="GET"&gt;&lt;/a&gt;GET&lt;/h4&gt;
&lt;p&gt;Create a new widget by going to Administration &amp;gt; Interface &amp;gt; Widgets. &amp;nbsp;Once the widget is created you will be shown the overview page where you can click the Show Details link to grab the Widget ID value that will be used with your Scripting REST Endpoint. &amp;nbsp;To learn more about widgets, see the [[Widgets]]&amp;nbsp;portion of this guide. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;The following sample widget accepts the QueryString parameters&amp;nbsp;ContentId and ContentTypeId&amp;nbsp;and will return a JSON&amp;nbsp;response which will include all comments along with any likes on the comments themselves for the ContentId and ContentTypeId passed in.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="velocity"&gt;$core_v2_page.SetContentType(&amp;#39;application/json&amp;#39;)

#set ($ContentId = $core_v2_utility.ParseGuid($core_v2_page.GetQueryStringValue(&amp;#39;ContentId&amp;#39;)))
#set ($ContentTypeId = $core_v2_utility.ParseGuid($core_v2_page.GetQueryStringValue(&amp;#39;ContentTypeId&amp;#39;)))

#if (!$core_v2_page.IsPost &amp;amp;&amp;amp; $ContentId &amp;amp;&amp;amp; $ContentTypeId)
#set($comments = $core_v2_comments.List(&amp;quot;%{ContentId = $ContentId, ContentTypeId = $ContentTypeId}&amp;quot;))
    {&amp;quot;Comments&amp;quot;: [
        #foreach($comment in $comments)
            #before
                {
            #each
            &amp;quot;Comment&amp;quot;:{
                #set($likes = $core_v2_like.List(&amp;quot;%{ContentId = $comment.CommentId, ContentTypeId = $core_v2_comments.ContentTypeId}&amp;quot;))
                #if ($likes.HasErrors())
    		        $core_v2_page.SendJsonError($likes.Errors)
    		    #else
                    &amp;quot;ContentId&amp;quot;: &amp;quot;$comment.ContentId&amp;quot;,&amp;quot;ContentTypeId&amp;quot;: &amp;quot;$comment.ContentTypeId&amp;quot;,&amp;quot;Body&amp;quot;: &amp;quot;$comment.Body&amp;quot;,&amp;quot;UserId&amp;quot;: &amp;quot;$comment.UserId&amp;quot;,&amp;quot;Likes&amp;quot;: [
                            #foreach($like in $likes)
                                #before
                                {
                                #each
                                    &amp;quot;Like&amp;quot;:{&amp;quot;UserId&amp;quot;:&amp;quot;$like.UserId&amp;quot;,&amp;quot;CreatedDate&amp;quot;:&amp;quot;$like.CreatedDate&amp;quot;}
                                #after
                                }
                            #end
                            ]
            #after
                }
                #end
            }
        #end
    ]}
#end&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The following sample GET request calls the sample widget using the Scripted REST Endpoint. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(string.Format(&amp;quot;https://mytelligentcommunitysite.com/api.ashx/v2/scripted?Id={0}&amp;amp;ContentId={1}&amp;amp;ContentTypeId={2}&amp;quot;, 
    &amp;quot;709a35f5-150e-443a-8483-4907a3efec60&amp;quot;, //Widget ID of the widget we are calling
    &amp;quot;BC21522C-39D8-4020-B14A-DA623B9F2C64&amp;quot;, //ContentId of the item we are trying to retrieve comments on
    &amp;quot;6B577B8C-0470-4E20-9D29-B6772BF67243&amp;quot; //ContentTypeId of the item we are trying to retrieve comments on
    )) as HttpWebRequest;
request.Method = &amp;quot;GET&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);
request.ContentType = &amp;quot;application/x-www-form-urlencoded&amp;quot;;

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;
&lt;h4&gt;&lt;a id="POST" name="POST"&gt;&lt;/a&gt;POST&lt;/h4&gt;
&lt;p&gt;Create a new widget by going to Administration &amp;gt; Interface &amp;gt; Widgets. &amp;nbsp;Once the widget is created you will be shown the overview page where you can click the Show Details link to grab the Widget ID value that will be used with your Scripting REST Endpoint. &amp;nbsp;To learn more about widgets, see the [[Widgets]]&amp;nbsp;portion of this guide. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;The following sample widget accepts the QueryString parameters&amp;nbsp;ContentId and ContentTypeId&amp;nbsp;and create a like on the associated content. &amp;nbsp;The response will be return as JSON.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="velocity"&gt;$core_v2_page.SetContentType(&amp;#39;application/json&amp;#39;)

#set ($ContentId = $core_v2_utility.ParseGuid($core_v2_page.GetQueryStringValue(&amp;#39;ContentId&amp;#39;)))
#set ($ContentTypeId = $core_v2_utility.ParseGuid($core_v2_page.GetQueryStringValue(&amp;#39;ContentTypeId&amp;#39;)))

#if ($core_v2_page.IsPost &amp;amp;&amp;amp; $ContentId &amp;amp;&amp;amp; $ContentTypeId)
    #set($likeResponse = $core_v2_like.Create($ContentId, $ContentTypeId))
    {&amp;quot;Like&amp;quot;: {&amp;quot;UserId&amp;quot;:&amp;quot;$likeResponse.UserId&amp;quot;,&amp;quot;ContentId&amp;quot;:&amp;quot;$likeResponse.ContentId&amp;quot;,&amp;quot;CreatedDate&amp;quot;:&amp;quot;$likeResponse.CreatedDate&amp;quot;}}
#end&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The following sample POST&amp;nbsp;request calls the sample widget using the Scripted REST Endpoint. &amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(string.Format(&amp;quot;https://mytelligentcommunitysite.com/api.ashx/v2/scripted?Id={0}&amp;amp;ContentId={1}&amp;amp;ContentTypeId={2}&amp;quot;,
    &amp;quot;9127c3e9-813c-429e-84a0-743bbd414c24&amp;quot;, //Widget ID of the widget we are calling
    &amp;quot;BC21522C-39D8-4020-B14A-DA623B9F2C64&amp;quot;, //ContentId of the item we are creating a like on
    &amp;quot;6B577B8C-0470-4E20-9D29-B6772BF67243&amp;quot; //ContentTypeId of the item we are creating a like on
   )) as HttpWebRequest;
request.Method = &amp;quot;POST&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);
request.ContentLength = 0;

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item><item><title>Making Requests</title><link>https://community.telligent.com/community/11/w/developer-training/63122/making-requests/revision/1</link><pubDate>Tue, 04 Jun 2019 20:37:50 GMT</pubDate><guid isPermaLink="false">739289b7-6a34-4a50-b03c-31adb488a8a4</guid><dc:creator>Ben Tiedt</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/63122/making-requests#comments</comments><description>Revision 1 posted to Developer Training by Ben Tiedt on 06/04/2019 20:37:50&lt;br /&gt;
&lt;div class="content"&gt;
&lt;p&gt;The following guide is meant to provide a basic understanding of making REST requests using the Telligent Community REST API. &amp;nbsp;We recommend always making requests over HTTPS. &amp;nbsp;To prevent authentication headers and data&amp;nbsp;from being intercepted, it is recommended to always use &lt;a title="HTTPS" href="https://en.wikipedia.org/wiki/HTTPS"&gt;HTTPS&lt;/a&gt;&amp;nbsp;to authenticate with your Telligent Community website.&lt;/p&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;h3&gt;&lt;a name="get"&gt;&lt;/a&gt;GET&lt;/h3&gt;
&lt;p&gt;GET requests are used to request a LIST of entities or to SHOW details for one entity. A GET request is the simplest HTTP method. In this kind of request, all data is passed in the URL. The easiest way to understand a GET request is by comparing it to what happens when you type a URL into the address bar of your browser and click &lt;strong&gt;Go&lt;/strong&gt;: Your browser makes a GET request to that URL, retrieves the results returned by the Web site, and displays the results to you. A GET request sent to a Web service works the same way, except the request is usually performed via code.&lt;/p&gt;
&lt;p&gt;Sample SHOW user request using the [[api-documentation:Show User REST Endpoint|Show User REST Endpoint]].&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(&amp;quot;https://mytelligentcommunitysite.com/api.ashx/v2/{0}.json&amp;quot;,
    &amp;quot;username&amp;quot; // Username of the user we are returning
    ) as HttpWebRequest;
request.Method = &amp;quot;GET&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;
&lt;h3&gt;&lt;a name="post"&gt;&lt;/a&gt;POST&lt;/h3&gt;
&lt;p&gt;POST requests are translated as CREATE requests. Unlike GET requests, HTTP POST requests contain their data in the body of the request. If you have ever submitted a form online, you have probably submitted an HTTP POST request. You can&amp;#39;t create a POST request to a Web service directly from your browser without using a form, code, or browser plug-in.&lt;/p&gt;
&lt;p&gt;The easiest way to demonstrate a POST request is by using a little bit of C# code. The following code snippet demonstrates submitting a POST request to the Telligent Community platform&amp;#39;s v2 Web services &lt;span style="font-family:courier new,courier;"&gt;Users &lt;/span&gt;endpoint. Performing the POST with the accompanying data to the &lt;span style="font-family:courier new,courier;"&gt;Users &lt;/span&gt;endpoint will CREATE a new user:&lt;/p&gt;
&lt;p&gt;Sample POST&amp;nbsp;request&amp;nbsp;using the&amp;nbsp;[[api-documentation:Create User REST Endpoint|Create User REST Endpoint]].&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(&amp;quot;https://mytelligentcommunitysite.com/api.ashx/v2/users.json&amp;quot;) as HttpWebRequest;
request.Method = &amp;quot;POST&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);
request.ContentType = &amp;quot;application/x-www-form-urlencoded&amp;quot;;

var data = string.Format(&amp;quot;Username={0}&amp;amp;Password={1}&amp;amp;PrivateEmail={2}&amp;quot;, 
    &amp;quot;username&amp;quot;, // Username of the user we are creating
    &amp;quot;password&amp;quot;, // Password of the user we are creating
    &amp;quot;username@mysite.com&amp;quot; // Private email address of the user we are creating
    );
byte[] bytes = Encoding.UTF8.GetBytes(data);

var requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;
&lt;h3&gt;&lt;a name="put"&gt;&lt;/a&gt;PUT&lt;/h3&gt;
&lt;p&gt;PUT requests are translated as UPDATE request. Like a &lt;a href="#post"&gt;POST&lt;/a&gt; request, a PUT request&amp;#39;s data is included within the message body. Performing a PUT request is very similar to performing a POST request. To update a user with an ID of 2132, you would perform a PUT request using code similar to the POST example above to the &lt;span style="font-family:courier new,courier;"&gt;http://localhost/api.ashx/v2/users/2132.xml&lt;/span&gt; endpoint.&lt;/p&gt;
&lt;p class="tdocs-note"&gt;&lt;strong&gt;&lt;a name="note-put"&gt;&lt;/a&gt;&lt;/strong&gt;Some Web servers, including IIS, disable PUT and DELETE requests by default for security purposes. For this reason the Telligent Community platform&amp;#39;s v2 Web services provides overloads of the POST method for &lt;a href="#put"&gt;PUT&lt;/a&gt;&amp;nbsp;operations that allow you to perform PUT- like functions by making a &lt;a href="#post"&gt;POST&lt;/a&gt; request with a custom HTTP header of &lt;span style="font-family:courier new,courier;"&gt;Rest-Method: PUT&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Sample PUT request using the [[api-documentation:Update User REST Endpoint|Update User REST Endpoint]].&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(string.Format(&amp;quot;https://mytelligentcommunitysite.com/api.ashx/v2/users/{0}.json&amp;quot;, 
    &amp;quot;username&amp;quot; // Username of the user we are updating
    )) as HttpWebRequest;
request.Method = &amp;quot;POST&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);
request.Headers.Add(&amp;quot;Rest-Method&amp;quot;, &amp;quot;PUT&amp;quot;);
request.ContentType = &amp;quot;application/x-www-form-urlencoded&amp;quot;;

// We are only updating the users Private Email
var data = string.Format(&amp;quot;PrivateEmail={0}&amp;quot;, &amp;quot;username.updated@mysite.com&amp;quot;);
byte[] bytes = Encoding.UTF8.GetBytes(data);

var requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;
&lt;h3&gt;&lt;a name="delete"&gt;&lt;/a&gt;DELETE&lt;/h3&gt;
&lt;p&gt;Used for DELETE requests. If you make a DELETE request to &lt;span style="font-family:courier new,courier;"&gt;http://localhost/api.ashx/v2/users/2132.xml&lt;/span&gt;, you are asking that the user with ID 2132 be removed.&lt;/p&gt;
&lt;p class="tdocs-note"&gt;&lt;strong&gt;&lt;a name="note-delete"&gt;&lt;/a&gt;&lt;/strong&gt;Some Web servers, including IIS, disable PUT and DELETE requests by default for security purposes. For this reason the Telligent Community platform&amp;#39;s v2 Web services provides overloads of the POST method for &lt;a href="#put"&gt;DELETE&lt;/a&gt; operations that allow you to perform DELETE-like functions by making a &lt;a href="#post"&gt;POST&lt;/a&gt; request with a custom HTTP header of &lt;span style="font-family:courier new,courier;"&gt;Rest-Method: DELETE&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Sample DELETE user request using the [[api-documentation:Delete User REST Endpoint|Delete User REST Endpoint]].&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(string.Format(&amp;quot;https://mytelligentcommunitysite.com/api.ashx/v2/users/{0}.xml?includetypes=true&amp;quot;, 
    &amp;quot;username&amp;quot; // Username of the user we are deleting
    )) as HttpWebRequest;
request.Method = &amp;quot;POST&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);
request.Headers.Add(&amp;quot;Rest-Method&amp;quot;, &amp;quot;DELETE&amp;quot;);
request.ContentLength = 0;

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;
&lt;h3&gt;&lt;a id="Using_the_Batch_REST_Endpoint" name="Using_the_Batch_REST_Endpoint"&gt;&lt;/a&gt;Using the Batch REST Endpoint&lt;/h3&gt;
&lt;p&gt;The [[api-documentation:Batch Batching REST Endpoint|BATCH REST Endpoint]]&amp;nbsp;can be used to make a series of REST request in a batch. &amp;nbsp;Up to 100 requests can be made in one batch request. &amp;nbsp;The batch request can also be set to run sequential. &amp;nbsp;When running sequential if one request fails, the remaining requests will not be executed. &amp;nbsp;Using this endpoint can offer performance by reducing the number of hops between the external application and Telligent Community as well as by allowing requests to run simultaneously.&lt;/p&gt;
&lt;p&gt;The following sample uses the BATCH REST endpoint to create both a user and a group in one request.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(&amp;quot;https://mytelligentcommunitysite.com/api.ashx/v2/batch.json&amp;quot;) as HttpWebRequest;
request.Method = &amp;quot;POST&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);
request.ContentType = &amp;quot;application/x-www-form-urlencoded&amp;quot;;

var userData = string.Format(&amp;quot;Username={0}&amp;amp;Password={1}&amp;amp;PrivateEmail={2}&amp;quot;, 
    &amp;quot;username&amp;quot;, // Username of the user we are creating
    &amp;quot;password&amp;quot;, // Password of the user we are creating
    &amp;quot;username@mysite.com&amp;quot;); //Private email addres of the user we are creating

var groupData = string.Format(&amp;quot;Name={0}&amp;amp;GroupType={1}&amp;quot;, 
    &amp;quot;name&amp;quot;, // Name of the group we are creating
    &amp;quot;Joinless&amp;quot;); // Type of group we are creating

var batchData =
    string.Format(
        &amp;quot;_REQUEST_0_URL={0}&amp;amp;_REQUEST_0_METHOD={1}&amp;amp;_REQUEST_0_DATA={2}&amp;amp;_REQUEST_1_URL={3}&amp;amp;_REQUEST_1_METHOD={4}&amp;amp;_REQUEST_1_DATA={5}&amp;quot;,
        HttpUtility.UrlEncode(&amp;quot;~/api.ashx/v2/users.json&amp;quot;), 
        &amp;quot;POST&amp;quot;, 
        HttpUtility.UrlEncode(userData), 
        HttpUtility.UrlEncode(&amp;quot;~/api.ashx/v2/groups.json&amp;quot;), 
        &amp;quot;POST&amp;quot;, 
        HttpUtility.UrlEncode(groupData));

byte[] bytes = Encoding.UTF8.GetBytes(batchData);

var requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Using the above sample, the request&amp;nbsp;can be made to run&amp;nbsp;sequentially but adding the &lt;code&gt;&amp;amp;Sequential=true &lt;/code&gt;to the batchData querystring.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;var batchData =
string.Format(
    &amp;quot;_REQUEST_0_URL={0}&amp;amp;_REQUEST_0_METHOD={1}&amp;amp;_REQUEST_0_DATA={2}&amp;amp;_REQUEST_1_URL={3}&amp;amp;_REQUEST_1_METHOD={4}&amp;amp;_REQUEST_1_DATA={5}&amp;amp;Sequential=true&amp;quot;,
    HttpUtility.UrlEncode(&amp;quot;~/api.ashx/v2/users.json&amp;quot;), 
    &amp;quot;POST&amp;quot;, 
    HttpUtility.UrlEncode(userData), 
    HttpUtility.UrlEncode(&amp;quot;~/api.ashx/v2/groups.json&amp;quot;), 
    &amp;quot;POST&amp;quot;, 
    HttpUtility.UrlEncode(groupData));&lt;/pre&gt;&lt;/p&gt;
&lt;h3&gt;&lt;a id="Using_the_Scripting_REST_Endpoint" name="Using_the_Scripting_REST_Endpoint"&gt;&lt;/a&gt;Using the Scripting REST Endpoint&lt;/h3&gt;
&lt;p&gt;The [[api-documentation:Scripting REST Endpoints|Scripting REST Endpoint]]&amp;nbsp;is used to execute widgets through REST. &amp;nbsp;The&amp;nbsp;code sample is the widget used&amp;nbsp;in&amp;nbsp;the sample GET and POST requests. &amp;nbsp;The Scripting REST Endpoint offers performance advantages of &amp;nbsp;being able to make multiple API calls in one REST API call. &amp;nbsp;It also allows you to reduce the size of the HTTP response by only including fields you really need. &amp;nbsp;It also allows for responses&amp;nbsp;to be pre-rendered and can return any data type it wants:&amp;nbsp;HTML, CSV, XML, JSON, etc.&lt;/p&gt;
&lt;h4&gt;&lt;a id="GET" name="GET"&gt;&lt;/a&gt;GET&lt;/h4&gt;
&lt;p&gt;Create a new widget by going to Administration &amp;gt; Interface &amp;gt; Widgets. &amp;nbsp;Once the widget is created you will be shown the overview page where you can click the Show Details link to grab the Widget ID value that will be used with your Scripting REST Endpoint. &amp;nbsp;To learn more about widgets, see the [[Widgets]]&amp;nbsp;portion of this guide. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;The following sample widget accepts the QueryString parameters&amp;nbsp;ContentId and ContentTypeId&amp;nbsp;and will return a JSON&amp;nbsp;response which will include all comments along with any likes on the comments themselves for the ContentId and ContentTypeId passed in.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="velocity"&gt;$core_v2_page.SetContentType(&amp;#39;application/json&amp;#39;)

#set ($ContentId = $core_v2_utility.ParseGuid($core_v2_page.GetQueryStringValue(&amp;#39;ContentId&amp;#39;)))
#set ($ContentTypeId = $core_v2_utility.ParseGuid($core_v2_page.GetQueryStringValue(&amp;#39;ContentTypeId&amp;#39;)))

#if (!$core_v2_page.IsPost &amp;amp;&amp;amp; $ContentId &amp;amp;&amp;amp; $ContentTypeId)
#set($comments = $core_v2_comments.List(&amp;quot;%{ContentId = $ContentId, ContentTypeId = $ContentTypeId}&amp;quot;))
    {&amp;quot;Comments&amp;quot;: [
        #foreach($comment in $comments)
            #before
                {
            #each
            &amp;quot;Comment&amp;quot;:{
                #set($likes = $core_v2_like.List(&amp;quot;%{ContentId = $comment.CommentId, ContentTypeId = $core_v2_comments.ContentTypeId}&amp;quot;))
                #if ($likes.HasErrors())
    		        $core_v2_page.SendJsonError($likes.Errors)
    		    #else
                    &amp;quot;ContentId&amp;quot;: &amp;quot;$comment.ContentId&amp;quot;,&amp;quot;ContentTypeId&amp;quot;: &amp;quot;$comment.ContentTypeId&amp;quot;,&amp;quot;Body&amp;quot;: &amp;quot;$comment.Body&amp;quot;,&amp;quot;UserId&amp;quot;: &amp;quot;$comment.UserId&amp;quot;,&amp;quot;Likes&amp;quot;: [
                            #foreach($like in $likes)
                                #before
                                {
                                #each
                                    &amp;quot;Like&amp;quot;:{&amp;quot;UserId&amp;quot;:&amp;quot;$like.UserId&amp;quot;,&amp;quot;CreatedDate&amp;quot;:&amp;quot;$like.CreatedDate&amp;quot;}
                                #after
                                }
                            #end
                            ]
            #after
                }
                #end
            }
        #end
    ]}
#end&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The following sample GET request calls the sample widget using the Scripted REST Endpoint. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(string.Format(&amp;quot;https://mytelligentcommunitysite.com/api.ashx/v2/scripted?Id={0}&amp;amp;ContentId={1}&amp;amp;ContentTypeId={2}&amp;quot;, 
    &amp;quot;709a35f5-150e-443a-8483-4907a3efec60&amp;quot;, //Widget ID of the widget we are calling
    &amp;quot;BC21522C-39D8-4020-B14A-DA623B9F2C64&amp;quot;, //ContentId of the item we are trying to retrieve comments on
    &amp;quot;6B577B8C-0470-4E20-9D29-B6772BF67243&amp;quot; //ContentTypeId of the item we are trying to retrieve comments on
    )) as HttpWebRequest;
request.Method = &amp;quot;GET&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);
request.ContentType = &amp;quot;application/x-www-form-urlencoded&amp;quot;;

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;
&lt;h4&gt;&lt;a id="POST" name="POST"&gt;&lt;/a&gt;POST&lt;/h4&gt;
&lt;p&gt;Create a new widget by going to Administration &amp;gt; Interface &amp;gt; Widgets. &amp;nbsp;Once the widget is created you will be shown the overview page where you can click the Show Details link to grab the Widget ID value that will be used with your Scripting REST Endpoint. &amp;nbsp;To learn more about widgets, see the [[Widgets]]&amp;nbsp;portion of this guide. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;The following sample widget accepts the QueryString parameters&amp;nbsp;ContentId and ContentTypeId&amp;nbsp;and create a like on the associated content. &amp;nbsp;The response will be return as JSON.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="velocity"&gt;$core_v2_page.SetContentType(&amp;#39;application/json&amp;#39;)

#set ($ContentId = $core_v2_utility.ParseGuid($core_v2_page.GetQueryStringValue(&amp;#39;ContentId&amp;#39;)))
#set ($ContentTypeId = $core_v2_utility.ParseGuid($core_v2_page.GetQueryStringValue(&amp;#39;ContentTypeId&amp;#39;)))

#if ($core_v2_page.IsPost &amp;amp;&amp;amp; $ContentId &amp;amp;&amp;amp; $ContentTypeId)
    #set($likeResponse = $core_v2_like.Create($ContentId, $ContentTypeId))
    {&amp;quot;Like&amp;quot;: {&amp;quot;UserId&amp;quot;:&amp;quot;$likeResponse.UserId&amp;quot;,&amp;quot;ContentId&amp;quot;:&amp;quot;$likeResponse.ContentId&amp;quot;,&amp;quot;CreatedDate&amp;quot;:&amp;quot;$likeResponse.CreatedDate&amp;quot;}}
#end&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The following sample POST&amp;nbsp;request calls the sample widget using the Scripted REST Endpoint. &amp;nbsp;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;// replace the &amp;quot;admin&amp;quot; and &amp;quot;Admin&amp;#39;s API key&amp;quot; with your valid user and apikey!
var adminKey = String.Format(&amp;quot;{0}:{1}&amp;quot;, &amp;quot;Admin&amp;#39;s API key&amp;quot;, &amp;quot;admin&amp;quot;);
var adminKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(adminKey));

var request = WebRequest.Create(string.Format(&amp;quot;https://mytelligentcommunitysite.com/api.ashx/v2/scripted?Id={0}&amp;amp;ContentId={1}&amp;amp;ContentTypeId={2}&amp;quot;,
    &amp;quot;9127c3e9-813c-429e-84a0-743bbd414c24&amp;quot;, //Widget ID of the widget we are calling
    &amp;quot;BC21522C-39D8-4020-B14A-DA623B9F2C64&amp;quot;, //ContentId of the item we are creating a like on
    &amp;quot;6B577B8C-0470-4E20-9D29-B6772BF67243&amp;quot; //ContentTypeId of the item we are creating a like on
   )) as HttpWebRequest;
request.Method = &amp;quot;POST&amp;quot;;
request.Headers.Add(&amp;quot;Rest-User-Token&amp;quot;, adminKeyBase64);
request.ContentLength = 0;

var response = request.GetResponse() as HttpWebResponse;
string text = null;
using (var sr = new StreamReader(response.GetResponseStream()))
{
    text = sr.ReadToEnd();
}

Console.WriteLine(text);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item></channel></rss>