Sample code for 30+ languages & platforms
SQL Server

MemberMouse -- getMember API Call

See more HTTP Misc Examples

Demonstrates how to use the getMember API call is used to retrieve information about an existing member's account.

See MemberMouse getMember API call for more information.

Chilkat SQL Server Downloads

SQL Server
-- 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)
    DECLARE @success int
    SELECT @success = 0

    -- This example assumes the Chilkat HTTP API to have been previously unlocked.
    -- See Global Unlock Sample for sample code.

    -- Build the POST request to get a member's data.
    DECLARE @req int
    EXEC @hr = sp_OACreate 'Chilkat.HttpRequest', @req OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    -- If your particular API URL is "https://mydomain.com/wp-content/plugins/membermouse/api/request.php",
    -- then the Path part of the URL is "/wp-content/plugins/membermouse/api/request.php",
    -- and the Domain part of the URL is "mydomain.com".
    -- If "https" is used, then the port is 443 (not 80).

    EXEC sp_OASetProperty @req, 'HttpVerb', 'POST'
    -- Use the Path part of your API_URL with "?q=/getMember".
    -- The command, such as /getMember, /createMember, etc. goes in the Path.
    -- The remainder of the POST arguments are query params that go in the body of the request.
    -- (Do not put the apikey and apisecret in the Path because the secret will be exposed.
    -- You want the confidential information to be in the body of the request.)
    EXEC sp_OASetProperty @req, 'Path', '/wp-content/plugins/membermouse/api/request.php?q=/getMember'
    EXEC sp_OASetProperty @req, 'ContentType', 'application/x-www-form-urlencoded'

    -- Add the query params.
    -- (Use your particular values in place of "MEMBERMOUSE_...")
    EXEC sp_OAMethod @req, 'AddParam', NULL, 'apikey', 'MEMBERMOUSE_API_KEY'
    EXEC sp_OAMethod @req, 'AddParam', NULL, 'apisecret', 'MEMBERMOUSE_API_SECRET'
    EXEC sp_OAMethod @req, 'AddParam', NULL, 'email', 'some_member@somewhere.com'

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT

    -- Use the Domain part of your API URL here:
    DECLARE @resp int
    EXEC @hr = sp_OACreate 'Chilkat.HttpResponse', @resp OUT

    EXEC sp_OAMethod @http, 'HttpSReq', @success OUT, 'mydomain.com', 443, 1, @req, @resp
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @req
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @resp
        RETURN
      END

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT

    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    EXEC sp_OAMethod @json, 'Load', @success OUT, @sTmp0
    EXEC sp_OASetProperty @json, 'EmitCompact', 0

    -- A sample JSON response is shown below..
    EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT 'Response Status Code: ' + @iTmp0

    -- A response code of 200 is success.
    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    IF @iTmp0 = 200
      BEGIN
        -- Show a few values from the JSON..

        EXEC sp_OAMethod @json, 'StringOf', @sTmp0 OUT, 'response_data.first_name'
        PRINT 'first_name: ' + @sTmp0

        EXEC sp_OAMethod @json, 'StringOf', @sTmp0 OUT, 'response_data.last_name'
        PRINT 'last_name: ' + @sTmp0

        -- Iterate over the bundles.
        DECLARE @i int
        SELECT @i = 0
        DECLARE @numBundles int
        EXEC sp_OAMethod @json, 'SizeOfArray', @numBundles OUT, 'response_data.bundles'
        WHILE @i < @numBundles
          BEGIN
            EXEC sp_OASetProperty @json, 'I', @i


            EXEC sp_OAMethod @json, 'StringOf', @sTmp0 OUT, 'response_data.bundles[i].name'
            PRINT 'Bundle: ' + @sTmp0
            SELECT @i = @i + 1
          END
      END

    -- ----------------------------------------------------
    -- Sample JSON response for /getMember
    -- ----------------------------------------------------

    -- {
    --   "response_code": "200",
    --   "response_message": "",
    --   "response_data": {
    --     "member_id": 59,
    --     "first_name": "Jim",
    --     "last_name": "Smith",
    --     "is_complimentary": "false",
    --     "registered": "2003-08-08 00:00:00",
    --     "cancellation_date": "",
    --     "last_logged_in": "2017-04-28 16:26:06",
    --     "last_updated": "2017-04-28 16:26:06",
    --     "days_as_member": 5013,
    --     "status": "1",
    --     "status_name": "Active",
    --     "membership_level": "12",
    --     "membership_level_name": "Expert Instructor",
    --     "username": "JSmith",
    --     "email": "some_member@somewhere.com",
    --     "password": null,
    --     "phone": "(618) 555-5555",
    --     "billing_address": "555 Shady Lane",
    --     "billing_city": "Wheaton",
    --     "billing_state": "IL",
    --     "billing_zip": "60187",
    --     "billing_country": "United States",
    --     "shipping_address": "555 Shady Lane",
    --     "shipping_city": "Wheaton",
    --     "shipping_state": "IL",
    --     "shipping_zip": "60187",
    --     "shipping_country": "United States",
    --     "bundles": [
    --       {
    --         "id": "6",
    --         "name": "ABC Bundle",
    --         "is_complimentary": "false",
    --         "days_with_bundle": 2758,
    --         "status": "1",
    --         "status_name": "Active",
    --         "date_added": "2009-10-10 00:00:00",
    --         "last_updated": "2017-03-26 13:00:30"
    --       },
    --       {
    --         "id": "8",
    --         "name": "XZ 2.0 Software License",
    --         "is_complimentary": "false",
    --         "days_with_bundle": 2758,
    --         "status": "1",
    --         "status_name": "Active",
    --         "date_added": "2009-10-10 00:00:00",
    --         "last_updated": "2017-03-26 13:00:30"
    --       }
    --     ],
    --     "custom_fields": [
    --       {
    --         "id": 1,
    --         "name": "Class Location:",
    --         "value": ""
    --       },
    --       {
    --         "id": 2,
    --         "name": "Company",
    --         "value": "Acme Interiors Inc"
    --       },
    --       {
    --         "id": 3,
    --         "name": "Referred by:",
    --         "value": ""
    --       },
    --       {
    --         "id": 4,
    --         "name": "Sound Analysis Equipment",
    --         "value": "AudioTools Sound Analyzer with HAA multi mic Kit"
    --       },
    --       {
    --         "id": 5,
    --         "name": "HAA Member Number",
    --         "value": "22222222"
    --       },
    --       {
    --         "id": 6,
    --         "name": "Alumni Class Dates",
    --         "value": ""
    --       }
    --     ]
    --   }
    -- }
    -- 

    EXEC @hr = sp_OADestroy @req
    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @resp
    EXEC @hr = sp_OADestroy @json


END
GO