リクエストの種類
GET,POST
リクエスト方法
どのパラメーターをurlに含めるのか
リクエストヘッダーのパラメーター
json指定やAuthorization,accept
リクエストボディの中身,形式
jsonなのか,encode_formなのか
認証方法
OAuth確認
会計freeeの請求書発行API
def make_invoice
uri = URI.parse(BASE_URL + '/api/1/invoices')
http = Net::HTTP.new(uri.host,uri.port)
http.use_ssl = uri.scheme === "https"
params = INVOICE_PARAMS
headers = MAKE_INVOICE_HEADER
req = Net::HTTP::Post.new(uri.path)
req.body = INVOICE_PARAMS.to_json
req.initialize_http_header(headers)
response = http.request(req)
res_hash = JSON.parse(response.body)
end
ヘッダーとボディをリファレンスで注意深く確認
MAKE_INVOICE_HEADER = {
"accept" => "application/json",
"Authorization"=> "Bearer #{ACCESS_TOKEN}",
"Content-Type" => "application/json"
}
INVOICE_PARAMS = {
"company_id": COMPANY_ID,
"issue_date": Date.today,
"due_date": Date.new(Time.now.year, Time.now.month, -1),
"partner_id": PARTNER_ID,
"booking_date": Date.today,
"description": "#{Date.today.month}月分請求書",
"invoice_status": "draft",
"partner_display_name": "株式会社freeeパートナー",
"partner_title": "御中",
"partner_contact_info": "営業担当",
"partner_zipcode": "012-0009",
"partner_prefecture_code": 4,
"partner_address1": "湯沢市",
"partner_address2": "Aビル",
"company_name": "freee株式会社",
"company_zipcode": "000-0000",
"company_prefecture_code": 12,
"company_address1": "XX区YY1−1−1",
"company_address2": "ビル 1F",
"company_contact_info": "法人営業担当",
"payment_type": "transfer",
"payment_bank_info": "XX銀行YY支店 1111111",
"message": "下記の通りご請求申し上げます。",
"notes": "毎度ありがとうございます",
"invoice_layout": "default_classic",
"tax_entry_method": "exclusive",
"invoice_contents": [
{
"order": 0,
"type": "normal",
"qty": 1,
"unit": "個",
"unit_price": 1,
"vat": 8000,
"description": "備考",
"tax_code": 1,
"account_item_id": ACCOUNT_ITEM_ID
}
]
}
日々精進