SQL Server / Postman API / API Key Owner
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_OAMethod @http, 'SetRequestHeader', NULL, 'X-API-Key', '{{postman_api_key}}'
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://api.getpostman.com/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": {
-- "id": "631643",
-- "username": "janedoe",
-- "email": "janedoe@example.com",
-- "fullName": "Jane Doe",
-- "avatar": "https://www.gravatar.com/avatar/e1f3994f2632af3d1c8c2dcc168a10e6",
-- "isPublic": false
-- },
-- "operations": [
-- {
-- "name": "mock_usage",
-- "limit": 1000000,
-- "usage": 2382,
-- "overage": 0
-- },
-- {
-- "name": "monitor_request_runs",
-- "limit": 10000000,
-- "usage": 49492,
-- "overage": 0
-- },
-- {
-- "name": "documenter_public_views",
-- "limit": 5000000,
-- "usage": 120232,
-- "overage": 0
-- },
-- {
-- "name": "api_usage",
-- "limit": 1000000,
-- "usage": 1345,
-- "overage": 0
-- },
-- {
-- "name": "custom_domains",
-- "limit": 25,
-- "usage": 1,
-- "overage": 0
-- },
-- {
-- "name": "custom_authentication_methods",
-- "limit": 1,
-- "usage": 1,
-- "overage": 0
-- },
-- {
-- "name": "serverless_requests",
-- "limit": 10000,
-- "usage": 0,
-- "overage": 0
-- },
-- {
-- "name": "integrations",
-- "limit": 5000,
-- "usage": 145,
-- "overage": 0
-- },
-- {
-- "name": "cloud_agent_requests",
-- "limit": 1000000,
-- "usage": 23823,
-- "overage": 0
-- }
-- ]
-- }
-- 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)
DECLARE @limit int
DECLARE @usage int
DECLARE @overage int
DECLARE @Id nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Id OUT, 'user.id'
DECLARE @Username nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Username OUT, 'user.username'
DECLARE @v_Email nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @v_Email OUT, 'user.email'
DECLARE @FullName nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @FullName OUT, 'user.fullName'
DECLARE @Avatar nvarchar(4000)
EXEC sp_OAMethod @jResp, 'StringOf', @Avatar OUT, 'user.avatar'
DECLARE @IsPublic int
EXEC sp_OAMethod @jResp, 'BoolOf', @IsPublic OUT, 'user.isPublic'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'operations'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'operations[i].name'
EXEC sp_OAMethod @jResp, 'IntOf', @limit OUT, 'operations[i].limit'
EXEC sp_OAMethod @jResp, 'IntOf', @usage OUT, 'operations[i].usage'
EXEC sp_OAMethod @jResp, 'IntOf', @overage OUT, 'operations[i].overage'
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO
Curl Command
curl -X GET
-H "X-API-Key: {{postman_api_key}}"
https://api.getpostman.com/me
Postman Collection Item JSON
{
"name": "API Key Owner",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"var responseJSON;",
"",
"// parse response body as JSON",
"try { responseJSON = JSON.parse(responseBody); } catch (e) { }",
"tests['received a valid response JSON'] = !!responseJSON;",
"!responseJSON && (responseJSON = {});",
"",
"tests['status code is 200'] = (responseCode.code === 200);",
"tests['response does not have errors'] = (!responseJSON.error);",
"",
"tests['response has a user object'] = (typeof responseJSON.user === 'object');",
"tests['response user object has id'] = (responseJSON.user && responseJSON.user.id);"
]
}
}
],
"request": {
"method": "GET",
"header": [
],
"url": {
"raw": "https://api.getpostman.com/me",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"me"
]
},
"description": "the `/me` Postman API endpoint lets you access information about the authenticated user. You can retrieve the authenticated user's username, full name, e-mail address, and any other available information.\n\n> Requires <a href=\"#authentication\">API Key</a> as `X-Api-Key` request header or `apikey` URL query parameter."
},
"response": [
{
"name": "Valid Response",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "https://api.getpostman.com/me",
"protocol": "https",
"host": [
"api",
"getpostman",
"com"
],
"path": [
"me"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"name": "Content-Type",
"description": {
"content": "",
"type": "text/plain"
}
}
],
"cookie": [
],
"body": "{\n \"user\": {\n \"id\": \"631643\",\n \"username\": \"janedoe\",\n \"email\": \"janedoe@example.com\",\n \"fullName\": \"Jane Doe\",\n \"avatar\": \"https://www.gravatar.com/avatar/e1f3994f2632af3d1c8c2dcc168a10e6\",\n \"isPublic\": false\n },\n \"operations\": [\n {\n \"name\": \"mock_usage\",\n \"limit\": 1000000,\n \"usage\": 2382,\n \"overage\": 0\n },\n {\n \"name\": \"monitor_request_runs\",\n \"limit\": 10000000,\n \"usage\": 49492,\n \"overage\": 0\n },\n {\n \"name\": \"documenter_public_views\",\n \"limit\": 5000000,\n \"usage\": 120232,\n \"overage\": 0\n },\n {\n \"name\": \"api_usage\",\n \"limit\": 1000000,\n \"usage\": 1345,\n \"overage\": 0\n },\n {\n \"name\": \"custom_domains\",\n \"limit\": 25,\n \"usage\": 1,\n \"overage\": 0\n },\n {\n \"name\": \"custom_authentication_methods\",\n \"limit\": 1,\n \"usage\": 1,\n \"overage\": 0\n },\n {\n \"name\": \"serverless_requests\",\n \"limit\": 10000,\n \"usage\": 0,\n \"overage\": 0\n },\n {\n \"name\": \"integrations\",\n \"limit\": 5000,\n \"usage\": 145,\n \"overage\": 0\n },\n {\n \"name\": \"cloud_agent_requests\",\n \"limit\": 1000000,\n \"usage\": 23823,\n \"overage\": 0\n }\n ]\n}"
}
]
}