Android / Cognite API v1 / Legacy update of a project
Back to Collection Items
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttp http = new CkHttp();
boolean success;
// 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
// }
CkJsonObject json = new CkJsonObject();
json.UpdateString("authentication.protocol","oauth2");
json.UpdateString("authentication.oAuth2Configuration.loginUrl","veniam");
json.UpdateString("authentication.oAuth2Configuration.logoutUrl","anim sit");
json.UpdateString("authentication.oAuth2Configuration.tokenUrl","laboris enim Ut quis cillum");
json.UpdateString("authentication.oAuth2Configuration.clientId","Ut");
json.UpdateString("authentication.oAuth2Configuration.clientSecret","sit do dolore");
json.UpdateNewArray("authentication.validDomains");
json.UpdateNewArray("authentication.applicationDomains");
json.UpdateString("name","fugiat do");
json.UpdateInt("defaultGroupId",14203386);
http.SetRequestHeader("content-type","application/json");
http.SetRequestHeader("api-key","{{api-key}}");
CkStringBuilder sbRequestBody = new CkStringBuilder();
json.EmitSb(sbRequestBody);
CkHttpResponse resp = http.PTextSb("PUT","https://domain.com/api/v1/projects/{{project}}",sbRequestBody,"utf-8","application/json",false,false);
if (http.get_LastMethodSuccess() == false) {
Log.i(TAG, http.lastErrorText());
return;
}
Log.i(TAG, String.valueOf(resp.get_StatusCode()));
Log.i(TAG, resp.bodyStr());
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}
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}"
}
}
}