本稿で学べること
- Yahoo!注文検索APIをhttpieでたたく方法と、そのために最低限必要なオプションの指定。
前提条件
- httpieがインストール済み。
- アクセストークンが取得済み。
- ストアアカウントのIDが分かる。
# !/bin/bash
set -eu
ACCESS_TOKEN="ここにアクセストークンを書く"
URL="https://test.circus.shopping.yahooapis.jp/ShoppingWebService/V1/orderList"
AUTH_HEADER="Authorization: Bearer ${ACCESS_TOKEN}"
echo -n '<?xml version="1.0" encoding="UTF-8" ?>
<Req>
<Search>
<Condition>
<OrderTimeFrom>20190101000000</OrderTimeFrom>
</Condition>
<Field>OrderId,Version</Field>
</Search>
<SellerId>ここにストアアカウントIDを書く</SellerId>
</Req>' | http -v POST ${URL} 'Content-Type: application/xml' "${AUTH_HEADER}"
実行結果の例
POST /ShoppingWebService/V1/orderList HTTP/1.1
Accept: application/json, */*
Accept-Encoding: gzip, deflate
Authorization: Bearer [[...中略...]]
Connection: keep-alive
Content-Length: 241
Content-Type: application/xml
Host: test.circus.shopping.yahooapis.jp
User-Agent: HTTPie/1.0.2
<?xml version="1.0" encoding="UTF-8" ?>
<Req>
<Search>
<Condition>
<OrderTimeFrom>20190101000000</OrderTimeFrom>
</Condition>
<Field>OrderId,Version</Field>
</Search>
<SellerId>***-*******</SellerId>
</Req>
HTTP/1.1 200 OK
Age: 0
Connection: keep-alive
Content-Encoding: gzip
Content-Length: 181
Content-Type: application/xml; charset=UTF-8
Date: Tue, 07 May 2019 09:14:02 GMT
P3P: policyref="http://privacy.yahoo.co.jp/w3c/p3p_jp.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV"
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
<?xml version="1.0" encoding="UTF-8" ?><Result><Status>OK</Status><Search><TotalCount>2</TotalCount><OrderInfo><OrderId>snbx-******-10000001</OrderId><Version>1</Version><Index>1</Index></OrderInfo><OrderInfo><OrderId>snbx-******-10000002</OrderId><Version>1</Version><Index>2</Index></OrderInfo></Search></Result>