Chilkat Online Tools

PureBasic / Cognite API v1 / Legacy update of a project

Back to Collection Items

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"

Procedure ChilkatExample()

    ; This example assumes the Chilkat API to have been previously unlocked.
    ; See Global Unlock Sample for sample code.

    http.i = CkHttp::ckCreate()
    If http.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ; 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
    ; }

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckUpdateString(json,"authentication.protocol","oauth2")
    CkJsonObject::ckUpdateString(json,"authentication.oAuth2Configuration.loginUrl","veniam")
    CkJsonObject::ckUpdateString(json,"authentication.oAuth2Configuration.logoutUrl","anim sit")
    CkJsonObject::ckUpdateString(json,"authentication.oAuth2Configuration.tokenUrl","laboris enim Ut quis cillum")
    CkJsonObject::ckUpdateString(json,"authentication.oAuth2Configuration.clientId","Ut")
    CkJsonObject::ckUpdateString(json,"authentication.oAuth2Configuration.clientSecret","sit do dolore")
    CkJsonObject::ckUpdateNewArray(json,"authentication.validDomains")
    CkJsonObject::ckUpdateNewArray(json,"authentication.applicationDomains")
    CkJsonObject::ckUpdateString(json,"name","fugiat do")
    CkJsonObject::ckUpdateInt(json,"defaultGroupId",14203386)

    CkHttp::ckSetRequestHeader(http,"content-type","application/json")
    CkHttp::ckSetRequestHeader(http,"api-key","{{api-key}}")

    sbRequestBody.i = CkStringBuilder::ckCreate()
    If sbRequestBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckEmitSb(json,sbRequestBody)

    resp.i = CkHttp::ckPTextSb(http,"PUT","https://domain.com/api/v1/projects/{{project}}",sbRequestBody,"utf-8","application/json",0,0)
    If CkHttp::ckLastMethodSuccess(http) = 0
        Debug CkHttp::ckLastErrorText(http)
        CkHttp::ckDispose(http)
        CkJsonObject::ckDispose(json)
        CkStringBuilder::ckDispose(sbRequestBody)
        ProcedureReturn
    EndIf

    Debug Str(CkHttpResponse::ckStatusCode(resp))
    Debug CkHttpResponse::ckBodyStr(resp)
    CkHttpResponse::ckDispose(resp)



    CkHttp::ckDispose(http)
    CkJsonObject::ckDispose(json)
    CkStringBuilder::ckDispose(sbRequestBody)


    ProcedureReturn
EndProcedure

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}"
    }
  }
}