> For the complete documentation index, see [llms.txt](https://photon-commerce.gitbook.io/photon-commerce-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://photon-commerce.gitbook.io/photon-commerce-api/async-api.md).

# Async API

For async processing of your documents

## Asynchronous API for batches and queues of documents

A typical REST API which accepts your documents and returns the photon key needed to access the result in less than a second. Be sure to save that photon key in order to be able to fetch the results later.&#x20;

No need to wait for the results. You will be notified via email when the document has been processed and the result is ready to be fetched.\
\
This ASYNC API allows us to upload multiple documents, one after another with a minimal waiting time. Store the photon\_key we send in the response and access it once you receive an email from Photon.

## Invoice and receipt capture

<mark style="color:green;">`POST`</mark> `https://api.photoncommerce.com/api/v4?type=async`

Capture invoices and receipts using your Client ID, Client Secret, API Key and Username

#### Path Parameters

| Name | Type   | Description                                                                    |
| ---- | ------ | ------------------------------------------------------------------------------ |
| type | string | <p>Type of processing needed- sync or async<br>Please pass type as 'async'</p> |

#### Headers

| Name          | Type   | Description                                                                                     |
| ------------- | ------ | ----------------------------------------------------------------------------------------------- |
| PASSWORD      | string | The password of the account                                                                     |
| SECRET-KEY    | string | The secret key of the account                                                                   |
| AUTHORIZATION | string | Pass your username and unique API key  in the form 'apikey \<your\_username>:\<your\_api\_key>' |
| CLIENT-ID     | string | Unique Client\_ID for every user. Incorrect value will lead to an authorization error.          |

#### Request Body

| Name | Type   | Description                                                     |
| ---- | ------ | --------------------------------------------------------------- |
| pdf  | string | The path to the pdf, document, or image needing to be captured. |

{% tabs %}
{% tab title="200 " %}

```
{'photon_key': 'data/<your_username>/<filename>.json', 'message': 'success', 'status': 'success'}
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Python" %}

```python
import requests

headers = {
    'CLIENT-ID': '<client-id>',
    'AUTHORIZATION': 'apikey <username>:<api-key>',
    'PASSWORD':'<Your-valid-password>',
    'SECRET-KEY':'<your-client-secret>'
}
files = {'pdf': open('<path-to-file>', 'rb')}

response = requests.post('https://api.photoncommerce.com/api/v4?type=async', headers=headers, files=files)
```

{% endtab %}

{% tab title="cURL" %}

```
curl  -X POST -H "CLIENT-ID:<client-id>" -H "AUTHORIZATION:apikey <username>:<api-key>" -H 'PASSWORD:<password>' -H "SECRET-KEY:<secret-key>" -F "pdf=@<path-to-file>" "https://api.photoncommerce.com/api/v4?type=async"
```

{% endtab %}

{% tab title="Node.js" %}

```
var request = require('request');

var headers = {
    'CLIENT-ID': '<client-id>',
    'AUTHORIZATION': 'apikey <username>:<api-key>',
    'PASSWORD': '<password>',
    'SECRET-KEY': '<secret-key>'
};

var options = {
    url: 'https://api.photoncommerce.com/api/v4?type=async',
    method: 'POST',
    headers: headers
};

function callback(error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log(body);
    }
}

request(options, callback);
```

{% endtab %}

{% tab title="Java" %}

```
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;

class Main {

	public static void main(String[] args) throws IOException {
		URL url = new URL("https://api.photoncommerce.com/api/v4?type=async");
		HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
		httpConn.setRequestMethod("POST");

		httpConn.setRequestProperty("CLIENT-ID", "<client-id>");
		httpConn.setRequestProperty("AUTHORIZATION", "apikey <username>:<api-key>");
		httpConn.setRequestProperty("PASSWORD", "<password>");
		httpConn.setRequestProperty("SECRET-KEY", "<secret-key>");

		InputStream responseStream = httpConn.getResponseCode() / 100 == 2
				? httpConn.getInputStream()
				: httpConn.getErrorStream();
		Scanner s = new Scanner(responseStream).useDelimiter("\\A");
		String response = s.hasNext() ? s.next() : "";
		System.out.println(response);
	}
}
```

{% endtab %}
{% endtabs %}

Once your document has been processed, you will receive an email from <notifications@photoncommerce.com> with the subject "Photon API - The document has been processed". Upon receiving this email, you can fetch the result using the photon\_key we sent to you when you uploaded the document. In case you missed it, the email we send you will also contain the photon key.

You can use the fetch the json by following the steps mentioned under the section 'Retrieve Data (JSON)" on the "Getting Started with the Photon Commerce API" Page.

## Async API Webhook

Please see the Async API Webhook page for instructions to set up a webhook.
