Chilkat Online Tools

SQL Server / Support API / Show Self

Back to Collection Items

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr 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.

    DECLARE @http int
    -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int

    EXEC sp_OASetProperty @http, 'BasicAuth', 1
    EXEC sp_OASetProperty @http, 'Login', 'login'
    EXEC sp_OASetProperty @http, 'Password', 'password'

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Accept', 'application/json'

    DECLARE @sbResponseBody int
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbResponseBody OUT

    EXEC sp_OAMethod @http, 'QuickGetSb', @success OUT, 'https://example.zendesk.com/api/v2/users/me', @sbResponseBody
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        RETURN
      END

    DECLARE @jResp int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jResp OUT

    EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @sbResponseBody
    EXEC sp_OASetProperty @jResp, 'EmitCompact', 0


    PRINT 'Response Body:'
    EXEC sp_OAMethod @jResp, 'Emit', @sTmp0 OUT
    PRINT @sTmp0

    DECLARE @respStatusCode int
    EXEC sp_OAGetProperty @http, 'LastStatus', @respStatusCode OUT

    PRINT 'Response Status Code = ' + @respStatusCode
    IF @respStatusCode >= 400
      BEGIN

        PRINT 'Response Header:'
        EXEC sp_OAGetProperty @http, 'LastHeader', @sTmp0 OUT
        PRINT @sTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @sbResponseBody
        EXEC @hr = sp_OADestroy @jResp
        RETURN
      END

    -- Sample JSON response:
    -- (Sample code for parsing the JSON response is shown below)

    -- {
    --   "user": {
    --     "name": "<string>",
    --     "active": "<boolean>",
    --     "alias": "<string>",
    --     "chat_only": "<boolean>",
    --     "created_at": "<string>",
    --     "custom_role_id": "<integer>",
    --     "default_group_id": "<integer>",
    --     "details": "<string>",
    --     "email": "<string>",
    --     "external_id": "<string>",
    --     "iana_time_zone": "<string>",
    --     "id": "<integer>",
    --     "last_login_at": "<string>",
    --     "locale": "<string>",
    --     "locale_id": "<integer>",
    --     "moderator": "<boolean>",
    --     "notes": "<string>",
    --     "only_private_comments": "<boolean>",
    --     "organization_id": "<integer>",
    --     "phone": "<string>",
    --     "photo": {
    --       "dolore50": -51881550.25541992
    --     },
    --     "remote_photo_url": "<string>",
    --     "report_csv": "<boolean>",
    --     "restricted_agent": "<boolean>",
    --     "role": "<string>",
    --     "role_type": "<integer>",
    --     "shared": "<boolean>",
    --     "shared_agent": "<boolean>",
    --     "shared_phone_number": "<boolean>",
    --     "signature": "<string>",
    --     "suspended": "<boolean>",
    --     "tags": "<array>",
    --     "ticket_restriction": "<string>",
    --     "time_zone": "<string>",
    --     "two_factor_auth_enabled": "<boolean>",
    --     "updated_at": "<string>",
    --     "url": "<string>",
    --     "user_fields": {
    --       "deserunt_c4": -61141403
    --     },
    --     "verified": "<boolean>",
    --     "authenticity_token": "<string>"
    --   }
    -- }

    -- Sample code for parsing the JSON response...
    -- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    DECLARE @Name nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'user.name'
    DECLARE @Active nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Active OUT, 'user.active'
    DECLARE @Alias nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Alias OUT, 'user.alias'
    DECLARE @Chat_only nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Chat_only OUT, 'user.chat_only'
    DECLARE @Created_at nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Created_at OUT, 'user.created_at'
    DECLARE @Custom_role_id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Custom_role_id OUT, 'user.custom_role_id'
    DECLARE @Default_group_id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Default_group_id OUT, 'user.default_group_id'
    DECLARE @Details nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Details OUT, 'user.details'
    DECLARE @v_Email nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_Email OUT, 'user.email'
    DECLARE @External_id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @External_id OUT, 'user.external_id'
    DECLARE @Iana_time_zone nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Iana_time_zone OUT, 'user.iana_time_zone'
    DECLARE @Id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Id OUT, 'user.id'
    DECLARE @Last_login_at nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Last_login_at OUT, 'user.last_login_at'
    DECLARE @Locale nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Locale OUT, 'user.locale'
    DECLARE @Locale_id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Locale_id OUT, 'user.locale_id'
    DECLARE @Moderator nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Moderator OUT, 'user.moderator'
    DECLARE @Notes nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Notes OUT, 'user.notes'
    DECLARE @Only_private_comments nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Only_private_comments OUT, 'user.only_private_comments'
    DECLARE @Organization_id nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Organization_id OUT, 'user.organization_id'
    DECLARE @Phone nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Phone OUT, 'user.phone'
    DECLARE @Dolore50 nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Dolore50 OUT, 'user.photo.dolore50'
    DECLARE @Remote_photo_url nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Remote_photo_url OUT, 'user.remote_photo_url'
    DECLARE @Report_csv nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Report_csv OUT, 'user.report_csv'
    DECLARE @Restricted_agent nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Restricted_agent OUT, 'user.restricted_agent'
    DECLARE @Role nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Role OUT, 'user.role'
    DECLARE @Role_type nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Role_type OUT, 'user.role_type'
    DECLARE @v_Shared nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_Shared OUT, 'user.shared'
    DECLARE @Shared_agent nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Shared_agent OUT, 'user.shared_agent'
    DECLARE @Shared_phone_number nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Shared_phone_number OUT, 'user.shared_phone_number'
    DECLARE @Signature nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Signature OUT, 'user.signature'
    DECLARE @Suspended nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Suspended OUT, 'user.suspended'
    DECLARE @Tags nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Tags OUT, 'user.tags'
    DECLARE @Ticket_restriction nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Ticket_restriction OUT, 'user.ticket_restriction'
    DECLARE @Time_zone nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Time_zone OUT, 'user.time_zone'
    DECLARE @Two_factor_auth_enabled nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Two_factor_auth_enabled OUT, 'user.two_factor_auth_enabled'
    DECLARE @Updated_at nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Updated_at OUT, 'user.updated_at'
    DECLARE @v_Url nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @v_Url OUT, 'user.url'
    DECLARE @Deserunt_c4 int
    EXEC sp_OAMethod @jResp, 'IntOf', @Deserunt_c4 OUT, 'user.user_fields.deserunt_c4'
    DECLARE @Verified nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Verified OUT, 'user.verified'
    DECLARE @Authenticity_token nvarchar(4000)
    EXEC sp_OAMethod @jResp, 'StringOf', @Authenticity_token OUT, 'user.authenticity_token'

    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @sbResponseBody
    EXEC @hr = sp_OADestroy @jResp


END
GO

Curl Command

curl  -u login:password -X GET
	-H "Accept: application/json"
https://example.zendesk.com/api/v2/users/me

Postman Collection Item JSON

{
  "name": "Show Self",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/users/me",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "users",
        "me"
      ]
    },
    "description": "#### Allowed For\n\n* Anonymous users\n\n#### Authenticity Token\n\nThe endpoint returns an `authenticity_token`. Zendesk API calls made by end users from a Zendesk help center must include this token in the `X-CSRF-Token` HTTP header. This helps prevent [cross-site request forgery (CSRF)](https://en.wikipedia.org/wiki/Cross-site_request_forgery) attacks.\n\nFor an example using an authenticity token, see the AJAX request in the [Upgrading from Templating API v1](https://developer.zendesk.com/documentation/help_center/help-center-templates/v1#jquery) documentation.\n"
  },
  "response": [
    {
      "name": "Success response",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "description": "Added as a part of security scheme: basic",
            "key": "Authorization",
            "value": "Basic <credentials>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/users/me",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "users",
            "me"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"user\": {\n    \"name\": \"<string>\",\n    \"active\": \"<boolean>\",\n    \"alias\": \"<string>\",\n    \"chat_only\": \"<boolean>\",\n    \"created_at\": \"<string>\",\n    \"custom_role_id\": \"<integer>\",\n    \"default_group_id\": \"<integer>\",\n    \"details\": \"<string>\",\n    \"email\": \"<string>\",\n    \"external_id\": \"<string>\",\n    \"iana_time_zone\": \"<string>\",\n    \"id\": \"<integer>\",\n    \"last_login_at\": \"<string>\",\n    \"locale\": \"<string>\",\n    \"locale_id\": \"<integer>\",\n    \"moderator\": \"<boolean>\",\n    \"notes\": \"<string>\",\n    \"only_private_comments\": \"<boolean>\",\n    \"organization_id\": \"<integer>\",\n    \"phone\": \"<string>\",\n    \"photo\": {\n      \"dolore50\": -51881550.25541992\n    },\n    \"remote_photo_url\": \"<string>\",\n    \"report_csv\": \"<boolean>\",\n    \"restricted_agent\": \"<boolean>\",\n    \"role\": \"<string>\",\n    \"role_type\": \"<integer>\",\n    \"shared\": \"<boolean>\",\n    \"shared_agent\": \"<boolean>\",\n    \"shared_phone_number\": \"<boolean>\",\n    \"signature\": \"<string>\",\n    \"suspended\": \"<boolean>\",\n    \"tags\": \"<array>\",\n    \"ticket_restriction\": \"<string>\",\n    \"time_zone\": \"<string>\",\n    \"two_factor_auth_enabled\": \"<boolean>\",\n    \"updated_at\": \"<string>\",\n    \"url\": \"<string>\",\n    \"user_fields\": {\n      \"deserunt_c4\": -61141403\n    },\n    \"verified\": \"<boolean>\",\n    \"authenticity_token\": \"<string>\"\n  }\n}"
    }
  ]
}