Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) Populi Get RolesDemonstrates the Populi getRoles task.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @iTmp0 int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) -- This example assumes the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. -- First load the previously obtained API token. -- See Get Populi Access Token for sample code showing how to get the API token. DECLARE @xml int -- Use "Chilkat_9_5_0.Xml" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Xml', @xml OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END DECLARE @success int EXEC sp_OAMethod @xml, 'LoadXmlFile', @success OUT, 'qa_data/tokens/populi_token.xml' DECLARE @accessKey nvarchar(4000) EXEC sp_OAMethod @xml, 'GetChildContent', @accessKey OUT, 'access_key' EXEC sp_OAGetProperty @xml, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 <> 1 BEGIN PRINT 'Did not find the access_key' EXEC @hr = sp_OADestroy @xml RETURN END DECLARE @rest int -- Use "Chilkat_9_5_0.Rest" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Rest', @rest OUT -- Connect using TLS. -- A single REST object, once connected, can be used for many Populi REST API calls. -- The auto-reconnect indicates that if the already-established HTTPS connection is closed, -- then it will be automatically re-established as needed. DECLARE @bAutoReconnect int SELECT @bAutoReconnect = 1 EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'yourcollege.populi.co', 443, 1, @bAutoReconnect IF @success <> 1 BEGIN EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @xml EXEC @hr = sp_OADestroy @rest RETURN END EXEC sp_OASetProperty @rest, 'Authorization', @accessKey EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'task', 'getRoles' DECLARE @responseBody nvarchar(4000) EXEC sp_OAMethod @rest, 'FullRequestFormUrlEncoded', @responseBody OUT, 'POST', '/api/index.php' EXEC sp_OAGetProperty @rest, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 <> 1 BEGIN EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @xml EXEC @hr = sp_OADestroy @rest RETURN END -- We should expect a 200 response if successful. EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT IF @iTmp0 <> 200 BEGIN PRINT 'Request Header: ' EXEC sp_OAGetProperty @rest, 'LastRequestHeader', @sTmp0 OUT PRINT @sTmp0 PRINT '----' EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT PRINT 'Response StatusCode = ' + @iTmp0 EXEC sp_OAGetProperty @rest, 'ResponseStatusText', @sTmp0 OUT PRINT 'Response StatusLine: ' + @sTmp0 PRINT 'Response Header:' EXEC sp_OAGetProperty @rest, 'ResponseHeader', @sTmp0 OUT PRINT @sTmp0 PRINT 'Response Body:' PRINT @responseBody EXEC @hr = sp_OADestroy @xml EXEC @hr = sp_OADestroy @rest RETURN END EXEC sp_OAMethod @xml, 'LoadXml', @success OUT, @responseBody EXEC sp_OAMethod @xml, 'GetXml', @sTmp0 OUT PRINT @sTmp0 -- Sample response: -- Use this online tool to generate parsing code from sample XML: -- Generate Parsing Code from XML -- <?xml version="1.0" encoding="ISO-8859-1"?> -- <response> -- <role> -- <id>7</id> -- <name>Academic Admin</name> -- <inactive>0</inactive> -- </role> -- <role> -- <id>19</id> -- <name>Financial Aid</name> -- <inactive>0</inactive> -- </role> -- <role> -- <id>15</id> -- <name>Registrar</name> -- <inactive>0</inactive> -- </role> -- <role> -- <id>4</id> -- <name>Staff</name> -- <inactive>0</inactive> -- </role> -- <role> -- <id>1</id> -- <name>Everyone</name> -- <inactive>0</inactive> -- </role> -- </response> DECLARE @i int DECLARE @count_i int DECLARE @id int DECLARE @name nvarchar(4000) DECLARE @inactive int SELECT @i = 0 EXEC sp_OAMethod @xml, 'NumChildrenHavingTag', @count_i OUT, 'role' WHILE @i < @count_i BEGIN EXEC sp_OASetProperty @xml, 'I', @i EXEC sp_OAMethod @xml, 'GetChildIntValue', @id OUT, 'role[i]|id' EXEC sp_OAMethod @xml, 'GetChildContent', @name OUT, 'role[i]|name' EXEC sp_OAMethod @xml, 'GetChildIntValue', @inactive OUT, 'role[i]|inactive' SELECT @i = @i + 1 END EXEC @hr = sp_OADestroy @xml EXEC @hr = sp_OADestroy @rest END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.