Attachment - Fetch
Retrieve ServiceNow attachment metadata using SQL Server
- See SQLHTTP easy setup for ServiceNow
- See API Call documentation for parameter values and other information
- Create the stored procedure documented below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
CREATE PROCEDURE usp_ServiceNow_Attachment_Fetch( @Profile nvarchar(100), @Sys_id varchar(50), @Response nvarchar(MAX) OUTPUT, @StatusCode int OUTPUT, @StatusDescription nvarchar(MAX) OUTPUT) AS DECLARE @URL nvarchar(MAX) DECLARE @QueryString varchar(MAX) DECLARE @UserName nvarchar(4000) DECLARE @Password nvarchar(4000) DECLARE @HTTPSessionID uniqueidentifier SET @URL = SQLHTTP.net.AuthParam(@Profile, 'Domain') EXEC SQLHTTP.net.UrlBuilder @URL OUTPUT, @Profile, 'api', 'now', 'attachment', @Sys_id EXEC SQLHTTP.net.HTTPSession @HTTPSessionID OUTPUT SET @UserName = SQLHTTP.net.AuthParam(@Profile, 'UserName') SET @Password = SQLHTTP.net.AuthParam(@Profile, 'Password') EXEC SQLHTTP.net.BasicAuthHeader @HttpSessionID, @UserName, @Password EXEC SQLHTTP.net.HTTPRequest @HttpSessionID, @URL = @URL, @Method = 'GET', @Accept = 'application/xml', @StatusCode = @StatusCode OUTPUT, @StatusDescription = @StatusDescription OUTPUT, @Response = @Response OUTPUT GO |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
DECLARE @Response nvarchar(MAX) DECLARE @StatusCode int DECLARE @StatusDescription nvarchar(MAX) EXEC usp_ServiceNow_Attachment_Fetch @Profile = 'My ServiceNow', @Sys_id = 'f5d469d74ff1120031577d2ca310c7c1', @Response = @Response OUTPUT, @StatusCode = @StatusCode OUTPUT, @StatusDescription = @StatusDescription OUTPUT IF @StatusCode >= 400 EXEC SQLHTTP.net.RaiseHttpError @StatusCode, @StatusDescription, @Response ELSE BEGIN DECLARE @X xml SET @X = CONVERT(xml, CONVERT(varchar(MAX), @Response)) --The XPath syntax below was easily generated by executing the following commands: --EXEC SQLHTTP.net.XQueryHelper @X --and then executing: --EXEC SQLHTTP.net.XQueryHelper @X, 'response/result' -- SELECT T.C.value(N'sys_id[1]', N'nvarchar(MAX)') AS [sys_id] ,T.C.value(N'file_name[1]', N'nvarchar(MAX)') AS [file_name] ,T.C.value(N'size_bytes[1]', N'nvarchar(MAX)') AS [size_bytes] ,T.C.value(N'table_name[1]', N'nvarchar(MAX)') AS [table_name] ,T.C.value(N'download_link[1]', N'nvarchar(MAX)') AS [download_link] FROM @X.nodes(N'/response/result') T(C) END |
1 2 3 4 5 |
sys_id file_name size_bytes table_name download_link --------------- ---------------------------- ----------- ----------------- ------------------- f5d469d74ff... 1.3_4_remove-a-favorite.png 190660 sys_product_help https://dev32049... |
IMPORTANT DISCLAIMER
CODE/SQL ON THESE PAGES ARE PROVIDED AS-IS AND ARE AVAILABLE FOR ILLUSTRATIVE PURPOSES ONLY.
USERS ARE REQUIRED TO ABIDE BY THE TERMS AND CONDITIONS FOR USING REFERENCED THIRD PARTY WEBSITES AND/OR APIs FROM THEIR RESPECTIVE WEBSITES. WE DO NOT CONDONE ANY VIOLATION OF THIRD PARTY WEBSITES AND/OR APIs TERMS AND CONDITIONS USING OUR SOFTWARE.
USERS SHALL BE SOLELY RESPONSIBLE AND BE SOLELY LIABLE FOR VIOLATION OF ANY RULES SPECIFIED BY THIRD PARTIES FOR USING THEIR WEBSITES AND/OR APIs, OR INFRINGEMENT OF RIGHTS OF SUCH THIRD PARTIES.