> ## Documentation Index
> Fetch the complete documentation index at: https://docs.journeybee.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Leads

> Retrieve a list of leads for a company with advanced filtering, sorting, and pagination support

## Authentication

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://app.journeybee.io/api/v1/leads?userId={userId}" \
    -H "Authorization: Bearer your-api-key-uuid" \
    -H "Content-Type: application/json"
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://app.journeybee.io/api/v1/leads?userId={userId}', {
    method: 'GET',
    headers: {
      'Authorization': 'Bearer your-api-key-uuid',
      'Content-Type': 'application/json'
    }
  });
  ```
</CodeGroup>

## Query Parameters

<ParamField query="userId" type="number" required>
  The ID of the user making the request (for authorization)
</ParamField>

<ParamField query="cursor" type="string">
  Pagination cursor (ISO timestamp) for fetching the next set of results
</ParamField>

<ParamField query="search" type="string">
  Search leads by company name, email, phone, first name, last name, assigned users, or partner companies
</ParamField>

<ParamField query="view" type="string">
  Filter by lead source/type. Options: `received`, `sent`, `reseller`, `campaigns`
</ParamField>

<ParamField query="assigned" type="number">
  Filter by assignment status. Use `1` to show only assigned leads
</ParamField>

<ParamField query="unassigned" type="number">
  Filter by assignment status. Use `1` to show only unassigned leads
</ParamField>

<ParamField query="status" type="string">
  Comma-separated list of lead statuses to filter by. Options: `new`, `contacted`, `qualified`, `converted`, `lost`
</ParamField>

<ParamField query="tags" type="string">
  Comma-separated list of tag IDs to filter by
</ParamField>

<ParamField query="users" type="string">
  Comma-separated list of user IDs to filter by assigned users
</ParamField>

<ParamField query="customFields" type="string">
  JSON string of custom field filters with format: `[{"id": 123, "value": {"text": "search"}}]`
</ParamField>

<ParamField query="sort" type="string">
  JSON string of sort options with format: `[{"type": "status", "asc": true}]`. Types: `status`
</ParamField>

## Response Schema

<ResponseField name="leads" type="array">
  Array of lead objects

  <Expandable title="Lead Object">
    <ResponseField name="total" type="number">
      Total number of leads matching the query
    </ResponseField>

    <ResponseField name="id" type="number">
      Lead ID
    </ResponseField>

    <ResponseField name="uuid" type="string">
      Lead UUID
    </ResponseField>

    <ResponseField name="created_at" type="string">
      Lead creation timestamp
    </ResponseField>

    <ResponseField name="updated_at" type="string">
      Lead last update timestamp
    </ResponseField>

    <ResponseField name="source" type="string">
      Lead source: `manual`, `campaign`, `partnership`, `integration`, `form`
    </ResponseField>

    <ResponseField name="company_name" type="string">
      Lead company name
    </ResponseField>

    <ResponseField name="email" type="string">
      Lead contact email
    </ResponseField>

    <ResponseField name="phone_number" type="string">
      Lead contact phone number
    </ResponseField>

    <ResponseField name="first_name" type="string">
      Lead contact first name
    </ResponseField>

    <ResponseField name="last_name" type="string">
      Lead contact last name
    </ResponseField>

    <ResponseField name="status" type="string">
      Lead status: `new`, `contacted`, `qualified`, `converted`, `lost`
    </ResponseField>

    <ResponseField name="partner_type" type="string">
      Partner relationship type: `referral`, `reseller`, `null`
    </ResponseField>

    <ResponseField name="company_id" type="number">
      Company ID that owns this lead
    </ResponseField>

    <ResponseField name="created_by_user_id" type="number">
      ID of user who created this lead
    </ResponseField>

    <ResponseField name="campaign_id" type="number">
      Campaign ID if lead came from a campaign
    </ResponseField>

    <ResponseField name="campaign_title" type="string">
      Campaign name if lead came from a campaign
    </ResponseField>

    <ResponseField name="tags" type="array">
      Array of assigned tags

      <Expandable title="Tag Object">
        <ResponseField name="id" type="number">Tag ID</ResponseField>
        <ResponseField name="label" type="string">Tag label</ResponseField>
        <ResponseField name="background_color" type="string">Tag background color</ResponseField>
        <ResponseField name="text_color" type="string">Tag text color</ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="assigned_users" type="array">
      Array of assigned users

      <Expandable title="User Object">
        <ResponseField name="id" type="number">User ID</ResponseField>
        <ResponseField name="email" type="string">User email</ResponseField>
        <ResponseField name="first_name" type="string">User first name</ResponseField>
        <ResponseField name="last_name" type="string">User last name</ResponseField>
        <ResponseField name="color" type="string">User color</ResponseField>
        <ResponseField name="profile_image_id" type="number">Profile image asset ID</ResponseField>
        <ResponseField name="profile_image_uuid" type="string">Profile image asset UUID</ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="partnership_leads" type="array">
      Array of partnership information (for sent/received leads)

      <Expandable title="Partnership Lead Object">
        <ResponseField name="id" type="number">Partnership lead ID</ResponseField>
        <ResponseField name="created_at" type="string">Partnership creation timestamp</ResponseField>
        <ResponseField name="partnership_id" type="number">Partnership ID</ResponseField>
        <ResponseField name="sent_by_company_id" type="number">Sending company ID</ResponseField>
        <ResponseField name="sent_by_company_name" type="string">Sending company name</ResponseField>
        <ResponseField name="sent_by_company_logo_id" type="number">Sending company logo asset ID</ResponseField>
        <ResponseField name="sent_by_company_logo_uuid" type="string">Sending company logo asset UUID</ResponseField>
        <ResponseField name="received_by_company_id" type="number">Receiving company ID</ResponseField>
        <ResponseField name="received_by_company_name" type="string">Receiving company name</ResponseField>
        <ResponseField name="received_by_company_logo_id" type="number">Receiving company logo asset ID</ResponseField>
        <ResponseField name="received_by_company_logo_uuid" type="string">Receiving company logo asset UUID</ResponseField>
        <ResponseField name="partner_type" type="string">Partnership type: `referral`, `reseller`</ResponseField>
        <ResponseField name="direction" type="string">Direction from perspective: `sent`, `received`</ResponseField>
        <ResponseField name="fallback_data" type="object">Partner fallback data for inactive partners</ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="campaign_partners" type="array">
      Array of campaign partner information (for campaign leads)

      <Expandable title="Campaign Partner Object">
        <ResponseField name="partners_company_id" type="number">Partner company ID</ResponseField>
        <ResponseField name="partners_company_name" type="string">Partner company name</ResponseField>
        <ResponseField name="partners_company_logo_id" type="number">Partner company logo asset ID</ResponseField>
        <ResponseField name="partners_company_logo_uuid" type="string">Partner company logo asset UUID</ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="lead_deals" type="array">
      Array of associated deals

      <Expandable title="Lead Deal Object">
        <ResponseField name="id" type="number">Deal ID</ResponseField>
        <ResponseField name="label" type="string">Deal name</ResponseField>
        <ResponseField name="deal_value" type="number">Deal value</ResponseField>
        <ResponseField name="currency_code" type="string">Currency code for deal value</ResponseField>
        <ResponseField name="stage_id" type="number">Deal stage ID</ResponseField>
        <ResponseField name="stage_label" type="string">Deal stage label</ResponseField>
        <ResponseField name="stage_series" type="number">Deal stage series (order)</ResponseField>
        <ResponseField name="stage_phase" type="string">Deal stage phase</ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

## Example Request

<CodeGroup>
  ```bash cURL theme={null}
  curl -X GET "https://app.journeybee.io/api/v1/leads?userId=456&view=received&search=tech&status=new,contacted" \
    -H "Authorization: Bearer jb_api_1234567890abcdef" \
    -H "Content-Type: application/json"
  ```

  ```javascript JavaScript theme={null}
  const params = new URLSearchParams({
    userId: '456',
    view: 'received',
    search: 'tech',
    status: 'new,contacted'
  });

  const response = await fetch(
    `https://app.journeybee.io/api/v1/leads?${params}`,
    {
      method: 'GET',
      headers: {
        'Authorization': 'Bearer jb_api_1234567890abcdef',
        'Content-Type': 'application/json'
      }
    }
  );

  const leads = await response.json();
  ```
</CodeGroup>

## Example Response

<ResponseExample>
  ```json Example Response theme={null}
  [
    {
      "total": 1,
      "id": 789,
      "uuid": "lead-uuid-789",
      "created_at": "2024-01-15T10:30:00Z",
      "updated_at": "2024-01-15T12:45:00Z",
      "source": "partnership",
      "company_name": "TechCorp Solutions",
      "email": "contact@techcorp.com",
      "phone_number": "+1-555-123-4567",
      "first_name": "John",
      "last_name": "Smith",
      "status": "new",
      "partner_type": "referral",
      "company_id": 123,
      "created_by_user_id": 456,
      "campaign_id": null,
      "campaign_title": null,
      "tags": [
        {
          "id": 10,
          "label": "High Priority",
          "background_color": "#EF4444",
          "text_color": "#FFFFFF"
        }
      ],
      "assigned_users": [
        {
          "id": 456,
          "email": "jane@company.com",
          "first_name": "Jane",
          "last_name": "Doe",
          "color": "#3B82F6",
          "profile_image_id": 789,
          "profile_image_uuid": "profile-uuid-456"
        }
      ],
      "partnership_leads": [
        {
          "id": 123,
          "created_at": "2024-01-15T10:30:00Z",
          "partnership_id": 456,
          "sent_by_company_id": 234,
          "sent_by_company_name": "Partner Corp",
          "sent_by_company_logo_id": 567,
          "sent_by_company_logo_uuid": "logo-uuid-567",
          "received_by_company_id": 123,
          "received_by_company_name": "Your Company",
          "received_by_company_logo_id": 890,
          "received_by_company_logo_uuid": "logo-uuid-890",
          "partner_type": "referral",
          "direction": "received",
          "fallback_data": null
        }
      ],
      "campaign_partners": [],
      "lead_deals": [
        {
          "id": 345,
          "label": "TechCorp Deal",
          "deal_value": 50000,
          "currency_code": "USD",
          "stage_id": 2,
          "stage_label": "Proposal",
          "stage_series": 2,
          "stage_phase": "negotiation"
        }
      ]
    }
  ]
  ```
</ResponseExample>

## Error Responses

<ResponseExample>
  ```json 401 Unauthorized theme={null}
  {
    "error": "Invalid API key or insufficient permissions"
  }
  ```
</ResponseExample>

<ResponseExample>
  ```json 403 Forbidden theme={null}
  {
    "error": "Read access required for this operation"
  }
  ```
</ResponseExample>

<ResponseExample>
  ```json 404 Not Found theme={null}
  {
    "error": "Company not found or user not authorized"
  }
  ```
</ResponseExample>

## Notes

* Requires API key with `read_access` permission
* User ID must match the authenticated user
* Results are paginated using cursor-based pagination (timestamp-based)
