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
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.
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
DECLARE @queryParams int
-- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @queryParams OUT
EXEC sp_OAMethod @queryParams, 'UpdateInt', @success OUT, 'limit', 801
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Authorization', '{{signature}}'
EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'Date', '{{date}}'
DECLARE @resp int
EXEC sp_OAMethod @http, 'QuickRequestParams', @resp OUT, 'GET', 'https://iaas.{{region}}.oraclecloud.com/20160918/services', @queryParams
EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
IF @iTmp0 = 0
BEGIN
EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @queryParams
RETURN
END
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 @resp, 'GetBodySb', @success OUT, @sbResponseBody
DECLARE @jarrResp int
-- Use "Chilkat_9_5_0.JsonArray" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.JsonArray', @jarrResp OUT
EXEC sp_OAMethod @jarrResp, 'LoadSb', @success OUT, @sbResponseBody
EXEC sp_OASetProperty @jarrResp, 'EmitCompact', 0
PRINT 'Response Body:'
EXEC sp_OAMethod @jarrResp, 'Emit', @sTmp0 OUT
PRINT @sTmp0
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @resp, 'StatusCode', @respStatusCode OUT
PRINT 'Response Status Code = ' + @respStatusCode
IF @respStatusCode >= 400
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @resp, 'Header', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Failed.'
EXEC @hr = sp_OADestroy @resp
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @queryParams
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jarrResp
RETURN
END
EXEC @hr = sp_OADestroy @resp
-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)
-- [
-- {
-- "id": {
-- "value": "<Error: Too many levels of nesting to fake this schema>"
-- },
-- "name": {
-- "value": "<Error: Too many levels of nesting to fake this schema>"
-- },
-- "cidrBlock": {
-- "value": "<Error: Too many levels of nesting to fake this schema>"
-- },
-- "description": {
-- "value": "<Error: Too many levels of nesting to fake this schema>"
-- }
-- },
-- {
-- "id": {
-- "value": "<Error: Too many levels of nesting to fake this schema>"
-- },
-- "name": {
-- "value": "<Error: Too many levels of nesting to fake this schema>"
-- },
-- "cidrBlock": {
-- "value": "<Error: Too many levels of nesting to fake this schema>"
-- },
-- "description": {
-- "value": "<Error: Too many levels of nesting to fake this schema>"
-- }
-- }
-- ]
-- Sample code for parsing the JSON response...
-- Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
DECLARE @json int
DECLARE @Value nvarchar(4000)
DECLARE @nameValue nvarchar(4000)
DECLARE @cidrBlockValue nvarchar(4000)
DECLARE @descriptionValue nvarchar(4000)
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAGetProperty @jarrResp, 'Size', @count_i OUT
WHILE @i < @count_i
BEGIN
EXEC sp_OAMethod @jarrResp, 'ObjectAt', @json OUT, @i
EXEC sp_OAMethod @json, 'StringOf', @Value OUT, 'id.value'
EXEC sp_OAMethod @json, 'StringOf', @nameValue OUT, 'name.value'
EXEC sp_OAMethod @json, 'StringOf', @cidrBlockValue OUT, 'cidrBlock.value'
EXEC sp_OAMethod @json, 'StringOf', @descriptionValue OUT, 'description.value'
EXEC @hr = sp_OADestroy @json
SELECT @i = @i + 1
END
EXEC @hr = sp_OADestroy @http
EXEC @hr = sp_OADestroy @queryParams
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jarrResp
END
GO
Curl Command
curl -G -d "limit=801"
-H "Date: {{date}}"
-H "Authorization: {{signature}}"
https://iaas.{{region}}.oraclecloud.com/20160918/services
Postman Collection Item JSON
{
"name": "ListServices",
"request": {
"method": "GET",
"header": [
{
"key": "Date",
"value": "{{date}}",
"description": "(Required) Current Date",
"type": "text"
},
{
"key": "Authorization",
"value": "{{signature}}",
"description": "(Required) Signature Authentication on Authorization header",
"type": "text"
}
],
"url": {
"raw": "{{baseUrl}}/services?limit=801",
"host": [
"{{baseUrl}}"
],
"path": [
"services"
],
"query": [
{
"key": "limit",
"value": "801",
"description": "For list pagination. The maximum number of results per page, or items to return in a paginated\n\"List\" call. For important details about how pagination works, see\n[List Pagination](/iaas/Content/API/Concepts/usingapi.htm#nine).\n\nExample: `50`\n"
},
{
"key": "page",
"value": "laboris proident officia tempor",
"description": "For list pagination. The value of the `opc-next-page` response header from the previous \"List\"\ncall. For important details about how pagination works, see\n[List Pagination](/iaas/Content/API/Concepts/usingapi.htm#nine).\n",
"disabled": true
}
]
},
"description": "Lists the available [Service](#/en/iaas/latest/Service/) objects that you can enable for a\nservice gateway in this region.\n"
},
"response": [
{
"name": "The list is being retrieved.",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/services?limit=801&page=laboris proident officia tempor",
"host": [
"{{baseUrl}}"
],
"path": [
"services"
],
"query": [
{
"key": "limit",
"value": "801"
},
{
"key": "page",
"value": "laboris proident officia tempor"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "opc-next-page",
"value": "officia sed",
"description": "For list pagination. When this header appears in the response, additional pages\nof results remain. For important details about how pagination works, see\n[List Pagination](/iaas/Content/API/Concepts/usingapi.htm#nine).\n"
},
{
"key": "opc-request-id",
"value": "officia sed",
"description": "Unique Oracle-assigned identifier for the request. If you need to contact\nOracle about a particular request, please provide the request ID.\n"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "[\n {\n \"id\": {\n \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n },\n \"name\": {\n \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n },\n \"cidrBlock\": {\n \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n },\n \"description\": {\n \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n }\n },\n {\n \"id\": {\n \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n },\n \"name\": {\n \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n },\n \"cidrBlock\": {\n \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n },\n \"description\": {\n \"value\": \"<Error: Too many levels of nesting to fake this schema>\"\n }\n }\n]"
},
{
"name": "Internal Server Error",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/services?limit=801&page=laboris proident officia tempor",
"host": [
"{{baseUrl}}"
],
"path": [
"services"
],
"query": [
{
"key": "limit",
"value": "801"
},
{
"key": "page",
"value": "laboris proident officia tempor"
}
]
}
},
"status": "Internal Server Error",
"code": 500,
"_postman_previewlanguage": "json",
"header": [
{
"key": "opc-request-id",
"value": "officia sed",
"description": "Unique Oracle-assigned identifier for the request. If you need to contact\nOracle about a particular request, please provide the request ID.\n"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"code\": \"et exercitation Excepteur\",\n \"message\": \"irure sit\"\n}"
},
{
"name": "An error has occurred.",
"originalRequest": {
"method": "GET",
"header": [
],
"url": {
"raw": "{{baseUrl}}/services?limit=801&page=laboris proident officia tempor",
"host": [
"{{baseUrl}}"
],
"path": [
"services"
],
"query": [
{
"key": "limit",
"value": "801"
},
{
"key": "page",
"value": "laboris proident officia tempor"
}
]
}
},
"status": "Internal Server Error",
"code": 500,
"_postman_previewlanguage": "json",
"header": [
{
"key": "opc-request-id",
"value": "officia sed",
"description": "Unique Oracle-assigned identifier for the request. If you need to contact\nOracle about a particular request, please provide the request ID.\n"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"code\": \"et exercitation Excepteur\",\n \"message\": \"irure sit\"\n}"
}
]
}