Skip to content

Instantly share code, notes, and snippets.

@yokoji
Last active May 15, 2019 09:05
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save yokoji/822edacff497b21fa7bf to your computer and use it in GitHub Desktop.
Save yokoji/822edacff497b21fa7bf to your computer and use it in GitHub Desktop.
freee API v1.0

freee API v1.0

全自動クラウド会計ソフトfreeeの開発者向けAPIのドキュメントです。

概要

本APIを利用することで、あなたのアプリやサービスをfreeeと連携させることができます。

提供機能(2013/10/10現在)

  • ユーザ情報の取得
  • 事業所情報の取得
  • 取引(収入・支出・振替)の照会/登録
  • 口座明細の照会/登録
  • 取引先の照会/登録
  • 品目の照会/登録
  • 勘定科目の照会
  • 税区分の照会
  • 口座情報の照会

仕様

APIエンドポイント

https://api.freee.co.jp/ (httpsのみ)

認証

OAuth2に対応

  • Authorization Code Flow (Webアプリ向け)
  • Implicit Flow (Mobileアプリ向け)

エンドポイント

https://secure.freee.co.jp/ (httpsのみ)

  • authorize : /oauth/authorize
  • token : /oauth/token

データフォーマット

リクエスト、レスポンスともにJSON形式をサポート

はじめに

  1. freeeにサインアップします。
  2. アプリケーション一覧から「新しいアプリケーションを登録」します。
  3. アプリケーションの登録が完了すると、AppIDとSecretが取得できます。
  4. ローカルの開発環境でテストする際は、認証用URLを直打ちしてAuthorization Codeを取得できます。

APIリファレンス

https://secure.freee.co.jp/developers/api/doc

サンプル実装 (Ruby)

Authorization Code Flowでユーザ情報、事業所情報を取得するまでの実装例です。

  • 使用する外部ライブラリ
  • oauth2
  • faraday
  • faraday_middleware

注意点

  • 本機能は現在β版として運用しており、予告なく新規APIが追加されることがありますのでご了承ください。

  • APIのパラメータ等が変更になる場合は、バージョンを更新して提供いたします。

連絡先

ご不明点、ご要望等は以下までご連絡ください。

dev-support@freee.co.jp

require 'oauth2'
require 'faraday'
require 'faraday_middleware'
# Initialize
options = {
site: 'https://api.freee.co.jp',
authorize_url: '/oauth/authorize',
token_url: '/oauth/token'
}
client = OAuth2::Client.new(YOUR_APP_ID, YOUR_SECRET, options) do |conn|
conn.request :url_encoded
conn.request :json
conn.response :json, content_type: /\bjson$/
conn.adapter Faraday.default_adapter
end
# Getting authorized
params = {
grant_type: 'authorization_code',
code: AUTHORIZATION_CODE,
redirect_uri: YOUR_REDIRECT_URI,
headers: {
'Content-Type' => 'application/json',
'Authorization' => HTTPAuth::Basic.pack_authorization(YOUR_APP_ID, YOUR_SECRET)
}
}
token = client.get_token(params).token
access_token = OAuth2::AccessToken.new(client, token)
# GET /api/1/users/me
access_token.get('/api/1/users/me?companies=true').response.env[:body]
# {
# "user" =>
# {
# "email" => "freee@freee.co.jp",
# "display_name" => "freee太郎,
# "first_name" => "太郎",
# "last_name" => "freee",
# "first_name_kana" => "たろう",
# "last_name_kana"=> "ふりー"
# "companies" =>
# {
# "id" => "12345",
# "display_name" => "freee株式会社",
# "role" => "default"
# }
# }
# }
# GET /api/1/companies/:id
access_token.get('/api/1/companies/12345?details=true').response.env[:body]
# {
# "company" =>
# {
# "id" => 12345,
# "name" => "freee株式会社,
# "name_kana" => "ふりーかぶしきがいしゃ",
# "display_name"=> "freeeカブシキガイシャ",
# "role" => "default",
# "account_items" => {...},
# "taxes" => {...},
# "items" => {...},
# "partners" => {...}
# }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment