例「バーコードで物品管理」で作成した「バーコード指定でデータ取得」をするエンドポイントに対してPerlからアクセスします。
エンドポイントのページにサンプルコードがありますのでそれを使用します。
use LWP::UserAgent; <ここからテンプレートを使用> use JSON; my $url = 'https://dbaassandbox.matsuesoft.co.jp/?????/proxyserver-AssetInfo-GetSpecificAssetByBarcode.php'; my $json = { "TOKEN"=> "?????????", "param_AssetInfo_Barcode_where"=> "9784845623556" ← 取得したいバーコードの値を設定 }; my $req = HTTP::Request->new('POST', $url); $req->header('Content-Type' => 'application/json'); $req->content(encode_json $json); my $ua = LWP::UserAgent->new; my $response = $ua->request($req); if ($response->is_success) {
my $json_response = JSON->new()->decode($response->content);
if ($json_response->{_status} eq "OK") { # Success. Result is in: $json_response->{Result} <ここまでテンプレートを使用> ↓ここを追加 if ($json_response->{Result}) {
print "Result - Item Name: " . $json_response->{Result}->{ItemName} . "\n"; ← 取得結果を表示
print "Result - Description: " . $json_response->{Result}->{Description} . "\n"; ← 取得結果を表示
print "Result - Barcode: " . $json_response->{Result}->{Barcode} . "\n"; ← 取得結果を表示
} else {
print "No Item matched\n";
}
↑ここまで追加 } else { <ここからテンプレートを使用>
print "Error! Result: " . $json_response->{_status} . " : " . $json_response->{Message} . "\n";
}
} <ここまでテンプレートを使用>
実行しますと以下のように表示されます。
Result - Item Name: DEF Travel Book Result - Description: This is DEF... Result - Barcode: 9784845623556
※PerlのJSONモジュールが必要です。
弊社の開発フレームワークおよびクラウド・データベースです
© 2016-2023 Matsuesoft Corporation