tag:github.com,2008:https://github.com/MadeiraData/ClrHttpRequest/releasesRelease notes from ClrHttpRequest2020-08-27T10:42:33Ztag:github.com,2008:Repository/156730430/v3.0.02020-08-27T10:44:02ZClrHttpRequest-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) = '<Headers><Header Name="Content-Type">application/json</Header><Header Name="Authorization-Basic-Credentials">' + @credentials + '</Header></Headers>'
-- 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<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) = '<Headers><Header Name="Content-Type">application/json</Header><Header Name="Authorization-Basic-Credentials">' + @credentials + '</Header></Headers>'
-- 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<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>EitanBlumintag:github.com,2008:Repository/156730430/v2.0.02020-02-12T15:45:39ZClrHttpRequest-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 "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;"><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) = '<Headers><Header Name="Content-Type">application/json</Header><Header Name="Authorization-Basic-Credentials">' + @credentials + '</Header></Headers>'
-- 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<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) = '<Headers><Header Name="Content-Type">application/json</Header><Header Name="Authorization-Basic-Credentials">' + @credentials + '</Header></Headers>'
-- 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<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>EitanBlumintag:github.com,2008:Repository/156730430/v1.0.02018-11-09T20:57:25Zv1.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 "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;"><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) = '<Headers><Header Name="Content-Type">application/json</Header><Header Name="Authorization-Basic-Credentials">' + @credentials + '</Header></Headers>'
-- 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<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) = '<Headers><Header Name="Content-Type">application/json</Header><Header Name="Authorization-Basic-Credentials">' + @credentials + '</Header></Headers>'
-- 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<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