Start an API request to extract text and other metadata from the input document and specify a location where you want to store the generated JSON output file within the same bucket.
For example, the following cURL command submits a request to extract text from the input_doc.pdf file to an output file named output_file.json in the same Cloud Object Storage bucket.
curl -X POST \
'https://<region>.cloud.ibm.com/ml/v1/text/extractions?version=2024-07-22' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <Your-access-token>'
--data '{
"project_id": "<Project-ID>",
"document_reference": {
"type": "connection_asset",
"connection": {
"id": "<COS-connection-ID>"
},
"location": {
"bucket":"<COS-bucket-name>",
"file_name": "input_doc.pdf"
}
},
"results_reference": {
"type": "connection_asset",
"connection": {
"id": "<COS-connection-ID>"
},
"location": {
"file_name": "output_file.json"
}
},
"steps": {
"ocr": {
"languages_list": [
"en",
]
},
"tables_processing": {
"enabled": true
}
}
}'
Optional: Check the status of your text extraction request by retrieving the request ID from the metadata section in the API response and running the following command:
curl -X GET \
'https://<region>.cloud.ibm.com/ml/v1/text/extractions/<request-id>?version=2024-07-22&project_id=<project-id>' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <Your-access-token>'
After the API request completes, the resulting file is generated in the Cloud Object Storage location that you specified in your text extraction request. The extracted JSON data contains details about various textual and visual elements in the document such as sections, paragraphs, table structures, images and more. For details about the watsonx.ai text extraction API, see the watsonx.ai as a service API reference documentation.