tag:github.com,2008:https://github.com/MadeiraData/ClrHttpRequest/releases Release notes from ClrHttpRequest 2020-08-27T10:42:33Z tag:github.com,2008:Repository/156730430/v3.0.0 2020-08-27T10:44:02Z ClrHttpRequest-v3 <p>SQL Server CLR function for running REST methods over HTTP.</p> <p>This project is a fork of the project initially published By Eilert Hjelmeseth, 2018/10/11 here:<br> <a href="http://www.sqlservercentral.com/articles/SQLCLR/177834/" rel="nofollow">http://www.sqlservercentral.com/articles/SQLCLR/177834/</a></p> <p>Eilert's GitHub project: <a href="https://github.com/eilerth/sqlclr-http-request">https://github.com/eilerth/sqlclr-http-request</a></p> <p>My version extends the project by adding the following:</p> <ul> <li>Usage of TLS1.2 security protocol (nowadays a global standard).</li> <li>Two new authentication methods: <ul> <li>Authorization-Basic-Credentials (Basic authorization using Base64 credentials)</li> <li>Authorization-Network-Credentials (creates a new <code>NetworkCredential</code> object and assigns it to the <code>Credentials</code> property of the request)</li> </ul> </li> <li>Addition of a proper PreDeployment script which takes care of CLR assembly signing without requiring the TRUSTWORTHY database setting.</li> <li>Added UTF8 encoding support instead of ASCII.</li> <li>Added support for case-insensitive headers.</li> </ul> <p>These changes allow the SQL Server function to work with advanced services such as Zendesk.<br> For example:</p> <div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="-- Credentials info: Username (email address) must be followed by /token when using API key DECLARE @credentials NVARCHAR(4000) = 'agent@company_domain.com/token:api_token_key_here' DECLARE @headers NVARCHAR(4000) = '&lt;Headers&gt;&lt;Header Name=&quot;Content-Type&quot;&gt;application/json&lt;/Header&gt;&lt;Header Name=&quot;Authorization-Basic-Credentials&quot;&gt;' + @credentials + '&lt;/Header&gt;&lt;/Headers&gt;' -- Global Zendesk Settings: DECLARE @zendesk_address NVARCHAR(400) = 'https://your_subdomain_here.zendesk.com' -- Look for existing tickets based on @RequesterEmail: SET @uri = @zendesk_address + '/api/v2/search.json?query=type:ticket status&lt;solved requester:' + @RequesterEmail DECLARE @tickets NVARCHAR(MAX), @ticket NVARCHAR(MAX) -- This is where the magic happens: SET @tickets = [dbo].[clr_http_request] ( 'GET', @uri, NULL, @headers, 300000, 0, 0 ).value('/Response[1]/Body[1]', 'NVARCHAR(MAX)') -- check if ticket exists based on @Subject: SELECT @ticket = [value] FROM OPENJSON(@tickets, '$.results') WHERE JSON_VALUE([value], '$.subject') = @Subject AND JSON_VALUE([value], '$.status') IN ('new', 'open', 'pending') SELECT uri = JSON_VALUE(@ticket, '$.url'), submitter = JSON_VALUE(@ticket, '$.submitter_id')"><pre class="notranslate"><code>-- Credentials info: Username (email address) must be followed by /token when using API key DECLARE @credentials NVARCHAR(4000) = 'agent@company_domain.com/token:api_token_key_here' DECLARE @headers NVARCHAR(4000) = '&lt;Headers&gt;&lt;Header Name="Content-Type"&gt;application/json&lt;/Header&gt;&lt;Header Name="Authorization-Basic-Credentials"&gt;' + @credentials + '&lt;/Header&gt;&lt;/Headers&gt;' -- Global Zendesk Settings: DECLARE @zendesk_address NVARCHAR(400) = 'https://your_subdomain_here.zendesk.com' -- Look for existing tickets based on @RequesterEmail: SET @uri = @zendesk_address + '/api/v2/search.json?query=type:ticket status&lt;solved requester:' + @RequesterEmail DECLARE @tickets NVARCHAR(MAX), @ticket NVARCHAR(MAX) -- This is where the magic happens: SET @tickets = [dbo].[clr_http_request] ( 'GET', @uri, NULL, @headers, 300000, 0, 0 ).value('/Response[1]/Body[1]', 'NVARCHAR(MAX)') -- check if ticket exists based on @Subject: SELECT @ticket = [value] FROM OPENJSON(@tickets, '$.results') WHERE JSON_VALUE([value], '$.subject') = @Subject AND JSON_VALUE([value], '$.status') IN ('new', 'open', 'pending') SELECT uri = JSON_VALUE(@ticket, '$.url'), submitter = JSON_VALUE(@ticket, '$.submitter_id') </code></pre></div> <p>For more use cases visit here: <a href="https://github.com/EitanBlumin/ClrHttpRequest/blob/master/UseCases.md">https://github.com/EitanBlumin/ClrHttpRequest/blob/master/UseCases.md</a></p> <p>For more info on using the Zendesk API, visit here: <a href="https://developer.zendesk.com/rest_api/docs/core/introduction" rel="nofollow">https://developer.zendesk.com/rest_api/docs/core/introduction</a></p> EitanBlumin tag:github.com,2008:Repository/156730430/v2.0.0 2020-02-12T15:45:39Z ClrHttpRequest-v2 <p>SQL Server CLR function for running REST methods over HTTP.</p> <p>This project is a fork of the project initially published By Eilert Hjelmeseth, 2018/10/11 here:<br> <a href="http://www.sqlservercentral.com/articles/SQLCLR/177834/" rel="nofollow">http://www.sqlservercentral.com/articles/SQLCLR/177834/</a></p> <p>My version extends the project by adding the following:</p> <ul> <li>Usage of TLS1.2 security protocol (nowadays a global standard).</li> <li>Two new authentication methods: <ul> <li>Authorization-Basic-Credentials (Basic authorization using Base64 credentials).</li> <li>Authorization-Network-Credentials (creates a new NetworkCredential object and assigns it to the Credentials property of the request).</li> </ul> </li> <li>Addition of a proper PreDeployment script which takes care of CLR assembly signing without requiring the TRUSTWORTHY database setting.</li> </ul> <p>The following code was added in clr_http_request.cs, line 19:</p> <div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;"><pre class="notranslate"><code>ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; </code></pre></div> <p>The following code was added in line 79:</p> <div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="case &quot;Authorization-Basic-Credentials&quot;: request.Headers.Add(&quot;Authorization&quot;, &quot;Basic &quot; + Convert.ToBase64String(Encoding.UTF8.GetBytes(headerValue))); break; case &quot;Authorization-Network-Credentials&quot;: request.Credentials = new NetworkCredential(headerValue.Split(':')[0], headerValue.Split(':')[1]); break;"><pre class="notranslate"><code>case "Authorization-Basic-Credentials": request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(headerValue))); break; case "Authorization-Network-Credentials": request.Credentials = new NetworkCredential(headerValue.Split(':')[0], headerValue.Split(':')[1]); break; </code></pre></div> <p>These changes allow the SQL Server function to work with advanced services such as Zendesk.<br> For example:</p> <div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="-- Credentials info: Username (email address) must be followed by /token when using API key DECLARE @credentials NVARCHAR(4000) = 'agent@company_domain.com/token:api_token_key_here' DECLARE @headers NVARCHAR(4000) = '&lt;Headers&gt;&lt;Header Name=&quot;Content-Type&quot;&gt;application/json&lt;/Header&gt;&lt;Header Name=&quot;Authorization-Basic-Credentials&quot;&gt;' + @credentials + '&lt;/Header&gt;&lt;/Headers&gt;' -- Global Zendesk Settings: DECLARE @zendesk_address NVARCHAR(400) = 'https://your_subdomain_here.zendesk.com' -- Look for existing tickets based on @RequesterEmail: SET @uri = @zendesk_address + '/api/v2/search.json?query=type:ticket status&lt;solved requester:' + @RequesterEmail DECLARE @tickets NVARCHAR(MAX), @ticket NVARCHAR(MAX) -- This is where the magic happens: SET @tickets = [dbo].[clr_http_request] ( 'GET', @uri, NULL, @headers, 300000, 0, 0 ).value('/Response[1]/Body[1]', 'NVARCHAR(MAX)') -- check if ticket exists based on @Subject: SELECT @ticket = [value] FROM OPENJSON(@tickets, '$.results') WHERE JSON_VALUE([value], '$.subject') = @Subject AND JSON_VALUE([value], '$.status') IN ('new', 'open', 'pending') SELECT uri = JSON_VALUE(@ticket, '$.url'), submitter = JSON_VALUE(@ticket, '$.submitter_id') For more use cases vist here: https://github.com/EitanBlumin/ClrHttpRequest/blob/master/UseCases.md"><pre class="notranslate"><code>-- Credentials info: Username (email address) must be followed by /token when using API key DECLARE @credentials NVARCHAR(4000) = 'agent@company_domain.com/token:api_token_key_here' DECLARE @headers NVARCHAR(4000) = '&lt;Headers&gt;&lt;Header Name="Content-Type"&gt;application/json&lt;/Header&gt;&lt;Header Name="Authorization-Basic-Credentials"&gt;' + @credentials + '&lt;/Header&gt;&lt;/Headers&gt;' -- Global Zendesk Settings: DECLARE @zendesk_address NVARCHAR(400) = 'https://your_subdomain_here.zendesk.com' -- Look for existing tickets based on @RequesterEmail: SET @uri = @zendesk_address + '/api/v2/search.json?query=type:ticket status&lt;solved requester:' + @RequesterEmail DECLARE @tickets NVARCHAR(MAX), @ticket NVARCHAR(MAX) -- This is where the magic happens: SET @tickets = [dbo].[clr_http_request] ( 'GET', @uri, NULL, @headers, 300000, 0, 0 ).value('/Response[1]/Body[1]', 'NVARCHAR(MAX)') -- check if ticket exists based on @Subject: SELECT @ticket = [value] FROM OPENJSON(@tickets, '$.results') WHERE JSON_VALUE([value], '$.subject') = @Subject AND JSON_VALUE([value], '$.status') IN ('new', 'open', 'pending') SELECT uri = JSON_VALUE(@ticket, '$.url'), submitter = JSON_VALUE(@ticket, '$.submitter_id') For more use cases vist here: https://github.com/EitanBlumin/ClrHttpRequest/blob/master/UseCases.md </code></pre></div> <p>For more info on using the Zendesk API, visit here: <a href="https://developer.zendesk.com/rest_api/docs/core/introduction" rel="nofollow">https://developer.zendesk.com/rest_api/docs/core/introduction</a></p> EitanBlumin tag:github.com,2008:Repository/156730430/v1.0.0 2018-11-09T20:57:25Z v1.0.0 <h1>ClrHttpRequest</h1> <p>SQL Server CLR function for running REST methods over HTTP.</p> <p>This project is a fork of the project initially published By Eilert Hjelmeseth, 2018/10/11 here:<br> <a href="http://www.sqlservercentral.com/articles/SQLCLR/177834/" rel="nofollow">http://www.sqlservercentral.com/articles/SQLCLR/177834/</a></p> <p>My version extends the project by adding the following:</p> <ul> <li>Usage of TLS1.2 security protocol (nowadays a global standard).</li> <li>Two new authentication methods: <ul> <li>Authorization-Basic-Credentials (Basic authorization using Base64 credentials)</li> <li>Authorization-Network-Credentials (creates a new <code>NetworkCredential</code> object and assigns it to the <code>Credentials</code> property of the request)</li> </ul> </li> </ul> <p>The following code was added in clr_http_request.cs, line 19:</p> <div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;"><pre class="notranslate"><code>ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; </code></pre></div> <p>The following code was added in line 79:</p> <div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="case &quot;Authorization-Basic-Credentials&quot;: request.Headers.Add(&quot;Authorization&quot;, &quot;Basic &quot; + Convert.ToBase64String(Encoding.UTF8.GetBytes(headerValue))); break; case &quot;Authorization-Network-Credentials&quot;: request.Credentials = new NetworkCredential(headerValue.Split(':')[0], headerValue.Split(':')[1]); break;"><pre class="notranslate"><code>case "Authorization-Basic-Credentials": request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(headerValue))); break; case "Authorization-Network-Credentials": request.Credentials = new NetworkCredential(headerValue.Split(':')[0], headerValue.Split(':')[1]); break; </code></pre></div> <p>These changes allow the SQL Server function to work with advanced services such as Zendesk.<br> For example:</p> <div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="-- Credentials info: Username (email address) must be followed by /token when using API key DECLARE @credentials NVARCHAR(4000) = 'agent@company_domain.com/token:api_token_key_here' DECLARE @headers NVARCHAR(4000) = '&lt;Headers&gt;&lt;Header Name=&quot;Content-Type&quot;&gt;application/json&lt;/Header&gt;&lt;Header Name=&quot;Authorization-Basic-Credentials&quot;&gt;' + @credentials + '&lt;/Header&gt;&lt;/Headers&gt;' -- Global Zendesk Settings: DECLARE @zendesk_address NVARCHAR(400) = 'https://your_subdomain_here.zendesk.com' -- Look for existing tickets based on @RequesterEmail: SET @uri = @zendesk_address + '/api/v2/search.json?query=type:ticket status&lt;solved requester:' + @RequesterEmail DECLARE @tickets NVARCHAR(MAX), @ticket NVARCHAR(MAX) -- This is where the magic happens: SET @tickets = [dbo].[clr_http_request] ( 'GET', @uri, NULL, @headers, 300000, 0, 0 ).value('/Response[1]/Body[1]', 'NVARCHAR(MAX)') -- check if ticket exists based on @Subject: SELECT @ticket = [value] FROM OPENJSON(@tickets, '$.results') WHERE JSON_VALUE([value], '$.subject') = @Subject AND JSON_VALUE([value], '$.status') IN ('new', 'open', 'pending') SELECT uri = JSON_VALUE(@ticket, '$.url'), submitter = JSON_VALUE(@ticket, '$.submitter_id')"><pre class="notranslate"><code>-- Credentials info: Username (email address) must be followed by /token when using API key DECLARE @credentials NVARCHAR(4000) = 'agent@company_domain.com/token:api_token_key_here' DECLARE @headers NVARCHAR(4000) = '&lt;Headers&gt;&lt;Header Name="Content-Type"&gt;application/json&lt;/Header&gt;&lt;Header Name="Authorization-Basic-Credentials"&gt;' + @credentials + '&lt;/Header&gt;&lt;/Headers&gt;' -- Global Zendesk Settings: DECLARE @zendesk_address NVARCHAR(400) = 'https://your_subdomain_here.zendesk.com' -- Look for existing tickets based on @RequesterEmail: SET @uri = @zendesk_address + '/api/v2/search.json?query=type:ticket status&lt;solved requester:' + @RequesterEmail DECLARE @tickets NVARCHAR(MAX), @ticket NVARCHAR(MAX) -- This is where the magic happens: SET @tickets = [dbo].[clr_http_request] ( 'GET', @uri, NULL, @headers, 300000, 0, 0 ).value('/Response[1]/Body[1]', 'NVARCHAR(MAX)') -- check if ticket exists based on @Subject: SELECT @ticket = [value] FROM OPENJSON(@tickets, '$.results') WHERE JSON_VALUE([value], '$.subject') = @Subject AND JSON_VALUE([value], '$.status') IN ('new', 'open', 'pending') SELECT uri = JSON_VALUE(@ticket, '$.url'), submitter = JSON_VALUE(@ticket, '$.submitter_id') </code></pre></div> <p>For more use cases vist here: <a href="https://github.com/EitanBlumin/ClrHttpRequest/blob/master/UseCases.md">https://github.com/EitanBlumin/ClrHttpRequest/blob/master/UseCases.md</a></p> <p>For more info on using the Zendesk API, visit here: <a href="https://developer.zendesk.com/rest_api/docs/core/introduction" rel="nofollow">https://developer.zendesk.com/rest_api/docs/core/introduction</a></p> EitanBlumin