freee/apis/
invoices_api.rs

1/*
2 * freee API
3 *
4 *  <h1 id=\"freee_api\">freee API</h1> <hr /> <h2 id=\"start_guide\">スタートガイド</h2>  <p>freee API開発がはじめての方は<a href=\"https://developer.freee.co.jp/getting-started\">freee API スタートガイド</a>を参照してください。</p>  <hr /> <h2 id=\"specification\">仕様</h2>  <h3 id=\"api_endpoint\">APIエンドポイント</h3>  <p>https://api.freee.co.jp/ (httpsのみ)</p>  <h3 id=\"about_authorize\">認証について</h3> <p>OAuth2.0を利用します。<a href=\"https://developer.freee.co.jp/reference/#%e8%aa%8d%e8%a8%bc\" target=\"_blank\">詳細はリファレンスの認証に関する記載を参照してください。</a></p>  <h3 id=\"data_format\">データフォーマット</h3>  <p>リクエスト、レスポンスともにJSON形式をサポートしていますが、詳細は、API毎の説明欄(application/jsonなど)を確認してください。</p>  <h3 id=\"compatibility\">後方互換性ありの変更</h3>  <p>freeeでは、APIを改善していくために以下のような変更は後方互換性ありとして通知なく変更を入れることがあります。アプリケーション実装者は以下を踏まえて開発を行ってください。</p>  <ul> <li>新しいAPIリソース・エンドポイントの追加</li> <li>既存のAPIに対して必須ではない新しいリクエストパラメータの追加</li> <li>既存のAPIレスポンスに対する新しいプロパティの追加</li> <li>既存のAPIレスポンスに対するプロパティの順番の入れ変え</li> <li>keyとなっているidやcodeの長さの変更(長くする)</li> </ul>  <h3 id=\"common_response_header\">共通レスポンスヘッダー</h3>  <p>すべてのAPIのレスポンスには以下のHTTPヘッダーが含まれます。</p>  <ul> <li> <p>X-Freee-Request-ID</p> <ul> <li>各リクエスト毎に発行されるID</li> </ul> </li> </ul>  <h3 id=\"common_error_response\">共通エラーレスポンス</h3>  <ul> <li> <p>ステータスコードはレスポンス内のJSONに含まれる他、HTTPヘッダにも含まれる</p> </li> <li> <p>一部のエラーレスポンスにはエラーコードが含まれます。<br>詳細は、<a href=\"https://developer.freee.co.jp/tips/faq/40x-checkpoint\">HTTPステータスコード400台エラー時のチェックポイント</a>を参照してください</p> </li> <p>type</p>  <ul> <li>status : HTTPステータスコードの説明</li>  <li>validation : エラーの詳細の説明(開発者向け)</li> </ul> </li> </ul>  <p>レスポンスの例</p>  <pre><code>  {     &quot;status_code&quot; : 400,     &quot;errors&quot; : [       {         &quot;type&quot; : &quot;status&quot;,         &quot;messages&quot; : [&quot;不正なリクエストです。&quot;]       },       {         &quot;type&quot; : &quot;validation&quot;,         &quot;messages&quot; : [&quot;Date は不正な日付フォーマットです。入力例:2019-12-17&quot;]       }     ]   }</code></pre>  </br>  <h3 id=\"api_rate_limit\">API使用制限</h3>    <p>freeeは一定期間に過度のアクセスを検知した場合、APIアクセスをコントロールする場合があります。</p>   <p>その際のhttp status codeは403となります。制限がかかってから10分程度が過ぎると再度使用することができるようになります。</p>  <h4 id=\"reports_api_endpoint\">/reportsと/receipts/{id}/downloadエンドポイント</h4>  <p>freeeはエンドポイント毎に一定頻度以上のアクセスを検知した場合、APIアクセスをコントロールする場合があります。その際のhttp status codeは429(too many requests)となります。</p> <ul>   <li>/reports:1秒に10回まで</li>   <li>/receipts/{id}/download:1秒に3回まで</li> </ul>  <p>http status codeが429となった場合、API使用ステータスはレスポンスヘッダに付与されます。</p> <pre><code>x-ratelimit-limit:10 x-ratelimit-remaining:1 x-ratelimit-reset:2023-01-13T10:22:29+09:00 </code></pre>  <br> 各ヘッダの意味は次のとおりです。</p>  <table border=\"1\">   <tbody>     <tr>       <th style=\"padding: 10px\"><strong>ヘッダ名</strong></th>       <th style=\"padding: 10px\"><strong>説明</strong></th>     </tr>     <tr><td style=\"padding: 10px\">x-ratelimit-limit</td><td style=\"padding: 10px\">使用回数の上限</td></tr>     <tr><td style=\"padding: 10px\">x-ratelimit-remaining</td><td style=\"padding: 10px\">残り使用回数</td></tr>     <tr><td style=\"padding: 10px\">x-ratelimit-reset</td><td style=\"padding: 10px\">使用回数がリセットされる時刻</td></tr>   </tbody> </table>  </br>  <h3 id=\"plan_api_rate_limit\">プラン別のAPI Rate Limit</h3>   <table border=\"1\">     <tbody>       <tr>         <th style=\"padding: 10px\"><strong>freee会計プラン名</strong></th>         <th style=\"padding: 10px\"><strong>事業所とアプリケーション毎に1日でのAPIコール数</strong></th>       </tr>       <tr>         <td style=\"padding: 10px\">エンタープライズ</td>         <td style=\"padding: 10px\">10,000</td>       </tr>       <tr>         <td style=\"padding: 10px\">プロフェッショナル</td>         <td style=\"padding: 10px\">5,000</td>       </tr>       <tr>         <td style=\"padding: 10px\">ベーシック</td>         <td style=\"padding: 10px\">3,000</td>       </tr>       <tr>         <td style=\"padding: 10px\">ミニマム</td>         <td style=\"padding: 10px\">3,000</td>       </tr>       <tr>         <td style=\"padding: 10px\">上記以外</td>         <td style=\"padding: 10px\">3,000</td>       </tr>     </tbody>   </table>  <h3 id=\"webhook\">Webhookについて</h3>  <p>詳細は<a href=\"https://developer.freee.co.jp/docs/accounting/webhook\" target=\"_blank\">会計Webhook概要</a>を参照してください。</p>  <hr /> <h2 id=\"contact\">連絡先</h2>  <p>ご不明点、ご要望等は <a href=\"https://support.freee.co.jp/hc/ja/requests/new\">freee サポートデスクへのお問い合わせフォーム</a> からご連絡ください。</p> <hr />&copy; Since 2013 freee K.K.
5 *
6 * The version of the OpenAPI document: v1.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`create_invoice`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateInvoiceError {
22    Status400(crate::models::BadRequestError),
23    Status401(crate::models::UnauthorizedError),
24    Status403(crate::models::ForbiddenError),
25    Status404(crate::models::BadRequestNotFoundError),
26    Status500(crate::models::InternalServerError),
27    UnknownValue(serde_json::Value),
28}
29
30/// struct for typed errors of method [`destroy_invoice`]
31#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum DestroyInvoiceError {
34    Status400(crate::models::BadRequestError),
35    Status401(crate::models::UnauthorizedError),
36    Status403(crate::models::ForbiddenError),
37    Status404(crate::models::BadRequestNotFoundError),
38    Status500(crate::models::InternalServerError),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`get_invoice`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetInvoiceError {
46    Status400(crate::models::BadRequestError),
47    Status401(crate::models::UnauthorizedError),
48    Status403(crate::models::ForbiddenError),
49    Status404(crate::models::BadRequestNotFoundError),
50    Status500(crate::models::InternalServerError),
51    UnknownValue(serde_json::Value),
52}
53
54/// struct for typed errors of method [`get_invoices`]
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum GetInvoicesError {
58    Status400(crate::models::BadRequestError),
59    Status401(crate::models::UnauthorizedError),
60    Status403(crate::models::ForbiddenError),
61    Status404(crate::models::BadRequestNotFoundError),
62    Status500(crate::models::InternalServerError),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`update_invoice`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum UpdateInvoiceError {
70    Status400(crate::models::BadRequestError),
71    Status401(crate::models::UnauthorizedError),
72    Status403(crate::models::ForbiddenError),
73    Status404(crate::models::BadRequestNotFoundError),
74    Status500(crate::models::InternalServerError),
75    UnknownValue(serde_json::Value),
76}
77
78
79///  <h2 id=\"\">概要</h2>  <p>指定した事業所の請求書を作成する</p>  <h2 id=\"_1\">注意点</h2> <ul> <li> <p>partner_code, partner_idはどちらかの指定が必須です。ただし両方同時に指定することはできません。</p> </li> <li> <p>請求書ステータス(invoice_status)を発行(issue)で利用した場合、請求内容の合計金額が0円以上になる必要があります。</p> </li> <li> <p>partner_codeを利用するには、事業所の設定から取引先コードの利用を有効にする必要があります。</p> </li> <li> <p>本APIでは請求内容(invoice_contents)は、最大100行までになります。</p> </li> </ul>
80pub async fn create_invoice(configuration: &configuration::Configuration, invoice_create_params: Option<crate::models::InvoiceCreateParams>) -> Result<crate::models::InvoiceResponse, Error<CreateInvoiceError>> {
81    let local_var_configuration = configuration;
82
83    let local_var_client = &local_var_configuration.client;
84
85    let local_var_uri_str = format!("{}/api/1/invoices", local_var_configuration.base_path);
86    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
87
88    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
89        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
90    }
91    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
92        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
93    };
94    local_var_req_builder = local_var_req_builder.json(&invoice_create_params);
95
96    let local_var_req = local_var_req_builder.build()?;
97    let local_var_resp = local_var_client.execute(local_var_req).await?;
98
99    let local_var_status = local_var_resp.status();
100    let local_var_content = local_var_resp.text().await?;
101
102    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
103        serde_json::from_str(&local_var_content).map_err(Error::from)
104    } else {
105        let local_var_entity: Option<CreateInvoiceError> = serde_json::from_str(&local_var_content).ok();
106        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
107        Err(Error::ResponseError(local_var_error))
108    }
109}
110
111///  <h2 id=\"\">概要</h2>  <p>指定した事業所の請求書を削除する</p>
112pub async fn destroy_invoice(configuration: &configuration::Configuration, id: i32, company_id: i32) -> Result<(), Error<DestroyInvoiceError>> {
113    let local_var_configuration = configuration;
114
115    let local_var_client = &local_var_configuration.client;
116
117    let local_var_uri_str = format!("{}/api/1/invoices/{id}", local_var_configuration.base_path, id=id);
118    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
119
120    local_var_req_builder = local_var_req_builder.query(&[("company_id", &company_id.to_string())]);
121    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
122        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
123    }
124    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
125        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
126    };
127
128    let local_var_req = local_var_req_builder.build()?;
129    let local_var_resp = local_var_client.execute(local_var_req).await?;
130
131    let local_var_status = local_var_resp.status();
132    let local_var_content = local_var_resp.text().await?;
133
134    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
135        Ok(())
136    } else {
137        let local_var_entity: Option<DestroyInvoiceError> = serde_json::from_str(&local_var_content).ok();
138        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
139        Err(Error::ResponseError(local_var_error))
140    }
141}
142
143///  <h2 id=\"\">概要</h2>  <p>指定した事業所の請求書を取得する</p>
144pub async fn get_invoice(configuration: &configuration::Configuration, company_id: i32, id: i32) -> Result<crate::models::InvoiceResponse, Error<GetInvoiceError>> {
145    let local_var_configuration = configuration;
146
147    let local_var_client = &local_var_configuration.client;
148
149    let local_var_uri_str = format!("{}/api/1/invoices/{id}", local_var_configuration.base_path, id=id);
150    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
151
152    local_var_req_builder = local_var_req_builder.query(&[("company_id", &company_id.to_string())]);
153    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
154        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
155    }
156    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
157        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
158    };
159
160    let local_var_req = local_var_req_builder.build()?;
161    let local_var_resp = local_var_client.execute(local_var_req).await?;
162
163    let local_var_status = local_var_resp.status();
164    let local_var_content = local_var_resp.text().await?;
165
166    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
167        serde_json::from_str(&local_var_content).map_err(Error::from)
168    } else {
169        let local_var_entity: Option<GetInvoiceError> = serde_json::from_str(&local_var_content).ok();
170        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
171        Err(Error::ResponseError(local_var_error))
172    }
173}
174
175///  <h2 id=\"\">概要</h2>  <p>指定した事業所の請求書一覧を取得する</p> 
176pub async fn get_invoices(configuration: &configuration::Configuration, company_id: i32, partner_id: Option<i32>, partner_code: Option<&str>, start_issue_date: Option<&str>, end_issue_date: Option<&str>, start_due_date: Option<&str>, end_due_date: Option<&str>, invoice_number: Option<&str>, description: Option<&str>, invoice_status: Option<&str>, payment_status: Option<&str>, offset: Option<i64>, limit: Option<i32>) -> Result<crate::models::InvoiceIndexResponse, Error<GetInvoicesError>> {
177    let local_var_configuration = configuration;
178
179    let local_var_client = &local_var_configuration.client;
180
181    let local_var_uri_str = format!("{}/api/1/invoices", local_var_configuration.base_path);
182    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
183
184    local_var_req_builder = local_var_req_builder.query(&[("company_id", &company_id.to_string())]);
185    if let Some(ref local_var_str) = partner_id {
186        local_var_req_builder = local_var_req_builder.query(&[("partner_id", &local_var_str.to_string())]);
187    }
188    if let Some(ref local_var_str) = partner_code {
189        local_var_req_builder = local_var_req_builder.query(&[("partner_code", &local_var_str.to_string())]);
190    }
191    if let Some(ref local_var_str) = start_issue_date {
192        local_var_req_builder = local_var_req_builder.query(&[("start_issue_date", &local_var_str.to_string())]);
193    }
194    if let Some(ref local_var_str) = end_issue_date {
195        local_var_req_builder = local_var_req_builder.query(&[("end_issue_date", &local_var_str.to_string())]);
196    }
197    if let Some(ref local_var_str) = start_due_date {
198        local_var_req_builder = local_var_req_builder.query(&[("start_due_date", &local_var_str.to_string())]);
199    }
200    if let Some(ref local_var_str) = end_due_date {
201        local_var_req_builder = local_var_req_builder.query(&[("end_due_date", &local_var_str.to_string())]);
202    }
203    if let Some(ref local_var_str) = invoice_number {
204        local_var_req_builder = local_var_req_builder.query(&[("invoice_number", &local_var_str.to_string())]);
205    }
206    if let Some(ref local_var_str) = description {
207        local_var_req_builder = local_var_req_builder.query(&[("description", &local_var_str.to_string())]);
208    }
209    if let Some(ref local_var_str) = invoice_status {
210        local_var_req_builder = local_var_req_builder.query(&[("invoice_status", &local_var_str.to_string())]);
211    }
212    if let Some(ref local_var_str) = payment_status {
213        local_var_req_builder = local_var_req_builder.query(&[("payment_status", &local_var_str.to_string())]);
214    }
215    if let Some(ref local_var_str) = offset {
216        local_var_req_builder = local_var_req_builder.query(&[("offset", &local_var_str.to_string())]);
217    }
218    if let Some(ref local_var_str) = limit {
219        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
220    }
221    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
222        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
223    }
224    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
225        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
226    };
227
228    let local_var_req = local_var_req_builder.build()?;
229    let local_var_resp = local_var_client.execute(local_var_req).await?;
230
231    let local_var_status = local_var_resp.status();
232    let local_var_content = local_var_resp.text().await?;
233
234    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
235        serde_json::from_str(&local_var_content).map_err(Error::from)
236    } else {
237        let local_var_entity: Option<GetInvoicesError> = serde_json::from_str(&local_var_content).ok();
238        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
239        Err(Error::ResponseError(local_var_error))
240    }
241}
242
243///  <h2 id=\"\">概要</h2>  <p>指定した事業所の請求書を更新する</p>  <h2 id=\"_1\">注意点</h2> <ul> <li> <p>入金済みの請求書に対する金額関連の変更はできません。</p> </li> <li> <p>請求書ステータスは確定(issue)のみ指定可能です。請求書ステータスを確定する時のみ指定してください。</p> </li> <li> <p>請求書WFを利用している場合、承認済み請求書は承認権限を持たないユーザーでは更新できません。</p> </li> <li> <p>更新後の請求書ステータス(invoice_status)が下書き以外の場合、請求内容の合計金額が0円以上になる必要があります。</p> </li> <li> <p>partner_code, partner_idを両方同時に指定することはできません。</p> </li> <li> <p>partner_codeを利用するには、事業所の設定から取引先コードの利用を有効にする必要があります。</p> </li> <li> <p>本APIでは請求内容(invoice_contents)は、最大100行までになります。</p> </li> </ul>
244pub async fn update_invoice(configuration: &configuration::Configuration, id: i32, invoice_update_params: Option<crate::models::InvoiceUpdateParams>) -> Result<crate::models::InvoiceResponse, Error<UpdateInvoiceError>> {
245    let local_var_configuration = configuration;
246
247    let local_var_client = &local_var_configuration.client;
248
249    let local_var_uri_str = format!("{}/api/1/invoices/{id}", local_var_configuration.base_path, id=id);
250    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
251
252    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
253        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
254    }
255    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
256        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
257    };
258    local_var_req_builder = local_var_req_builder.json(&invoice_update_params);
259
260    let local_var_req = local_var_req_builder.build()?;
261    let local_var_resp = local_var_client.execute(local_var_req).await?;
262
263    let local_var_status = local_var_resp.status();
264    let local_var_content = local_var_resp.text().await?;
265
266    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
267        serde_json::from_str(&local_var_content).map_err(Error::from)
268    } else {
269        let local_var_entity: Option<UpdateInvoiceError> = serde_json::from_str(&local_var_content).ok();
270        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
271        Err(Error::ResponseError(local_var_error))
272    }
273}
274