Chilkat Online Tools

SQL Server / Cognite API v1 / Legacy update of a project

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
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.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.

    -- {
    --   "authentication": {
    --     "protocol": "oauth2",
    --     "oAuth2Configuration": {
    --       "loginUrl": "veniam",
    --       "logoutUrl": "anim sit",
    --       "tokenUrl": "laboris enim Ut quis cillum",
    --       "clientId": "Ut",
    --       "clientSecret": "sit do dolore"
    --     },
    --     "validDomains": [
    --     ],
    --     "applicationDomains": [
    --     ]
    --   },
    --   "name": "fugiat do",
    --   "defaultGroupId": 14203386
    -- }

    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'authentication.protocol', 'oauth2'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'authentication.oAuth2Configuration.loginUrl', 'veniam'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'authentication.oAuth2Configuration.logoutUrl', 'anim sit'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'authentication.oAuth2Configuration.tokenUrl', 'laboris enim Ut quis cillum'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'authentication.oAuth2Configuration.clientId', 'Ut'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'authentication.oAuth2Configuration.clientSecret', 'sit do dolore'
    EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'authentication.validDomains'
    EXEC sp_OAMethod @json, 'UpdateNewArray', @success OUT, 'authentication.applicationDomains'
    EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'name', 'fugiat do'
    EXEC sp_OAMethod @json, 'UpdateInt', @success OUT, 'defaultGroupId', 14203386

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

    DECLARE @sbRequestBody int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbRequestBody OUT

    EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody

    DECLARE @resp int
    EXEC sp_OAMethod @http, 'PTextSb', @resp OUT, 'PUT', 'https://domain.com/api/v1/projects/{{project}}', @sbRequestBody, 'utf-8', 'application/json', 0, 0
    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
        EXEC @hr = sp_OADestroy @sbRequestBody
        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
    EXEC @hr = sp_OADestroy @sbRequestBody


END
GO

Curl Command

curl -X PUT
	-H "api-key: {{api-key}}"
	-H "content-type: application/json"
	-d '{
    "authentication": {
        "protocol": "oauth2",
        "oAuth2Configuration": {
            "loginUrl": "veniam",
            "logoutUrl": "anim sit",
            "tokenUrl": "laboris enim Ut quis cillum",
            "clientId": "Ut",
            "clientSecret": "sit do dolore"
        },
        "validDomains": [],
        "applicationDomains": []
    },
    "name": "fugiat do",
    "defaultGroupId": 14203386
}'
https://domain.com/api/v1/projects/{{project}}

Postman Collection Item JSON

{
  "id": "putProject",
  "name": "Legacy update of a project",
  "request": {
    "url": {
      "host": "{{baseUrl}}",
      "path": [
        "api",
        "v1",
        "projects",
        "{{project}}"
      ],
      "query": [
      ],
      "variable": [
      ]
    },
    "method": "PUT",
    "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": "Updates the project configuration. **Warning:** This endpoint does not support partial updates, so all fields must be set when updating the project, otherwise the existing values will be lost. Ensure you set validDomains and applicationDomains correctly. If you set applicationDomains to be empty,  any domains previously set will be removed, and you may lock yourself out of your project.\n",
    "body": {
      "mode": "raw",
      "raw": "{\n    \"authentication\": {\n        \"protocol\": \"oauth2\",\n        \"oAuth2Configuration\": {\n            \"loginUrl\": \"veniam\",\n            \"logoutUrl\": \"anim sit\",\n            \"tokenUrl\": \"laboris enim Ut quis cillum\",\n            \"clientId\": \"Ut\",\n            \"clientSecret\": \"sit do dolore\"\n        },\n        \"validDomains\": [],\n        \"applicationDomains\": []\n    },\n    \"name\": \"fugiat do\",\n    \"defaultGroupId\": 14203386\n}"
    }
  }
}