1. Exports
  2. Create Export

Exports

Create Export

POST
`/v1/exports`

Overview

The Create Export endpoint is the starting point for data extraction. You specify what data to export, how to filter it, and how to format the output. The system will process your request asynchronously and provide you with a download URL when complete.

Quick Start

        const response = await fetch("https://api.packagex.io/v1/exports", {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    resource: "shipment",
    options: {
      limit: 1000,
      created_at: "gte:2024-01-01"
    },
    csv_field_options: {
      timezone: "America/New_York",
      datetime_format: "MM/dd/yyyy hh:mm:ss a",
      columns: {
        id: true,
        tracking_number: true,
        status: true,
        created_at: true
      }
    }
  })
});

const export_data = await response.json();
console.log("Export ID:", export_data.id);

      

Request Structure

Required Parameters

Parameter Type Description
resource string The type of data to export
options object Filtering and pagination options (same as List APIs)
csv_field_options object Output formatting configuration

Detailed Examples

1. Export Contacts with Group Filtering

Export all contacts in a specific group, ordered by creation date:

        const response = await fetch("https://api.packagex.io/v1/exports", {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    resource: "contact",
    options: {
      limit: "all",
      order_by: "created_at",
      direction: "asc",
      group_id: "grp_19asti9p9u8sBaiJVPxFUF"
    },
    csv_field_options: {
      timezone: "America/New_York",
      datetime_format: "MM/dd/yyyy hh:mm:ss a",
      columns: {
        id: true,
        external_id: true,
        name: true,
        alternate_names: true,
        email: true,
        alternate_emails: true,
        phone: true,
        alternate_phones: true,
        id_number: true,
        address: true,
        alternate_addresses: true,
        groups: true,
        locations: true,
        is_primary: true,
        notes: true,
        created_at: true,
        updated_at: true,
        updated_by: true,
        organization_id: true,
        metadata: true,
        _search: true,
        _experimental: true,
        _outbound_trackers: true,
        _inbound_trackers: true
      },
      column_order: [
        "id",
        "external_id", 
        "name",
        "alternate_names",
        "email",
        "alternate_emails",
        "phone",
        "alternate_phones",
        "id_number",
        "address",
        "alternate_addresses",
        "groups",
        "locations",
        "is_primary",
        "notes",
        "created_at",
        "updated_at",
        "updated_by",
        "organization_id",
        "metadata",
        "_search",
        "_experimental",
        "_outbound_trackers",
        "_inbound_trackers"
      ],
      properties: "merge"
    }
  })
});

const export_data = await response.json();

      

2. Export Contact Groups

Export all contact groups ordered alphabetically:

        const response = await fetch("https://api.packagex.io/v1/exports", {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    resource: "group",
    options: {
      limit: "all",
      order_by: "name",
      direction: "asc",
      resource: "contact"
    },
    csv_field_options: {
      timezone: "America/New_York",
      datetime_format: "MM/dd/yyyy hh:mm:ss a",
      columns: {
        id: true,
        name: true,
        resource: true,
        children: true,
        children_count: true,
        location: true,
        created_at: true,
        updated_at: true,
        updated_by: true,
        organization_id: true,
        metadata: true,
        _search: true
      },
      column_order: [
        "id",
        "name",
        "resource",
        "children",
        "children_count",
        "location",
        "created_at",
        "updated_at",
        "updated_by",
        "organization_id",
        "metadata",
        "_search"
      ],
      properties: "merge"
    }
  })
});

const export_data = await response.json();

      

3. Export Shipping Label Inferences with Filters

Export USPS shipping label inferences with specific metadata and date range:

        const response = await fetch("https://api.packagex.io/v1/exports", {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    resource: "shipping_label_inference",
    options: {
      limit: "all",
      provider_name: "usps",
      "metadata.service": "inbound",
      created_at: "bwi:1732993200000,1734548400000"
    },
    csv_field_options: {
      timezone: "America/New_York",
      datetime_format: "MM/dd/yyyy hh:mm:ss a",
      columns: {
        id: true,
        image_url: true,
        raw_text: true,
        layout: true,
        recipient: true,
        sender: true,
        extracted_recipient_name: true,
        extracted_sender_name: true,
        provider_name: true,
        service_level_name: true,
        rma_number: true,
        purchase_order: true,
        reference_number: true,
        invoice_number: true,
        tracking_number: true,
        order_number: true,
        notes: true,
        barcode_values: true,
        weight: true,
        dimensions: true,
        matches: true,
        status: true,
        errors: true,
        exceptions: true,
        error_details: true,
        tracker_id: true,
        tags: true,
        created_at: true,
        updated_at: true,
        updated_by: true,
        organization_id: true,
        metadata: true,
        location_id: true,
        provider_id: true,
        service_level_id: true,
        account_id: true,
        media_urls: true,
        provider: true,
        providers: true
      },
      column_order: [
        "id",
        "image_url",
        "raw_text",
        "layout",
        "recipient",
        "sender",
        "extracted_recipient_name",
        "extracted_sender_name",
        "provider_name",
        "service_level_name",
        "rma_number",
        "purchase_order",
        "reference_number",
        "invoice_number",
        "tracking_number",
        "order_number",
        "notes",
        "barcode_values",
        "weight",
        "dimensions",
        "matches",
        "status",
        "errors",
        "exceptions",
        "error_details",
        "tracker_id",
        "tags",
        "created_at",
        "updated_at",
        "updated_by",
        "organization_id",
        "metadata",
        "location_id",
        "provider_id",
        "service_level_id",
        "account_id",
        "media_urls",
        "provider",
        "providers"
      ],
      properties: "merge"
    }
  })
});

const export_data = await response.json();

      

4. Export Shipments with Multiple Filters

Export shipments from multiple providers with specific statuses and date range:

        const response = await fetch("https://api.packagex.io/v1/exports", {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    resource: "shipment",
    options: {
      limit: "all",
      provider: "fedex,ups,usps",
      statuses: "pickup_available,delivered,completed",
      created_at: "bwi:1732993200000,1734548400000"
    },
    csv_field_options: {
      timezone: "America/New_York",
      datetime_format: "MM/dd/yyyy hh:mm:ss a",
      columns: {
        id: true,
        label_url: true,
        amount: true,
        billed_amount: true,
        paid: true,
        currency: true,
        payment_reference: true,
        purchased_rate: true,
        rates: true,
        recommended_rate: true,
        coordinates: true,
        parcels: true,
        provider: true,
        refund_status: true,
        recipient: true,
        destination_contact: true,
        sender: true,
        status: true,
        order_number: true,
        tracking_number: true,
        tracking_updates: true,
        tracking_url: true,
        type: true,
        options: true,
        barcode_values: true,
        tags: true,
        customs: true,
        location: true,
        layout_id: true,
        container_id: true,
        invoice_id: true,
        fulfillment_id: true,
        manifest_id: true,
        inference_id: true,
        tracker_id: true,
        tracker: true,
        user_id: true,
        rates_generated_at: true,
        estimated_delivery_at: true,
        pickup_at: true,
        created_at: true,
        updated_at: true,
        updated_by: true,
        organization_id: true,
        metadata: true,
        rma_number: true,
        invoice_number: true,
        purchase_order: true,
        reference_number: true,
        account_id: true,
        notes: true,
        fee: true,
        _search: true
      },
      column_order: [
        "id",
        "label_url",
        "amount",
        "billed_amount",
        "paid",
        "currency",
        "payment_reference",
        "purchased_rate",
        "rates",
        "recommended_rate",
        "coordinates",
        "parcels",
        "provider",
        "refund_status",
        "recipient",
        "destination_contact",
        "sender",
        "status",
        "order_number",
        "tracking_number",
        "tracking_updates",
        "tracking_url",
        "type",
        "options",
        "barcode_values",
        "tags",
        "customs",
        "location",
        "layout_id",
        "container_id",
        "invoice_id",
        "fulfillment_id",
        "manifest_id",
        "inference_id",
        "tracker_id",
        "tracker",
        "user_id",
        "rates_generated_at",
        "estimated_delivery_at",
        "pickup_at",
        "created_at",
        "updated_at",
        "updated_by",
        "organization_id",
        "metadata",
        "rma_number",
        "invoice_number",
        "purchase_order",
        "reference_number",
        "account_id",
        "notes",
        "fee",
        "_search"
      ],
      properties: "merge"
    }
  })
});

const export_data = await response.json();

      

5. Export Trackers with Provider Filtering

Export trackers from multiple providers with specific statuses:

        const response = await fetch("https://api.packagex.io/v1/exports", {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    resource: "tracker",
    options: {
      limit: "all",
      provider: "fedex,ups,usps",
      statuses: "pickup_available,delivered,completed",
      created_at: "bwi:1732993200000,1734548400000"
    },
    csv_field_options: {
      timezone: "America/New_York",
      datetime_format: "MM/dd/yyyy hh:mm:ss a",
      columns: {
        id: true,
        type: true,
        tags: true,
        status: true,
        tracking_number: true,
        tracking_url: true,
        tracking_updates: true,
        destination_address: true,
        destination_layout: true,
        destination_location: true,
        destination_contact: true,
        sender_contact: true,
        chained_status: true,
        auto_close_shipments_option: true,
        auto_close_shipments_status: true,
        manifest_id: true,
        estimated_delivery_at: true,
        final_chained_shipment_id: true,
        current_shipment_id: true,
        created_at: true,
        updated_at: true,
        updated_by: true,
        organization_id: true,
        metadata: true,
        _search: true
      },
      column_order: [
        "id",
        "type",
        "tags",
        "status",
        "tracking_number",
        "tracking_url",
        "tracking_updates",
        "destination_address",
        "destination_layout",
        "destination_location",
        "destination_contact",
        "sender_contact",
        "chained_status",
        "auto_close_shipments_option",
        "auto_close_shipments_status",
        "manifest_id",
        "estimated_delivery_at",
        "final_chained_shipment_id",
        "current_shipment_id",
        "created_at",
        "updated_at",
        "updated_by",
        "organization_id",
        "metadata",
        "_search"
      ],
      properties: "merge"
    }
  })
});

const export_data = await response.json();

      

6. Export Locations Alphabetically

Export all locations ordered by name:

        const response = await fetch("https://api.packagex.io/v1/exports", {
  method: "POST",
  headers: {
    "PX-API-KEY": process.env.PX_API_KEY,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    resource: "location",
    options: {
      limit: "all",
      order_by: "name",
      direction: "asc"
    },
    csv_field_options: {
      timezone: "America/New_York",
      datetime_format: "MM/dd/yyyy hh:mm:ss a",
      columns: {
        id: true,
        name: true,
        code: true,
        email: true,
        address: true,
        service_levels: true,
        provider_instructions: true,
        operating_hours: true,
        holidays: true,
        users: true,
        groups: true,
        created_at: true,
        updated_at: true,
        updated_by: true,
        organization_id: true,
        metadata: true,
        last_audited_at: true,
        _search: true
      },
      column_order: [
        "id",
        "name",
        "code",
        "email",
        "address",
        "service_levels",
        "provider_instructions",
        "operating_hours",
        "holidays",
        "users",
        "groups",
        "created_at",
        "updated_at",
        "updated_by",
        "organization_id",
        "metadata",
        "last_audited_at"
      ],
      properties: "merge"
    }
  })
});

const export_data = await response.json();

      

Request Parameters

Resource Options

The options object accepts the same parameters as the corresponding List API for each resource. Common options include:

Parameter Type Description Example
limit string/number Number of records to export "all" or 1000
order_by string Field to sort by "created_at", "name"
direction string Sort direction "asc" or "desc"
created_at string Date filter "gte:2024-01-01"
updated_at string Date filter "bwi:1732993200000,1734548400000"

CSV Field Options

Parameter Type Required Description Example
timezone string Yes Timezone for datetime fields "America/New_York"
datetime_format string Yes Date/time format pattern "MM/dd/yyyy hh:mm:ss a"
columns object Yes Which columns to include { id: true, name: true }
column_order array No Order of columns in output ["id", "name", "created_at"]
properties string Yes How to handle nested data "merge" or "flatten"

Common Date Formats

Format Example Description
"MM/dd/yyyy hh:mm:ss a" 12/25/2024 02:30:45 PM US format with AM/PM
"yyyy-MM-dd HH:mm:ss" 2024-12-25 14:30:45 ISO format (24-hour)
"MM/dd/yyyy" 12/25/2024 Date only
"yyyy-MM-dd'T'HH:mm:ss.SSSZ" 2024-12-25T14:30:45.123Z ISO 8601 with timezone

Common Timezones

Timezone Description
"America/New_York" Eastern Time
"America/Chicago" Central Time
"America/Denver" Mountain Time
"America/Los_Angeles" Pacific Time
"UTC" Coordinated Universal Time
"Europe/London" British Time
"Asia/Tokyo" Japan Time

Response Format

Success Response

        {
  "id": "exp_1234567890abcdef",
  "resource": "shipment",
  "status": "queued",
  "created_at": "2024-01-15T10:30:00Z",
  "estimated_completion": "2024-01-15T10:35:00Z",
  "download_url": null,
  "expires_at": "2024-01-16T10:30:00Z"
}

      

Error Response

        {
  "error": "invalid_resource",
  "message": "Unsupported resource type: invalid_resource",
  "details": {
    "resource": "invalid_resource"
  }
}