Chilkat Online Tools

SQL Server / Cognite API v1 / Convert engineering diagrams to SVG format.

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

    -- Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    -- The following JSON is sent in the request body.

    -- {
    --   "items": [
    --     {
    --       "annotations": [
    --         {
    --           "text": "ullamco sit do id",
    --           "region": {
    --             "shape": "rectangle",
    --             "vertices": [
    --               {
    --                 "x": 0.3313160824131578,
    --                 "y": 0.06017099978470597
    --               },
    --               {
    --                 "x": 0.4553815976895428,
    --                 "y": 0.144886445412165
    --               }
    --             ],
    --             "page": 37
    --           },
    --           "confidence": 0.13333561382131243,
    --           "entities": [
    --             {},
    --             {}
    --           ]
    --         },
    --         {
    --           "text": "nulla incididunt eu elit",
    --           "region": {
    --             "shape": "rectangle",
    --             "vertices": [
    --               {
    --                 "x": 0.7156592481743367,
    --                 "y": 0.574575250659763
    --               },
    --               {
    --                 "x": 0.3406638759937599,
    --                 "y": 0.9382533039282044
    --               }
    --             ],
    --             "page": 27
    --           },
    --           "confidence": 0.4455875462977701,
    --           "entities": [
    --             {},
    --             {}
    --           ]
    --         }
    --       ],
    --       "fileId": -57827040,
    --       "fileExternalId": "ea aliquip ipsum"
    --     },
    --     {
    --       "annotations": [
    --         {
    --           "text": "aliquip exercitation",
    --           "region": {
    --             "shape": "rectangle",
    --             "vertices": [
    --               {
    --                 "x": 0.2442804051829428,
    --                 "y": 0.4917796879609626
    --               },
    --               {
    --                 "x": 0.7404857062791013,
    --                 "y": 0.8271623596435489
    --               }
    --             ],
    --             "page": 4
    --           },
    --           "confidence": 0.4320602168658312,
    --           "entities": [
    --             {},
    --             {}
    --           ]
    --         },
    --         {
    --           "text": "aliqua ea ut voluptate",
    --           "region": {
    --             "shape": "rectangle",
    --             "vertices": [
    --               {
    --                 "x": 0.25343046275755277,
    --                 "y": 0.8190223707736768
    --               },
    --               {
    --                 "x": 0.9117316520574312,
    --                 "y": 0.865071569037893
    --               }
    --             ],
    --             "page": 38
    --           },
    --           "confidence": 0.4476938516764881,
    --           "entities": [
    --             {},
    --             {}
    --           ]
    --         }
    --       ],
    --       "fileId": 98464957,
    --       "fileExternalId": 20163608
    --     }
    --   ],
    --   "grayscale": true
    -- }

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

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].annotations[0].text', 'ullamco sit do id'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].annotations[0].region.shape', 'rectangle'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].annotations[0].region.vertices[0].x', '0.3313160824131578'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].annotations[0].region.vertices[0].y', '0.06017099978470597'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].annotations[0].region.vertices[1].x', '0.4553815976895428'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].annotations[0].region.vertices[1].y', '0.144886445412165'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[0].annotations[0].region.page', 37
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].annotations[0].confidence', '0.13333561382131243'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].annotations[1].text', 'nulla incididunt eu elit'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].annotations[1].region.shape', 'rectangle'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].annotations[1].region.vertices[0].x', '0.7156592481743367'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].annotations[1].region.vertices[0].y', '0.574575250659763'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].annotations[1].region.vertices[1].x', '0.3406638759937599'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].annotations[1].region.vertices[1].y', '0.9382533039282044'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[0].annotations[1].region.page', 27
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[0].annotations[1].confidence', '0.4455875462977701'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[0].fileId', -57827040
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].fileExternalId', 'ea aliquip ipsum'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].annotations[0].text', 'aliquip exercitation'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].annotations[0].region.shape', 'rectangle'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].annotations[0].region.vertices[0].x', '0.2442804051829428'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].annotations[0].region.vertices[0].y', '0.4917796879609626'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].annotations[0].region.vertices[1].x', '0.7404857062791013'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].annotations[0].region.vertices[1].y', '0.8271623596435489'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[1].annotations[0].region.page', 4
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].annotations[0].confidence', '0.4320602168658312'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].annotations[1].text', 'aliqua ea ut voluptate'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].annotations[1].region.shape', 'rectangle'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].annotations[1].region.vertices[0].x', '0.25343046275755277'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].annotations[1].region.vertices[0].y', '0.8190223707736768'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].annotations[1].region.vertices[1].x', '0.9117316520574312'
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].annotations[1].region.vertices[1].y', '0.865071569037893'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[1].annotations[1].region.page', 38
    EXEC sp_OAMethod @json, 'UpdateNumber', @success OUT, 'items[1].annotations[1].confidence', '0.4476938516764881'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[1].fileId', 98464957
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'items[1].fileExternalId', 20163608
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'grayscale', 1

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'content-type', 'application/json'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'api-key', '{{api-key}}'

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PostJson3', @resp OUT, 'https://domain.com/api/v1/projects/{{project}}/context/diagram/convert', 'application/json', @json
    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 @json
        RETURN
      END

    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    PRINT @iTmp0
    EXEC sp_OAGetProperty @resp, 'BodyStr', @sTmp0 OUT
    PRINT @sTmp0
    EXEC @hr = sp_OADestroy @resp


    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @json


END
GO

Curl Command

curl -X POST
	-H "api-key: {{api-key}}"
	-H "content-type: application/json"
	-d '{
    "items": [
        {
            "annotations": [
                {
                    "text": "ullamco sit do id",
                    "region": {
                        "shape": "rectangle",
                        "vertices": [
                            {
                                "x": 0.3313160824131578,
                                "y": 0.06017099978470597
                            },
                            {
                                "x": 0.4553815976895428,
                                "y": 0.144886445412165
                            }
                        ],
                        "page": 37
                    },
                    "confidence": 0.13333561382131243,
                    "entities": [
                        {},
                        {}
                    ]
                },
                {
                    "text": "nulla incididunt eu elit",
                    "region": {
                        "shape": "rectangle",
                        "vertices": [
                            {
                                "x": 0.7156592481743367,
                                "y": 0.574575250659763
                            },
                            {
                                "x": 0.3406638759937599,
                                "y": 0.9382533039282044
                            }
                        ],
                        "page": 27
                    },
                    "confidence": 0.4455875462977701,
                    "entities": [
                        {},
                        {}
                    ]
                }
            ],
            "fileId": -57827040,
            "fileExternalId": "ea aliquip ipsum"
        },
        {
            "annotations": [
                {
                    "text": "aliquip exercitation",
                    "region": {
                        "shape": "rectangle",
                        "vertices": [
                            {
                                "x": 0.2442804051829428,
                                "y": 0.4917796879609626
                            },
                            {
                                "x": 0.7404857062791013,
                                "y": 0.8271623596435489
                            }
                        ],
                        "page": 4
                    },
                    "confidence": 0.4320602168658312,
                    "entities": [
                        {},
                        {}
                    ]
                },
                {
                    "text": "aliqua ea ut voluptate",
                    "region": {
                        "shape": "rectangle",
                        "vertices": [
                            {
                                "x": 0.25343046275755277,
                                "y": 0.8190223707736768
                            },
                            {
                                "x": 0.9117316520574312,
                                "y": 0.865071569037893
                            }
                        ],
                        "page": 38
                    },
                    "confidence": 0.4476938516764881,
                    "entities": [
                        {},
                        {}
                    ]
                }
            ],
            "fileId": 98464957,
            "fileExternalId": 20163608
        }
    ],
    "grayscale": true
}'
https://domain.com/api/v1/projects/{{project}}/context/diagram/convert

Postman Collection Item JSON

{
  "id": "diagramConvert",
  "name": "Convert engineering diagrams to SVG format.",
  "request": {
    "url": {
      "host": "{{baseUrl}}",
      "path": [
        "api",
        "v1",
        "projects",
        "{{project}}",
        "context",
        "diagram",
        "convert"
      ],
      "query": [
      ],
      "variable": [
      ]
    },
    "method": "POST",
    "header": [
      {
        "key": "api-key",
        "value": "{{api-key}}",
        "description": "An admin can create API keys in the Cognite console."
      },
      {
        "key": "content-type",
        "value": "application/json"
      }
    ],
    "description": "Create interactive engineering diagrams in SVG format with highlighted annotations.",
    "body": {
      "mode": "raw",
      "raw": "{\n    \"items\": [\n        {\n            \"annotations\": [\n                {\n                    \"text\": \"ullamco sit do id\",\n                    \"region\": {\n                        \"shape\": \"rectangle\",\n                        \"vertices\": [\n                            {\n                                \"x\": 0.3313160824131578,\n                                \"y\": 0.06017099978470597\n                            },\n                            {\n                                \"x\": 0.4553815976895428,\n                                \"y\": 0.144886445412165\n                            }\n                        ],\n                        \"page\": 37\n                    },\n                    \"confidence\": 0.13333561382131243,\n                    \"entities\": [\n                        {},\n                        {}\n                    ]\n                },\n                {\n                    \"text\": \"nulla incididunt eu elit\",\n                    \"region\": {\n                        \"shape\": \"rectangle\",\n                        \"vertices\": [\n                            {\n                                \"x\": 0.7156592481743367,\n                                \"y\": 0.574575250659763\n                            },\n                            {\n                                \"x\": 0.3406638759937599,\n                                \"y\": 0.9382533039282044\n                            }\n                        ],\n                        \"page\": 27\n                    },\n                    \"confidence\": 0.4455875462977701,\n                    \"entities\": [\n                        {},\n                        {}\n                    ]\n                }\n            ],\n            \"fileId\": -57827040,\n            \"fileExternalId\": \"ea aliquip ipsum\"\n        },\n        {\n            \"annotations\": [\n                {\n                    \"text\": \"aliquip exercitation\",\n                    \"region\": {\n                        \"shape\": \"rectangle\",\n                        \"vertices\": [\n                            {\n                                \"x\": 0.2442804051829428,\n                                \"y\": 0.4917796879609626\n                            },\n                            {\n                                \"x\": 0.7404857062791013,\n                                \"y\": 0.8271623596435489\n                            }\n                        ],\n                        \"page\": 4\n                    },\n                    \"confidence\": 0.4320602168658312,\n                    \"entities\": [\n                        {},\n                        {}\n                    ]\n                },\n                {\n                    \"text\": \"aliqua ea ut voluptate\",\n                    \"region\": {\n                        \"shape\": \"rectangle\",\n                        \"vertices\": [\n                            {\n                                \"x\": 0.25343046275755277,\n                                \"y\": 0.8190223707736768\n                            },\n                            {\n                                \"x\": 0.9117316520574312,\n                                \"y\": 0.865071569037893\n                            }\n                        ],\n                        \"page\": 38\n                    },\n                    \"confidence\": 0.4476938516764881,\n                    \"entities\": [\n                        {},\n                        {}\n                    ]\n                }\n            ],\n            \"fileId\": 98464957,\n            \"fileExternalId\": 20163608\n        }\n    ],\n    \"grayscale\": true\n}"
    }
  }
}