Chilkat Online Tools

SQL Server / Cognite API v1 / Create transformations

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": [
    --     {
    --       "name": "ipsum ut sed d",
    --       "ignoreNullFields": false,
    --       "externalId": "proident eu mollit",
    --       "query": "qui non sint ut",
    --       "destination": {
    --         "type": "assets"
    --       },
    --       "conflictMode": "aliquip dolore nulla c",
    --       "isPublic": false,
    --       "sourceApiKey": "esse dolore aliqua in",
    --       "destinationApiKey": "nulla in tempor",
    --       "sourceOidcCredentials": {
    --         "clientId": "p",
    --         "clientSecret": "amet",
    --         "tokenUri": "sit voluptate dolore ",
    --         "cdfProjectName": "aliquip velit incididunt",
    --         "scopes": "consectetur cillum",
    --         "audience": "non magna"
    --       },
    --       "destinationOidcCredentials": {
    --         "clientId": "est culpa",
    --         "clientSecret": "cillum exercitation",
    --         "tokenUri": "do ea sint culpa",
    --         "cdfProjectName": "officia proident",
    --         "scopes": "cupidatat Lorem elit adipisicing",
    --         "audience": "nisi veniam"
    --       }
    --     },
    --     {
    --       "name": "in occaecat ut",
    --       "ignoreNullFields": false,
    --       "externalId": "magna Lorem",
    --       "query": "cillum dolor ea",
    --       "destination": {
    --         "type": "relationships"
    --       },
    --       "conflictMode": "pariatur laborum eiusmod Ut consectetur",
    --       "isPublic": true,
    --       "sourceApiKey": "ullamco eu velit elit",
    --       "destinationApiKey": "dolore in",
    --       "sourceOidcCredentials": {
    --         "clientId": "Ut",
    --         "clientSecret": "minim commodo Lorem in",
    --         "tokenUri": "culpa ipsum aliquip pariatur",
    --         "cdfProjectName": "minim",
    --         "scopes": "deserunt cillum in non mollit",
    --         "audience": "elit ea"
    --       },
    --       "destinationOidcCredentials": {
    --         "clientId": "elit eu exercitation",
    --         "clientSecret": "fugiat",
    --         "tokenUri": "velit mollit",
    --         "cdfProjectName": "tempor enim exercitation voluptate dolore",
    --         "scopes": "ipsum Lorem ullamco consequat",
    --         "audience": "ullamco"
    --       }
    --     }
    --   ]
    -- }

    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].name', 'ipsum ut sed d'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[0].ignoreNullFields', 0
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].externalId', 'proident eu mollit'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].query', 'qui non sint ut'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].destination.type', 'assets'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].conflictMode', 'aliquip dolore nulla c'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[0].isPublic', 0
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].sourceApiKey', 'esse dolore aliqua in'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].destinationApiKey', 'nulla in tempor'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].sourceOidcCredentials.clientId', 'p'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].sourceOidcCredentials.clientSecret', 'amet'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].sourceOidcCredentials.tokenUri', 'sit voluptate dolore '
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].sourceOidcCredentials.cdfProjectName', 'aliquip velit incididunt'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].sourceOidcCredentials.scopes', 'consectetur cillum'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].sourceOidcCredentials.audience', 'non magna'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].destinationOidcCredentials.clientId', 'est culpa'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].destinationOidcCredentials.clientSecret', 'cillum exercitation'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].destinationOidcCredentials.tokenUri', 'do ea sint culpa'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].destinationOidcCredentials.cdfProjectName', 'officia proident'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].destinationOidcCredentials.scopes', 'cupidatat Lorem elit adipisicing'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[0].destinationOidcCredentials.audience', 'nisi veniam'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].name', 'in occaecat ut'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[1].ignoreNullFields', 0
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].externalId', 'magna Lorem'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].query', 'cillum dolor ea'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].destination.type', 'relationships'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].conflictMode', 'pariatur laborum eiusmod Ut consectetur'
    EXEC sp_OAMethod @json, 'UpdateBool', @success OUT, 'items[1].isPublic', 1
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].sourceApiKey', 'ullamco eu velit elit'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].destinationApiKey', 'dolore in'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].sourceOidcCredentials.clientId', 'Ut'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].sourceOidcCredentials.clientSecret', 'minim commodo Lorem in'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].sourceOidcCredentials.tokenUri', 'culpa ipsum aliquip pariatur'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].sourceOidcCredentials.cdfProjectName', 'minim'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].sourceOidcCredentials.scopes', 'deserunt cillum in non mollit'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].sourceOidcCredentials.audience', 'elit ea'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].destinationOidcCredentials.clientId', 'elit eu exercitation'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].destinationOidcCredentials.clientSecret', 'fugiat'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].destinationOidcCredentials.tokenUri', 'velit mollit'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].destinationOidcCredentials.cdfProjectName', 'tempor enim exercitation voluptate dolore'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].destinationOidcCredentials.scopes', 'ipsum Lorem ullamco consequat'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'items[1].destinationOidcCredentials.audience', 'ullamco'

    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}}/transformations', '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": [
        {
            "name": "ipsum ut sed d",
            "ignoreNullFields": false,
            "externalId": "proident eu mollit",
            "query": "qui non sint ut",
            "destination": {
                "type": "assets"
            },
            "conflictMode": "aliquip dolore nulla c",
            "isPublic": false,
            "sourceApiKey": "esse dolore aliqua in",
            "destinationApiKey": "nulla in tempor",
            "sourceOidcCredentials": {
                "clientId": "p",
                "clientSecret": "amet",
                "tokenUri": "sit voluptate dolore ",
                "cdfProjectName": "aliquip velit incididunt",
                "scopes": "consectetur cillum",
                "audience": "non magna"
            },
            "destinationOidcCredentials": {
                "clientId": "est culpa",
                "clientSecret": "cillum exercitation",
                "tokenUri": "do ea sint culpa",
                "cdfProjectName": "officia proident",
                "scopes": "cupidatat Lorem elit adipisicing",
                "audience": "nisi veniam"
            }
        },
        {
            "name": "in occaecat ut",
            "ignoreNullFields": false,
            "externalId": "magna Lorem",
            "query": "cillum dolor ea",
            "destination": {
                "type": "relationships"
            },
            "conflictMode": "pariatur laborum eiusmod Ut consectetur",
            "isPublic": true,
            "sourceApiKey": "ullamco eu velit elit",
            "destinationApiKey": "dolore in",
            "sourceOidcCredentials": {
                "clientId": "Ut",
                "clientSecret": "minim commodo Lorem in",
                "tokenUri": "culpa ipsum aliquip pariatur",
                "cdfProjectName": "minim",
                "scopes": "deserunt cillum in non mollit",
                "audience": "elit ea"
            },
            "destinationOidcCredentials": {
                "clientId": "elit eu exercitation",
                "clientSecret": "fugiat",
                "tokenUri": "velit mollit",
                "cdfProjectName": "tempor enim exercitation voluptate dolore",
                "scopes": "ipsum Lorem ullamco consequat",
                "audience": "ullamco"
            }
        }
    ]
}'
https://domain.com/api/v1/projects/{{project}}/transformations

Postman Collection Item JSON

{
  "id": "createTransformations",
  "name": "Create transformations",
  "request": {
    "url": {
      "host": "{{baseUrl}}",
      "path": [
        "api",
        "v1",
        "projects",
        "{{project}}",
        "transformations"
      ],
      "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 a maximum of 1000 transformations per request.",
    "body": {
      "mode": "raw",
      "raw": "{\n    \"items\": [\n        {\n            \"name\": \"ipsum ut sed d\",\n            \"ignoreNullFields\": false,\n            \"externalId\": \"proident eu mollit\",\n            \"query\": \"qui non sint ut\",\n            \"destination\": {\n                \"type\": \"assets\"\n            },\n            \"conflictMode\": \"aliquip dolore nulla c\",\n            \"isPublic\": false,\n            \"sourceApiKey\": \"esse dolore aliqua in\",\n            \"destinationApiKey\": \"nulla in tempor\",\n            \"sourceOidcCredentials\": {\n                \"clientId\": \"p\",\n                \"clientSecret\": \"amet\",\n                \"tokenUri\": \"sit voluptate dolore \",\n                \"cdfProjectName\": \"aliquip velit incididunt\",\n                \"scopes\": \"consectetur cillum\",\n                \"audience\": \"non magna\"\n            },\n            \"destinationOidcCredentials\": {\n                \"clientId\": \"est culpa\",\n                \"clientSecret\": \"cillum exercitation\",\n                \"tokenUri\": \"do ea sint culpa\",\n                \"cdfProjectName\": \"officia proident\",\n                \"scopes\": \"cupidatat Lorem elit adipisicing\",\n                \"audience\": \"nisi veniam\"\n            }\n        },\n        {\n            \"name\": \"in occaecat ut\",\n            \"ignoreNullFields\": false,\n            \"externalId\": \"magna Lorem\",\n            \"query\": \"cillum dolor ea\",\n            \"destination\": {\n                \"type\": \"relationships\"\n            },\n            \"conflictMode\": \"pariatur laborum eiusmod Ut consectetur\",\n            \"isPublic\": true,\n            \"sourceApiKey\": \"ullamco eu velit elit\",\n            \"destinationApiKey\": \"dolore in\",\n            \"sourceOidcCredentials\": {\n                \"clientId\": \"Ut\",\n                \"clientSecret\": \"minim commodo Lorem in\",\n                \"tokenUri\": \"culpa ipsum aliquip pariatur\",\n                \"cdfProjectName\": \"minim\",\n                \"scopes\": \"deserunt cillum in non mollit\",\n                \"audience\": \"elit ea\"\n            },\n            \"destinationOidcCredentials\": {\n                \"clientId\": \"elit eu exercitation\",\n                \"clientSecret\": \"fugiat\",\n                \"tokenUri\": \"velit mollit\",\n                \"cdfProjectName\": \"tempor enim exercitation voluptate dolore\",\n                \"scopes\": \"ipsum Lorem ullamco consequat\",\n                \"audience\": \"ullamco\"\n            }\n        }\n    ]\n}"
    }
  }
}