freee/apis/
receipts_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_receipt`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateReceiptError {
22    Status400(crate::models::BadRequestError),
23    Status401(crate::models::UnauthorizedError),
24    Status403(crate::models::ForbiddenError),
25    Status500(crate::models::InternalServerError),
26    UnknownValue(serde_json::Value),
27}
28
29/// struct for typed errors of method [`destroy_receipt`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum DestroyReceiptError {
33    Status400(crate::models::BadRequestError),
34    Status401(crate::models::UnauthorizedError),
35    Status403(crate::models::ForbiddenError),
36    Status404(crate::models::BadRequestNotFoundError),
37    Status500(crate::models::InternalServerError),
38    UnknownValue(serde_json::Value),
39}
40
41/// struct for typed errors of method [`download_receipt`]
42#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(untagged)]
44pub enum DownloadReceiptError {
45    Status400(crate::models::BadRequestError),
46    Status401(crate::models::UnauthorizedError),
47    Status403(crate::models::ForbiddenError),
48    Status404(crate::models::BadRequestNotFoundError),
49    Status500(crate::models::InternalServerError),
50    UnknownValue(serde_json::Value),
51}
52
53/// struct for typed errors of method [`get_receipt`]
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(untagged)]
56pub enum GetReceiptError {
57    Status400(crate::models::BadRequestError),
58    Status401(crate::models::UnauthorizedError),
59    Status403(crate::models::ForbiddenError),
60    Status404(crate::models::BadRequestNotFoundError),
61    Status500(crate::models::InternalServerError),
62    UnknownValue(serde_json::Value),
63}
64
65/// struct for typed errors of method [`get_receipts`]
66#[derive(Debug, Clone, Serialize, Deserialize)]
67#[serde(untagged)]
68pub enum GetReceiptsError {
69    Status400(crate::models::BadRequestError),
70    Status401(crate::models::UnauthorizedError),
71    Status403(crate::models::ForbiddenError),
72    Status500(crate::models::InternalServerError),
73    UnknownValue(serde_json::Value),
74}
75
76/// struct for typed errors of method [`update_receipt`]
77#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum UpdateReceiptError {
80    Status400(crate::models::BadRequestError),
81    Status401(crate::models::UnauthorizedError),
82    Status403(crate::models::ForbiddenError),
83    Status404(crate::models::BadRequestNotFoundError),
84    Status500(crate::models::InternalServerError),
85    UnknownValue(serde_json::Value),
86}
87
88
89///  <h2 id=\"\">概要</h2>  <p>ファイルボックス(証憑ファイル)をアップロードする</p> <h2 id=\"_2\">注意点</h2> <ul>   <li>リクエストヘッダーの Content-Type は、multipart/form-dataにのみ対応しています。</li> </ul>
90pub async fn create_receipt(configuration: &configuration::Configuration, company_id: i32, receipt: std::path::PathBuf, description: Option<&str>, issue_date: Option<&str>, receipt_metadatum_partner_name: Option<&str>, receipt_metadatum_issue_date: Option<&str>, receipt_metadatum_amount: Option<i64>, qualified_invoice: Option<&str>, document_type: Option<&str>) -> Result<crate::models::ReceiptResponse, Error<CreateReceiptError>> {
91    let local_var_configuration = configuration;
92
93    let local_var_client = &local_var_configuration.client;
94
95    let local_var_uri_str = format!("{}/api/1/receipts", local_var_configuration.base_path);
96    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
97
98    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
99        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
100    }
101    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
102        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
103    };
104    let mut local_var_form = reqwest::multipart::Form::new();
105    local_var_form = local_var_form.text("company_id", company_id.to_string());
106    if let Some(local_var_param_value) = description {
107        local_var_form = local_var_form.text("description", local_var_param_value.to_string());
108    }
109    if let Some(local_var_param_value) = issue_date {
110        local_var_form = local_var_form.text("issue_date", local_var_param_value.to_string());
111    }
112    // TODO: support file upload for 'receipt' parameter
113    if let Some(local_var_param_value) = receipt_metadatum_partner_name {
114        local_var_form = local_var_form.text("receipt_metadatum_partner_name", local_var_param_value.to_string());
115    }
116    if let Some(local_var_param_value) = receipt_metadatum_issue_date {
117        local_var_form = local_var_form.text("receipt_metadatum_issue_date", local_var_param_value.to_string());
118    }
119    if let Some(local_var_param_value) = receipt_metadatum_amount {
120        local_var_form = local_var_form.text("receipt_metadatum_amount", local_var_param_value.to_string());
121    }
122    if let Some(local_var_param_value) = qualified_invoice {
123        local_var_form = local_var_form.text("qualified_invoice", local_var_param_value.to_string());
124    }
125    if let Some(local_var_param_value) = document_type {
126        local_var_form = local_var_form.text("document_type", local_var_param_value.to_string());
127    }
128    local_var_req_builder = local_var_req_builder.multipart(local_var_form);
129
130    let local_var_req = local_var_req_builder.build()?;
131    let local_var_resp = local_var_client.execute(local_var_req).await?;
132
133    let local_var_status = local_var_resp.status();
134    let local_var_content = local_var_resp.text().await?;
135
136    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
137        serde_json::from_str(&local_var_content).map_err(Error::from)
138    } else {
139        let local_var_entity: Option<CreateReceiptError> = serde_json::from_str(&local_var_content).ok();
140        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
141        Err(Error::ResponseError(local_var_error))
142    }
143}
144
145///  <h2 id=\"\">概要</h2>  <p>ファイルボックス(証憑ファイル)を削除する</p>
146pub async fn destroy_receipt(configuration: &configuration::Configuration, id: i32, company_id: i32) -> Result<(), Error<DestroyReceiptError>> {
147    let local_var_configuration = configuration;
148
149    let local_var_client = &local_var_configuration.client;
150
151    let local_var_uri_str = format!("{}/api/1/receipts/{id}", local_var_configuration.base_path, id=id);
152    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
153
154    local_var_req_builder = local_var_req_builder.query(&[("company_id", &company_id.to_string())]);
155    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
156        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
157    }
158    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
159        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
160    };
161
162    let local_var_req = local_var_req_builder.build()?;
163    let local_var_resp = local_var_client.execute(local_var_req).await?;
164
165    let local_var_status = local_var_resp.status();
166    let local_var_content = local_var_resp.text().await?;
167
168    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
169        Ok(())
170    } else {
171        let local_var_entity: Option<DestroyReceiptError> = serde_json::from_str(&local_var_content).ok();
172        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
173        Err(Error::ResponseError(local_var_error))
174    }
175}
176
177///  <h2 id=\"\">概要</h2>  <p>指定した事業所のファイルボックス(証憑ファイル)をダウンロードする</p>
178pub async fn download_receipt(configuration: &configuration::Configuration, id: i32, company_id: i32) -> Result<String, Error<DownloadReceiptError>> {
179    let local_var_configuration = configuration;
180
181    let local_var_client = &local_var_configuration.client;
182
183    let local_var_uri_str = format!("{}/api/1/receipts/{id}/download", local_var_configuration.base_path, id=id);
184    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
185
186    local_var_req_builder = local_var_req_builder.query(&[("company_id", &company_id.to_string())]);
187    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
188        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
189    }
190    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
191        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
192    };
193
194    let local_var_req = local_var_req_builder.build()?;
195    let local_var_resp = local_var_client.execute(local_var_req).await?;
196
197    let local_var_status = local_var_resp.status();
198    let local_var_content = local_var_resp.text().await?;
199
200    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
201        serde_json::from_str(&local_var_content).map_err(Error::from)
202    } else {
203        let local_var_entity: Option<DownloadReceiptError> = serde_json::from_str(&local_var_content).ok();
204        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
205        Err(Error::ResponseError(local_var_error))
206    }
207}
208
209///  <h2 id=\"\">概要</h2>  <p>指定した事業所のファイルボックス(証憑ファイル)を取得する</p>
210pub async fn get_receipt(configuration: &configuration::Configuration, id: i32, company_id: i32) -> Result<crate::models::ReceiptResponse, Error<GetReceiptError>> {
211    let local_var_configuration = configuration;
212
213    let local_var_client = &local_var_configuration.client;
214
215    let local_var_uri_str = format!("{}/api/1/receipts/{id}", local_var_configuration.base_path, id=id);
216    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
217
218    local_var_req_builder = local_var_req_builder.query(&[("company_id", &company_id.to_string())]);
219    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
220        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
221    }
222    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
223        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
224    };
225
226    let local_var_req = local_var_req_builder.build()?;
227    let local_var_resp = local_var_client.execute(local_var_req).await?;
228
229    let local_var_status = local_var_resp.status();
230    let local_var_content = local_var_resp.text().await?;
231
232    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
233        serde_json::from_str(&local_var_content).map_err(Error::from)
234    } else {
235        let local_var_entity: Option<GetReceiptError> = serde_json::from_str(&local_var_content).ok();
236        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
237        Err(Error::ResponseError(local_var_error))
238    }
239}
240
241///  <h2 id=\"\">概要</h2>  <p>指定した事業所のファイルボックス(証憑ファイル)一覧を取得する</p>
242pub async fn get_receipts(configuration: &configuration::Configuration, company_id: i32, start_date: &str, end_date: &str, user_name: Option<&str>, number: Option<i32>, comment_type: Option<&str>, comment_important: Option<bool>, category: Option<&str>, offset: Option<i64>, limit: Option<i32>) -> Result<crate::models::GetReceipts200Response, Error<GetReceiptsError>> {
243    let local_var_configuration = configuration;
244
245    let local_var_client = &local_var_configuration.client;
246
247    let local_var_uri_str = format!("{}/api/1/receipts", local_var_configuration.base_path);
248    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
249
250    local_var_req_builder = local_var_req_builder.query(&[("company_id", &company_id.to_string())]);
251    local_var_req_builder = local_var_req_builder.query(&[("start_date", &start_date.to_string())]);
252    local_var_req_builder = local_var_req_builder.query(&[("end_date", &end_date.to_string())]);
253    if let Some(ref local_var_str) = user_name {
254        local_var_req_builder = local_var_req_builder.query(&[("user_name", &local_var_str.to_string())]);
255    }
256    if let Some(ref local_var_str) = number {
257        local_var_req_builder = local_var_req_builder.query(&[("number", &local_var_str.to_string())]);
258    }
259    if let Some(ref local_var_str) = comment_type {
260        local_var_req_builder = local_var_req_builder.query(&[("comment_type", &local_var_str.to_string())]);
261    }
262    if let Some(ref local_var_str) = comment_important {
263        local_var_req_builder = local_var_req_builder.query(&[("comment_important", &local_var_str.to_string())]);
264    }
265    if let Some(ref local_var_str) = category {
266        local_var_req_builder = local_var_req_builder.query(&[("category", &local_var_str.to_string())]);
267    }
268    if let Some(ref local_var_str) = offset {
269        local_var_req_builder = local_var_req_builder.query(&[("offset", &local_var_str.to_string())]);
270    }
271    if let Some(ref local_var_str) = limit {
272        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
273    }
274    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
275        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
276    }
277    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
278        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
279    };
280
281    let local_var_req = local_var_req_builder.build()?;
282    let local_var_resp = local_var_client.execute(local_var_req).await?;
283
284    let local_var_status = local_var_resp.status();
285    let local_var_content = local_var_resp.text().await?;
286
287    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
288        serde_json::from_str(&local_var_content).map_err(Error::from)
289    } else {
290        let local_var_entity: Option<GetReceiptsError> = serde_json::from_str(&local_var_content).ok();
291        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
292        Err(Error::ResponseError(local_var_error))
293    }
294}
295
296///  <h2 id=\"\">概要</h2>  <p>ファイルボックス(証憑ファイル)を更新する</p> <h2 id=\"_2\">注意点</h2> <ul>   <li>本APIでは、証憑ファイルの再アップロードはできません。</li> </ul>
297pub async fn update_receipt(configuration: &configuration::Configuration, id: i32, receipt_update_params: crate::models::ReceiptUpdateParams) -> Result<crate::models::ReceiptResponse, Error<UpdateReceiptError>> {
298    let local_var_configuration = configuration;
299
300    let local_var_client = &local_var_configuration.client;
301
302    let local_var_uri_str = format!("{}/api/1/receipts/{id}", local_var_configuration.base_path, id=id);
303    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
304
305    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
306        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
307    }
308    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
309        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
310    };
311    local_var_req_builder = local_var_req_builder.json(&receipt_update_params);
312
313    let local_var_req = local_var_req_builder.build()?;
314    let local_var_resp = local_var_client.execute(local_var_req).await?;
315
316    let local_var_status = local_var_resp.status();
317    let local_var_content = local_var_resp.text().await?;
318
319    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
320        serde_json::from_str(&local_var_content).map_err(Error::from)
321    } else {
322        let local_var_entity: Option<UpdateReceiptError> = serde_json::from_str(&local_var_content).ok();
323        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
324        Err(Error::ResponseError(local_var_error))
325    }
326}
327