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.
// {
// "items": [
// {
// "codetype": "EGS",
// "itemCode": "EG-113317713-5598542",
// "comment": "create code usage reason"
// },
// {
// "codetype": "EGS",
// "itemCode": "EG-100000053-10015",
// "comment": "create code usage reason"
// }
// ]
// }
CkJsonObject json = new CkJsonObject();
json.UpdateString("items[0].codetype","EGS");
json.UpdateString("items[0].itemCode","EG-113317713-5598542");
json.UpdateString("items[0].comment","create code usage reason");
json.UpdateString("items[1].codetype","EGS");
json.UpdateString("items[1].itemCode","EG-100000053-10015");
json.UpdateString("items[1].comment","create code usage reason");
http.SetRequestHeader("Content-Type","application/json");
http.SetRequestHeader("Accept-Language","en");
// Adds the "Authorization: Bearer <access_token>" header.
http.put_AuthToken("<access_token>");
CkStringBuilder sbRequestBody = new CkStringBuilder();
json.EmitSb(sbRequestBody);
CkHttpResponse resp = http.PTextSb("PUT","https://domain.com/api/v1.0/codetypes/requests/codeusages",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 "Authorization: Bearer <access_token>"
-H "Content-Type: application/json"
-H "Accept-Language: en"
-d '{
"items": [
{
"codetype": "EGS",
"itemCode": "EG-113317713-5598542",
"comment": "create code usage reason"
},
{
"codetype": "EGS",
"itemCode": "EG-100000053-10015",
"comment": "create code usage reason"
}
]
}'
https://domain.com/api/v1.0/codetypes/requests/codeusages
Postman Collection Item JSON
{
"name": "8. Request Code Reuse",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{generatedAccessToken}}",
"type": "string"
}
]
},
"method": "PUT",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept-Language",
"value": "en",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"items\": [\n {\n \"codetype\": \"EGS\",\n \"itemCode\": \"EG-113317713-5598542\",\n \"comment\": \"create code usage reason\"\n },\n {\n \"codetype\": \"EGS\",\n \"itemCode\": \"EG-100000053-10015\",\n \"comment\": \"create code usage reason\"\n }\n ]\n}"
},
"url": {
"raw": "{{apiBaseUrl}}/api/v1.0/codetypes/requests/codeusages",
"host": [
"{{apiBaseUrl}}"
],
"path": [
"api",
"v1.0",
"codetypes",
"requests",
"codeusages"
]
}
},
"response": [
]
}