対象のプラン
- 無料
- ミニマム
- ライト
- フル
対象の端末
- Web
- iPhone
- Android
Curl
# 在庫一覧取得
curl https://web.zaico.co.jp/api/v1/inventories/ -H "Authorization:Bearer ここにトークンを設定" -H "Content-Type:application/json"
# 在庫データ新規作成
curl https://web.zaico.co.jp/api/v1/inventories/ -X POST -H "Authorization:Bearer ここにトークンを設定" -H "Content-Type:application/json" -d '{"title":"エアブロアーAMG315", "quantity": 10, "optional_attributes":[{"name":"仕入単価","value":"300"}]}'
Ruby
require 'net/http'
require 'uri'
require 'json'
# APIの設定
$zaicoapi_token = "YOUR_TOKEN_HERE"
$zaicoapi_url = "https://web.zaico.co.jp/api/v1/inventories/"
# 在庫データ一覧取得
def get_inventories()
uri = URI.parse($zaicoapi_url)
req = Net::HTTP::Get.new(uri)
# TokenとContent-Typeの指定
req['Authorization'] = 'Bearer ' + $zaicoapi_token
req['Content-Type'] = req['Accept'] = 'application/json'
res = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') { |http|
http.request(req)
}
if res.is_a?(Net::HTTPSuccess)
puts "在庫データ一覧"
puts "------------------"
JSON.parse(res.body).each do |inventory|
puts "Inventory ID: " + inventory["id"].to_s
puts "Title: " + inventory["title"]
puts "Quantity: " + inventory["quantity"].to_s
puts "------------------"
end
puts ""
else
abort "call api failed: body=" + res.body
end
end
# 在庫データ新規作成
def create_inventory()
# 作成する在庫データの内容
post_inventory_json = {
title: "いちご",
quantity: 100,
state: "販売中"
}.to_json
uri = URI.parse($zaicoapi_url)
req = Net::HTTP::Post.new(uri)
req['Authorization'] = 'Bearer ' + $zaicoapi_token
req['Content-Type'] = req['Accept'] = 'application/json'
req.body = post_inventory_json
res = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') { |http|
http.request(req)
}
if res.is_a?(Net::HTTPSuccess)
response = JSON.parse(res.body)
puts "在庫データ新規作成"
puts "Status: " + response["status"].to_s
puts "Message: " + response["message"].to_s
puts "data id:" + response["data_id"].to_s
else
abort "call api failed: body=" + res.body
end
end
# 在庫データ更新
def update_inventory()
target_inventory_id = 123456 # 更新したい在庫データのIDを入力してください。
# 更新する項目
update_inventory_json = {
quantity: 10,
state: "販売中"
}.to_json
update_uri = $zaicoapi_url + target_inventory_id
uri = URI.parse(update_uri)
req = Net::HTTP::Put.new(uri)
req['Authorization'] = 'Bearer ' + $zaicoapi_token
req['Content-Type'] = req['Accept'] = 'application/json'
req.body = update_inventory_json
res = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') { |http|
http.request(req)
}
if res.is_a?(Net::HTTPSuccess)
response = JSON.parse(res.body)
puts "在庫データ更新"
puts "Status: " + response["status"].to_s
puts "Message: " + response["message"].to_s
else
abort "call api failed: body=" + res.body
end
end
# 在庫データ削除
def delete_inventory()
target_inventory_id = 123456 # 更新したい在庫データのIDを入力してください。
delete_uri = $zaicoapi_url + target_inventory_id
uri = URI.parse(delete_uri)
req = Net::HTTP::Delete.new(uri)
req['Authorization'] = 'Bearer ' + $zaicoapi_token
req['Content-Type'] = req['Accept'] = 'application/json'
res = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') { |http|
http.request(req)
}
if res.is_a?(Net::HTTPSuccess)
response = JSON.parse(res.body)
puts "在庫データ削除"
puts "Status: " + response["status"].to_s
puts "Message: " + response["message"].to_s
else
abort "call api failed: body=" + res.body
end
end
if __FILE__ == $0
get_inventories()
create_inventory()
# update_inventory()
# delete_inventory()
end
Python
import requests
import json
# APIの設定
zaicoapi_token = "YOUR_TOKEN_HERE"
zaicoapi_url = "https://web.zaico.co.jp/api/v1/inventories/"
headers = {
'Authorization': 'Bearer {}'.format(zaicoapi_token),
'Content-Type': 'application/json'
}
# 在庫データ一覧取得
def get_inventories():
# 在庫データを全部取得
inventories = requests.get(zaicoapi_url, headers=headers)
print(inventories)
print("在庫データ一覧")
print("----------------------")
for data in json.loads(inventories.text):
print("Inventory ID: ", data["id"])
print("Title: ", data["title"])
print("Quantity: ", data["quantity"])
print("")
print("----------------------")
print("")
# 在庫データ新規作成
def create_inventory():
data = {"title": "みかん", "quantity": 10, "state": "販売中"}
json_data = json.dumps(data).encode("UTF-8")
response = requests.post(zaicoapi_url, data=json_data, headers=headers)
print("在庫データ新規作成")
print(response)
# 在庫データ更新
def update_inventory():
target_inventory_id = "123456" # 対象の在庫データのIDを指定してください
data = {"quantity": 100}
json_data = json.dumps(data).encode("UTF-8")
response = requests.put(zaicoapi_url + target_inventory_id, data=json_data, headers=headers)
print(response)
# 在庫データ削除
def delete_inventory():
target_inventory_id = "123456" # 対象の在庫データのIDを指定してください
response = requests.delete(zaicoapi_url + target_inventory_id, headers=headers)
print(response)
if __name__ == '__main__':
get_inventories()
create_inventory()
# update_inventory()
# delete_inventory()
Node.js
'use strict'
// 必要なLibraryをロード
const request = require( 'request' );
// APIの設定
const zaicoapi_token = "YOUR_TOKEN_HERE";
const zaicoapi_url = "https://web.zaico.co.jp/api/v1/inventories/"
main();
// メイン関数
function main() {
get_inventories();
create_inventory();
// update_inventory(id);
// delete_inventory(id);
}
// 在庫データ一覧取得
function get_inventories() {
request( zaicoapi_url, {
// HTTPリクエスト設定
method: "GET",
// HTTPヘッダ設定
headers: {
"Authorization": " Bearer " + zaicoapi_token,
"Content-Type": "application/json"
},
}, function(err, res, body) {
// 在庫データ一覧取得
var inventories_data = JSON.parse(body);
console.log("GET INVENTORIES");
console.log("-------------------------");
// consoleに表示する
inventories_data.forEach(function(inventory_data){
console.log("Inventory ID: " + inventory_data.id);
console.log("Title: " + inventory_data.title);
console.log("Quantity: " + inventory_data.quantity);
console.log("Created at: " + inventory_data.created_at);
console.log("Updated at: " + inventory_data.updated_at);
console.log("-------------------------");
});
});
}
// 在庫データ作成
function create_inventory() {
request( zaicoapi_url, {
method: "POST",
headers: {
"Authorization": " Bearer " + zaicoapi_token,
"Content-Type": "application/json"
},
json: {
"title": "りんご", // 物品名
"quantity": "100", // 個数
"unit": "個" // 単位
},
}, function(err, res, body) {
console.log("CREATE INVENTORY");
console.log(body.status);
console.log(body.message);
});
}
// 在庫データ更新
function update_inventory(id) {
request( zaicoapi_url + id, { // idの部分には操作したい在庫データのIDを指定
method: "PUT",
headers: {
"Authorization": " Bearer " + zaicoapi_token,
"Content-Type": "application/json"
},
json: {
// 更新したい項目を記述する
"quantity": 100
}
}, function(err, res, body) {
console.log("UPDATE INVENTORY");
console.log(body.status);
console.log(body.message);
});
}
// 在庫データ削除
function delete_inventory(id) {
request( zaicoapi_url + id, { // idの部分には削除したい在庫データのIDを指定
method: "DELETE",
headers: {
"Authorization": " Bearer " + zaicoapi_token,
"Content-Type": "application/json"
}
}, function(err, res, body) {
console.log("DELETE INVENTORY");
console.log(body.status);
console.log(body.message);
});
}
.NET C#
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace APITest
{
class Program
{
static void Main(string[] args)
{
var client = new ZaicoApiClient("ここにトークンを設定");
var jsonStr = client.GetInventories().Result;
var result = JsonConvert.DeserializeObject<list>(jsonStr);
foreach(InventoryModel inventory in result)
{
Console.WriteLine($"id: {inventory.InventoryID}, Title: {inventory.Title}");
}
Console.Read();
}
}
public class ZaicoApiClient
{
private const string baseUrl = "https://web.zaico.co.jp/api/v1/inventories/";
private string apiToken;
public ZaicoApiClient(string apiToken)
{
this.apiToken = apiToken;
}
public async Task GetInventories()
{
var request = new HttpRequestMessage(HttpMethod.Get, baseUrl);
request.Headers.Add("ContentType", "application/json");
request.Headers.Add("Authorization", "Bearer " + this.apiToken);
var result = await new HttpClient().SendAsync(request);
var jsonString = await result.Content.ReadAsStringAsync();
return jsonString;
}
}
[JsonObject("inventory")]
public class InventoryModel
{
[JsonProperty("id")]
public int InventoryID { get; set; }
[JsonProperty("title")]
public string Title { get; set; }
}
}
Excel VBA
Excel VBAのサンプルについてはこちらのページをご覧ください。