Process an individual file by making a direct POST request
To make POST requests to the Unstructured Partition Endpoint, you will need:
These environment variables:
UNSTRUCTURED_API_KEY
- Your Unstructured API key value.UNSTRUCTURED_API_URL
- Your Unstructured API URL.
To get your API key, do the following:
If you signed up for Unstructured through the For Enterprise page, or if you are using a self-hosted deployment of Unstructured, the following information about signing up, signing in, and getting your Unstructured API key might apply differently to you. For details, contact Unstructured Sales at sales@unstructured.io.
-
Go to https://platform.unstructured.io and use your email address, Google account, or GitHub account to sign up for an Unstructured account (if you do not already have one) and sign into the account at the same time. The Unstructured user interface (UI) appears.
-
Get your Unstructured API key:
a. In the Unstructured UI, click API Keys on the sidebar.
b. Click Generate API Key.
c. Follow the on-screen instructions to finish generating the key.
d. Click the Copy icon next to your new key to add the key to your system’s clipboard. If you lose this key, simply return and click the Copy icon again.
By following the preceding instructions, you are signed up for a Developer pay per page account by default.
To save money, consider switching to a Subscribe & Save account instead. To save even more money, consider switching to an Enterprise account instead.
The API base URL is https://api.unstructuredapp.io
Let’s start with a simple example in which you use curl to send a local PDF file (*.pdf
) to partition via the Unstructured Partition Endpoint.
In this command, be sure to replace <path/to/file>
with the path to your local PDF file.
In the example above we’re representing the base API endpoint with the environment variable UNSTRUCTURED_API_URL
. Note, however, that you also need to authenticate yourself with
your individual API Key, represented by the environment variable UNSTRUCTURED_API_KEY
. Learn how to obtain an API URL and API key in the Unstructured Partition Endpoint guide.
The results are printed to your terminal or Command Prompt with a format similar to the following:
Make a note of the <job-id>
value.
Next, run the following curl
command, replacing <job_id>
with the <job_id>
value:
The results are printed to your terminal or Command Prompt with a format similar to the following:
If the job is still in progress, repeat the curl
command until the job is complete. However, if you run the curl
command
and the job has successfully completed, the results that are printed to your terminal or Command Prompt will contain the processed data within the
elements
array, for example:
By default, the JSON is printed without indenting or other whitespace. You can pretty-print the JSON output by using utilities such as jq in future command runs.
You can also pipe the JSON output to a local file by using the curl
option -o, —output <file> in future command runs.
Synchronous requests
The preceding section describes how to make asynchronous requests to the Unstructured Partition Endpoint. The Unstructured Partition Endpoint also supports synchronous requests.
To make a synchronous request, replace /v1/partition_async
with /general/v0/general
as follows:
If the request is successfully completed, the processed data is returned directly to your terminal or Command Prompt, without needing to make any additional requests. However, you must wait for the request to complete and return the results.
While supported, synchronous requests are not recommended for the following reasons:
- A synchronous request must wait until the operation is complete, which might result in a timeout error.
- A waiting synchronous request is a poor user experience, as it can give the user the mistaken impression that nothing is happening.
- While waiting, you cannot poll to check the current status of a synchronous request.
- If the related network connection is lost during a synchronous request, the request might fail.
For these reasons, if you must make synchronous requests, they should be limited to processing only relatively small, text-based files.
Parameters & examples
The API parameters are the same across all methods of accessing the Unstructured Partition Endpoint.
- Refer to the API parameters page for the full list of available parameters.
- Refer to the Examples page for some inspiration on using the parameters.
Postman collection
Unstructured offers a Postman collection that you can import into Postman to make POST requests through a graphical user interface.
-
In your workspace, click Import.
-
In the Paste cURL, Raw text or URL box, enter the following URL, and then press
Enter
: -
On the sidebar, click Collections.
-
Expand Unstructured REST.
-
Expand Partition Endpoint.
To create an asynchronous request, do the following:
- Click Asynchronous Job Request.
- On the Headers tab, next to
unstructured-api-key
, enter your Unstructured API key in the Value column. - On the Body tab, next to
files
, click the Select files box in the Value column. - Click New file from local machine.
- Browse to and select the file that you want Unstructured to process.
- Repeat steps 3-5 for any additional files that you want to process.
- On the Body tab, add, remove, or modify any allowed parameters that you want to use.
- Click Send. Note the value of the
partition_id
field in the response, as you will need it for the next procedure.
To check the status of an asynchronous request, do the following:
- Click Asynchronous Job Status.
- In the URL, replace
<partition-id>
with thepartition_id
value that you noted in the previous procedure. - On the Headers tab, next to
unstructured-api-key
, enter your Unstructured API key in the Value column. - Click Send.
- Keep clicking Send periodically until the job is complete.
- To download the processed data to your local machine, in the response area, click the ellipses, and then click Save response to file.
To create a synchronous request, do the following:
- Click Synchronous Request.
- On the Headers tab, next to
unstructured-api-key
, enter your Unstructured API key in the Value column. - On the Body tab, next to
files
, click the Select files box in the Value column. - Click New file from local machine.
- Browse to and select the file that you want Unstructured to process.
- On the Body tab, add, remove, or modify any allowed parameters that you want to use.
- Click Send. Processing could take several minutes.
- To download the processed data to your local machine, in the response area, click the ellipses, and then click Save response to file.