Chilkat Online Tools

delphiDll / easybill REST API / Create project

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
json: HCkJsonObject;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
name: PWideChar;
budget_amount: Integer;
budget_time: Integer;
customer_id: PWideChar;
hourly_rate: PWideChar;
id: PWideChar;
login_id: PWideChar;
note: PWideChar;
status: PWideChar;
due_at: PWideChar;
budget_notify_frequency: PWideChar;
consumed_time: PWideChar;
consumed_amount: PWideChar;

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

http := CkHttp_Create();

// Use this online tool to generate code from sample JSON: Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "name": "<string>",
//   "budget_amount": 0,
//   "budget_time": 0,
//   "customer_id": null,
//   "hourly_rate": "<float>",
//   "id": "<long>",
//   "login_id": "<long>",
//   "note": null,
//   "status": "OPEN",
//   "due_at": null,
//   "budget_notify_frequency": "ALWAYS",
//   "consumed_time": "<integer>",
//   "consumed_amount": "<integer>"
// }

json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'name','<string>');
CkJsonObject_UpdateInt(json,'budget_amount',0);
CkJsonObject_UpdateInt(json,'budget_time',0);
CkJsonObject_UpdateNull(json,'customer_id');
CkJsonObject_UpdateString(json,'hourly_rate','<float>');
CkJsonObject_UpdateString(json,'id','<long>');
CkJsonObject_UpdateString(json,'login_id','<long>');
CkJsonObject_UpdateNull(json,'note');
CkJsonObject_UpdateString(json,'status','OPEN');
CkJsonObject_UpdateNull(json,'due_at');
CkJsonObject_UpdateString(json,'budget_notify_frequency','ALWAYS');
CkJsonObject_UpdateString(json,'consumed_time','<integer>');
CkJsonObject_UpdateString(json,'consumed_amount','<integer>');

CkHttp_SetRequestHeader(http,'Content-Type','application/json');
CkHttp_SetRequestHeader(http,'Authorization','{{apiKey}}');
CkHttp_SetRequestHeader(http,'Accept','application/json');

resp := CkHttp_PostJson3(http,'https://api.easybill.de/rest/v1/projects','application/json',json);
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttpResponse__header(resp));
    Memo1.Lines.Add('Failed.');
    CkHttpResponse_Dispose(resp);
    Exit;
  end;
CkHttpResponse_Dispose(resp);

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "name": "<string>",
//   "budget_amount": 0,
//   "budget_time": 0,
//   "customer_id": null,
//   "hourly_rate": "<float>",
//   "id": "<long>",
//   "login_id": "<long>",
//   "note": null,
//   "status": "OPEN",
//   "due_at": null,
//   "budget_notify_frequency": "ALWAYS",
//   "consumed_time": "<integer>",
//   "consumed_amount": "<integer>"
// }

// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

name := CkJsonObject__stringOf(jResp,'name');
budget_amount := CkJsonObject_IntOf(jResp,'budget_amount');
budget_time := CkJsonObject_IntOf(jResp,'budget_time');
customer_id := CkJsonObject__stringOf(jResp,'customer_id');
hourly_rate := CkJsonObject__stringOf(jResp,'hourly_rate');
id := CkJsonObject__stringOf(jResp,'id');
login_id := CkJsonObject__stringOf(jResp,'login_id');
note := CkJsonObject__stringOf(jResp,'note');
status := CkJsonObject__stringOf(jResp,'status');
due_at := CkJsonObject__stringOf(jResp,'due_at');
budget_notify_frequency := CkJsonObject__stringOf(jResp,'budget_notify_frequency');
consumed_time := CkJsonObject__stringOf(jResp,'consumed_time');
consumed_amount := CkJsonObject__stringOf(jResp,'consumed_amount');

CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

Curl Command

curl -X POST
	-H "Authorization: {{apiKey}}"
	-H "Content-Type: application/json"
	-H "Accept: application/json"
	-d '{
  "name": "<string>",
  "budget_amount": 0,
  "budget_time": 0,
  "customer_id": null,
  "hourly_rate": "<float>",
  "id": "<long>",
  "login_id": "<long>",
  "note": null,
  "status": "OPEN",
  "due_at": null,
  "budget_notify_frequency": "ALWAYS",
  "consumed_time": "<integer>",
  "consumed_amount": "<integer>"
}'
https://api.easybill.de/rest/v1/projects

Postman Collection Item JSON

{
  "name": "Create project",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "value": "application/json"
      },
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n  \"name\": \"<string>\",\n  \"budget_amount\": 0,\n  \"budget_time\": 0,\n  \"customer_id\": null,\n  \"hourly_rate\": \"<float>\",\n  \"id\": \"<long>\",\n  \"login_id\": \"<long>\",\n  \"note\": null,\n  \"status\": \"OPEN\",\n  \"due_at\": null,\n  \"budget_notify_frequency\": \"ALWAYS\",\n  \"consumed_time\": \"<integer>\",\n  \"consumed_amount\": \"<integer>\"\n}",
      "options": {
        "raw": {
          "headerFamily": "json",
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{baseUrl}}/projects",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "projects"
      ]
    }
  },
  "response": [
    {
      "name": "Successful operation",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "Authorization",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"name\": \"<string>\",\n  \"budget_amount\": 0,\n  \"budget_time\": 0,\n  \"customer_id\": null,\n  \"hourly_rate\": \"<float>\",\n  \"id\": \"<long>\",\n  \"login_id\": \"<long>\",\n  \"note\": null,\n  \"status\": \"OPEN\",\n  \"due_at\": null,\n  \"budget_notify_frequency\": \"ALWAYS\",\n  \"consumed_time\": \"<integer>\",\n  \"consumed_amount\": \"<integer>\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/projects",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "projects"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"name\": \"<string>\",\n  \"budget_amount\": 0,\n  \"budget_time\": 0,\n  \"customer_id\": null,\n  \"hourly_rate\": \"<float>\",\n  \"id\": \"<long>\",\n  \"login_id\": \"<long>\",\n  \"note\": null,\n  \"status\": \"OPEN\",\n  \"due_at\": null,\n  \"budget_notify_frequency\": \"ALWAYS\",\n  \"consumed_time\": \"<integer>\",\n  \"consumed_amount\": \"<integer>\"\n}"
    },
    {
      "name": "Too Many Requests",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "Authorization",
            "value": "<API Key>"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n  \"name\": \"<string>\",\n  \"budget_amount\": 0,\n  \"budget_time\": 0,\n  \"customer_id\": null,\n  \"hourly_rate\": \"<float>\",\n  \"id\": \"<long>\",\n  \"login_id\": \"<long>\",\n  \"note\": null,\n  \"status\": \"OPEN\",\n  \"due_at\": null,\n  \"budget_notify_frequency\": \"ALWAYS\",\n  \"consumed_time\": \"<integer>\",\n  \"consumed_amount\": \"<integer>\"\n}",
          "options": {
            "raw": {
              "headerFamily": "json",
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{baseUrl}}/projects",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "projects"
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "text",
      "header": [
      ],
      "cookie": [
      ],
      "body": ""
    }
  ]
}