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 Search PeopleDemonstrates the Populi searchPeople 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', 'searchPeople' EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'search_term', 'Robert' EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'limit', '10' 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="UTF-8"?> -- <response> -- <person> -- <id>11111</id> -- <first_name>Robert</first_name> -- <last_name>McStudent</last_name> -- <middle_name>Kensington</middle_name> -- <preferred_name>Bobby</preferred_name> -- <is_user>1</is_user> -- <primary_email>r.mcstudent@myschool.edu</primary_email> -- </person> -- <person> -- <id>2222</id> -- <first_name>Robert</first_name> -- <last_name>McBoardmember</last_name> -- <middle_name/> -- <preferred_name/> -- <is_user>0</is_user> -- <primary_email>robert@gmail.com</primary_email> -- </person> -- </response> DECLARE @i int DECLARE @count_i int DECLARE @id int DECLARE @first_name nvarchar(4000) DECLARE @last_name nvarchar(4000) DECLARE @middle_name nvarchar(4000) DECLARE @preferred_name nvarchar(4000) DECLARE @is_user int DECLARE @primary_email nvarchar(4000) SELECT @i = 0 EXEC sp_OAMethod @xml, 'NumChildrenHavingTag', @count_i OUT, 'person' WHILE @i < @count_i BEGIN EXEC sp_OASetProperty @xml, 'I', @i EXEC sp_OAMethod @xml, 'GetChildIntValue', @id OUT, 'person[i]|id' EXEC sp_OAMethod @xml, 'GetChildContent', @first_name OUT, 'person[i]|first_name' EXEC sp_OAMethod @xml, 'GetChildContent', @last_name OUT, 'person[i]|last_name' EXEC sp_OAMethod @xml, 'GetChildContent', @middle_name OUT, 'person[i]|middle_name' EXEC sp_OAMethod @xml, 'GetChildContent', @preferred_name OUT, 'person[i]|preferred_name' EXEC sp_OAMethod @xml, 'GetChildIntValue', @is_user OUT, 'person[i]|is_user' EXEC sp_OAMethod @xml, 'GetChildContent', @primary_email OUT, 'person[i]|primary_email' 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.