# API Input

To provide an API as data input:

* Upload a Python script which can execute and produce output in CSV or JSON format.
* The output location will be passed as first argumen&#x74;**.**
* Provide a sample output JSON for the schema.

{% hint style="warning" %}
Ensure the sample output (few records) represents all of the columns.
{% endhint %}

Sample Python code snippet for an API\_:\_

```python
import json
import csv
import requests
import sys
import pandas as pd
def download_json(url):
    response = requests.get(url)
    data = response.json()
    return data['emp_hash']
def write_to_csv(data, output_path):
    df = pd.DataFrame(data)
    df.to_csv(output_path, index=False)
if __name__ == "__main__":
    output_path = sys.argv[1]
    url = "https://dataq-testing-data.s3.amazonaws.com/Input+Files/emp_hash.json"
    data = download_json(url)
    write_to_csv(data, output_path)
```

{% file src="<https://2027008842-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaO8uOTM2rdJeIbVeXK0c%2Fuploads%2FuAZyKzP5Nsgm2DIV36Up%2Fconversation.json?alt=media>" %}
Sample API output file(json)
{% endfile %}
