Documentation Index
Fetch the complete documentation index at: https://developer.box.com/llms.txt
Use this file to discover all available pages before exploring further.
マークダウンレプリゼンテーションを使用すると、ヘッダー、表、リスト、書式設定の指示などの構造を保持しながら、ドキュメントからテキストを抽出できます。マークダウンの変換速度は、ファイルサイズとコンテンツによって異なります。
サポートされているファイルの種類
マークダウンレプリゼンテーションは、以下のドキュメント形式に対応しています。
- Microsoft Office: Word (.docx)、PowerPoint (.pptx)、Excel (.xls、.xlsx、.xlsm)
- Google Workspace: Googleドキュメント (.gdoc)、Googleスライド (.gslide、.gslides)、
- Googleスプレッドシート (.gsheet)
- PDFファイル (.pdf)
マークダウンレプリゼンテーションの作成
この手順では、Box APIを使用してファイルのマークダウンレプリゼンテーションを生成してダウンロードする方法を説明します。
最初にマークダウンレプリゼンテーションを作成するには:
-
- 値
[markdown]を指定したx-rep-hintsヘッダーを渡して、する。
url_templateを呼び出してする。その際、{+asset_path}を空の文字列に置き換えます。
生成されたレプリゼンテーションは、後続のリクエストに備えてBoxによってキャッシュされます。
利用可能なレプリゼンテーションの取得
マークダウンレプリゼンテーションのヒントを指定して、ファイルの利用可能なレプリゼンテーションをリクエストします。
curl -X GET \
'https://api.box.com/2.0/files/12345?fields=id%2Cname%2Crepresentations' \
-H 'X-Rep-Hints: [markdown]' \
-H 'Authorization: Bearer YOUR_ACCESS_TOKEN'
レスポンスの例
{
"type": "file",
"id": "{file_id}",
"etag": "1",
"name": "test.docx",
"representations": {
"entries": [
{
"representation": "markdown",
"properties": {},
"info": {
"url": "https://api.box.com/2.0/internal_files/{file_id}/versions/{version_id}/representations/{representation}"
},
"status": {
"state": "none"
},
"content": {
"url_template": "https://dl.boxcloud.com/api/2.0/internal_files/{file_id}/versions/{version_id}/representations/{representation}/content/{+asset_path}"
}
}
]
}
}
マークダウン生成の開始
状態がnoneの場合、マークダウンレプリゼンテーションの生成を開始するために情報URLをリクエストします。
curl -X GET \
'https://api.box.com/2.0/internal_files/12345/versions/2200612360399/representations/markdown' \
-H 'Authorization: Bearer YOUR_ACCESS_TOKEN'
レプリゼンテーションのステータスの確認
ファイルに再度クエリを実行して、マークダウンレプリゼンテーションの現在のステータスを確認します。
curl -X GET \
'https://api.box.com/2.0/files/12345?fields=id%2Cname%2Crepresentations' \
-H 'X-Rep-Hints: [markdown]' \
-H 'Authorization: Bearer YOUR_ACCESS_TOKEN'
ステータスがpendingからsuccessに変わると、マークダウンファイルはダウンロード可能になります。このステータスはレプリゼンテーションが利用可能かどうかを示します。利用可能なオプションはsuccess、viewable、pending、noneです。Successはレプリゼンテーションを即座にダウンロードできることを意味するのに対し、noneはレプリゼンテーションが生成可能であることを示します。
マークダウンレプリゼンテーションのダウンロード
レプリゼンテーションの準備が整ったら、content/url_templateを使用してダウンロードします。
curl -L \
'https://dl.boxcloud.com/api/2.0/internal_files/12345/versions/1415005153353/representations/markdown/content/index.md' \
-H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
-o file_name.md