Java / easybill REST API / Create a stock entry for a position
Back to Collection Items
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
// 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.
// {
// "stock_count": "<long>",
// "position_id": "<long>",
// "id": "<long>",
// "note": "<string>",
// "document_id": "<long>",
// "document_position_id": "<long>",
// "stored_at": "<string>",
// "created_at": "<string>",
// "updated_at": "<string>"
// }
CkJsonObject json = new CkJsonObject();
json.UpdateString("stock_count","<long>");
json.UpdateString("position_id","<long>");
json.UpdateString("id","<long>");
json.UpdateString("note","<string>");
json.UpdateString("document_id","<long>");
json.UpdateString("document_position_id","<long>");
json.UpdateString("stored_at","<string>");
json.UpdateString("created_at","<string>");
json.UpdateString("updated_at","<string>");
http.SetRequestHeader("Content-Type","application/json");
http.SetRequestHeader("Authorization","{{apiKey}}");
http.SetRequestHeader("Accept","application/json");
CkHttpResponse resp = http.PostJson3("https://api.easybill.de/rest/v1/stocks","application/json",json);
if (http.get_LastMethodSuccess() == false) {
System.out.println(http.lastErrorText());
return;
}
CkStringBuilder sbResponseBody = new CkStringBuilder();
resp.GetBodySb(sbResponseBody);
CkJsonObject jResp = new CkJsonObject();
jResp.LoadSb(sbResponseBody);
jResp.put_EmitCompact(false);
System.out.println("Response Body:");
System.out.println(jResp.emit());
int respStatusCode = resp.get_StatusCode();
System.out.println("Response Status Code = " + respStatusCode);
if (respStatusCode >= 400) {
System.out.println("Response Header:");
System.out.println(resp.header());
System.out.println("Failed.");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "stock_count": "<long>",
// "position_id": "<long>",
// "id": "<long>",
// "note": "<string>",
// "document_id": "<long>",
// "document_position_id": "<long>",
// "stored_at": "<string>",
// "created_at": "<string>",
// "updated_at": "<string>"
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
String stock_count = jResp.stringOf("stock_count");
String position_id = jResp.stringOf("position_id");
String id = jResp.stringOf("id");
String note = jResp.stringOf("note");
String document_id = jResp.stringOf("document_id");
String document_position_id = jResp.stringOf("document_position_id");
String stored_at = jResp.stringOf("stored_at");
String created_at = jResp.stringOf("created_at");
String updated_at = jResp.stringOf("updated_at");
}
}
Curl Command
curl -X POST
-H "Authorization: {{apiKey}}"
-H "Content-Type: application/json"
-H "Accept: application/json"
-d '{
"stock_count": "<long>",
"position_id": "<long>",
"id": "<long>",
"note": "<string>",
"document_id": "<long>",
"document_position_id": "<long>",
"stored_at": "<string>",
"created_at": "<string>",
"updated_at": "<string>"
}'
https://api.easybill.de/rest/v1/stocks
Postman Collection Item JSON
{
"name": "Create a stock entry for a position",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"stock_count\": \"<long>\",\n \"position_id\": \"<long>\",\n \"id\": \"<long>\",\n \"note\": \"<string>\",\n \"document_id\": \"<long>\",\n \"document_position_id\": \"<long>\",\n \"stored_at\": \"<string>\",\n \"created_at\": \"<string>\",\n \"updated_at\": \"<string>\"\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/stocks",
"host": [
"{{baseUrl}}"
],
"path": [
"stocks"
]
}
},
"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 \"stock_count\": \"<long>\",\n \"position_id\": \"<long>\",\n \"id\": \"<long>\",\n \"note\": \"<string>\",\n \"document_id\": \"<long>\",\n \"document_position_id\": \"<long>\",\n \"stored_at\": \"<string>\",\n \"created_at\": \"<string>\",\n \"updated_at\": \"<string>\"\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/stocks",
"host": [
"{{baseUrl}}"
],
"path": [
"stocks"
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"stock_count\": \"<long>\",\n \"position_id\": \"<long>\",\n \"id\": \"<long>\",\n \"note\": \"<string>\",\n \"document_id\": \"<long>\",\n \"document_position_id\": \"<long>\",\n \"stored_at\": \"<string>\",\n \"created_at\": \"<string>\",\n \"updated_at\": \"<string>\"\n}"
},
{
"name": "Invalid position_id or stock_count",
"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 \"stock_count\": \"<long>\",\n \"position_id\": \"<long>\",\n \"id\": \"<long>\",\n \"note\": \"<string>\",\n \"document_id\": \"<long>\",\n \"document_position_id\": \"<long>\",\n \"stored_at\": \"<string>\",\n \"created_at\": \"<string>\",\n \"updated_at\": \"<string>\"\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/stocks",
"host": [
"{{baseUrl}}"
],
"path": [
"stocks"
]
}
},
"status": "Bad Request",
"code": 400,
"_postman_previewlanguage": "text",
"header": [
],
"cookie": [
],
"body": ""
},
{
"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 \"stock_count\": \"<long>\",\n \"position_id\": \"<long>\",\n \"id\": \"<long>\",\n \"note\": \"<string>\",\n \"document_id\": \"<long>\",\n \"document_position_id\": \"<long>\",\n \"stored_at\": \"<string>\",\n \"created_at\": \"<string>\",\n \"updated_at\": \"<string>\"\n}",
"options": {
"raw": {
"headerFamily": "json",
"language": "json"
}
}
},
"url": {
"raw": "{{baseUrl}}/stocks",
"host": [
"{{baseUrl}}"
],
"path": [
"stocks"
]
}
},
"status": "Too Many Requests",
"code": 429,
"_postman_previewlanguage": "text",
"header": [
],
"cookie": [
],
"body": ""
}
]
}