# Advocate Bulk Import Methods

Import jobs can be started from impact.com, via Advocate’s SFTP integration, or by using the Advocate API directly.

### File-based bulk imports in impact.com

Bulk imports can be started from within impact.com. To get started, from the left navigation menu, select ![](https://res.cloudinary.com/product-enablement/image/upload/v1768905009/Accessibility%20Icons/engage-v2.svg) **Engage → Reporting → Imports & Exports**.

For full instructions on the file-based bulk import process, see our other guides:

* [Import Participants in Bulk](https://help.impact.com/en/support/solutions/articles/155000000869)
* [Delete Participants in Bulk](https://help.impact.com/en/support/solutions/articles/155000000870)

### Bulk imports via SFTP integration

Bulk imports can be performed via the SaaSquatch SFTP integration. See our guide on the [SFTP integration](https://integrations.impact.com/impact-brand/docs/sftp-import-integration) for instructions on:

* Enabling and authenticating the integration
* Generating an SSH key
* Connecting to the SFTP server
* Uploading import files and checking their status

### Bulk imports via API

To start a bulk import job, there are three API requests to be performed.

* Uploading the import file
* Validating the import file
* Starting the import job

#### Uploading the import file

The `/export/upload` endpoint accepts a file upload in two different ways, either with `multipart/form-data` encoding or as a raw file upload.

**Example Request:**

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

```bash
curl -X POST 'https://app.referralsaasquatch.com/api/v1/{tenant_alias}/export/upload' \
        -u :{tenant_api_key} \
        --form 'file=@my_file.csv'
```

{% endtab %}
{% endtabs %}

When the file is successfully uploaded, a `fileRef` will be returned. The `fileRef` will be used in the next two API requests.

**Example Response:**

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

```json
{
    “fileRef”: “imports/test_akdq8a9wyvzba/userEvents_63323378e1edcd44b03eed9a.jsonl”
}
```

{% endtab %}
{% endtabs %}

#### Validating the import file

Before starting your import job, you can use the `validateJobInput` GraphQL mutation to validate the import file before attempting to start the import job.\
There are two inputs required, the `fileRef` from step 1, and the job `type`.\
These are the job types available:

* Import Users: `MUTATION/USER`
* Delete Users: `MUTATION/DELETE_USER`
* Import User Events: `MUTATION/USER_EVENT`

**Example:**

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

```bash
curl -X POST https://app.referralsaasquatch.com/api/v1/{tenant_alias}/graphql \ 
    -u :{tenant_api_key} \
    -H "Content-Type: application/json" 
    -d '{
    "operationName":"validate",
    "variables": {
        "jobInput": {
            "fileRef":"{file_ref}",
            "type":"{job_type}"
        }
    },
    "query": "query validate($jobInput: JobInput!) {validateJobCreation(jobInput: $jobInput) { errors }}"
}'
```

{% endtab %}
{% endtabs %}

If there are any errors found in the import file, they will be returned as an array in `errors`. If `errors` is empty, then the same `fileRef` can be used to start an import job in step 3.

**Example Response:**

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

```json
{
    "data": {
        "validateJobCreation": {
            "errors": []
        }
    }
}
```

{% endtab %}
{% endtabs %}

#### Starting the import job

To start the import job, use the `createJob` GraphQL mutation. Provide the `fileRef` and job `type` from the [Validating the import file](#validating-the-import-file) section.

**Example:**

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

```bash
curl -X POST https://app.referralsaasquatch.com/api/v1/{tenant_alias}/graphql \ 
    -u :{tenant_api_key}
    -H "Content-Type: application/json" 
    -d '{
    "variables":{
        "jobInput": {
            "type":"{job_type}",
            "outputFormat":"CSV",
            "fileRef":"{file_ref}"
        }
    },
    "query":"mutation ($jobInput: JobInput!) { createJob(jobInput: $jobInput) {id type requester dateCreated}}"
}'
```

{% endtab %}
{% endtabs %}

The `id` returned by the mutation can be used to query the status of the job

**Example Response:**

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

```json
{
    "data": {
        "createJob": {
            "id": "633b1cf34efc053cb50a3f6d",
            "type": "MUTATION/USER_EVENT",
            "requester": "API",
            "dateCreated": 1664818419661
        }
    }
}
```

{% endtab %}
{% endtabs %}

#### Check the status of the import job

To check the status of the import job, you can use the `job` GraphQL query and provide the job `id` returned from the [Starting the import job](#starting-the-import-job) section.

**Example:**

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

```bash
curl -X POST https://app.referralsaasquatch.com/api/v1/{tenant_alias}/graphql \
    -u :{tenant_api_key} \
    -H "Content-Type: application/json" 
    -d '{
    "variables": {
        "id": "{job_id}"
    },
    "query": "query ($id: ID!) { job(id: $id) { status stats { recordsProcessed }}}"
}'
```

{% endtab %}
{% endtabs %}

**Example Response:**

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

```json
{
    "data": {
        "job": {
            "status": "COMPLETED",
            "stats": {
                "recordsProcessed": 22
            }
        }
    }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://integrations.impact.com/integration-guides/for-brands/advocate/advocate-bulk-import-methods.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
