# Get DM for Linkedin (`addeus/get-dm`) Actor

Export LinkedIn DMs and conversation history to JSON. Uses internal API interception for fast, accurate extraction without HTML rendering. Captures participants, timestamps, and text. Perfect for CRM sync and backups.

- **URL**: https://apify.com/addeus/get-dm.md
- **Developed by:** [Addeus](https://apify.com/addeus) (community)
- **Categories:** Social media, Automation, Developer tools
- **Stats:** 22 total users, 0 monthly users, 100.0% runs succeeded, 1 bookmarks
- **User rating**: No ratings yet

## Pricing

$0.005 / actor start

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## LinkedIn Get Direct Messages Actor

Apify actor that retrieves all direct messages from your LinkedIn messaging inbox with comprehensive conversation details, participant information, and message metadata.

### Features

- Retrieves all conversations from LinkedIn messaging inbox
- Extracts detailed information for each conversation:
  - Thread URL
  - Participant LinkedIn profile URL
  - Last message content
  - Sender information (firstname, lastname, occupation, company)
  - Message direction (from me or from contact)
  - Read/unread status
  - Message timestamp
- Uses LinkedIn session cookies for authentication
- Follows the same authentication pattern as other Apify LinkedIn actors
- Multi-selector strategy for robust element detection
- Automatic scrolling to load all conversations

### Input

The actor requires the following input parameters:

#### Required

- **liAtCookie** (string, required): Your LinkedIn `li_at` cookie value for authentication
  - Example: `"AQEDATEtZ..."`
  - How to get it: Open LinkedIn in your browser, open Developer Tools (F12), go to Application/Storage → Cookies → https://www.linkedin.com, and copy the value of the `li_at` cookie

#### Optional

- **jsessionid** (string, optional): Your LinkedIn `JSESSIONID` cookie value for additional authentication
  - Example: `"ajax:1234567890123456789"`
  - Found in the same location as `li_at` cookie

- **userAgent** (string, optional): Custom user agent string
  - Default: `"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"`
  - Use a recent Chrome/Edge user agent for best results

### Input Example

```json
{
    "liAtCookie": "AQEDATEtZ...",
    "jsessionid": "ajax:1234567890123456789",
    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
}
```

### Output

The actor outputs a single dataset item containing:

- **success** (boolean): Whether the operation was successful
- **message** (string): Status message
- **conversationCount** (number): Total number of conversations retrieved
- **conversations** (array): Array of conversation objects
- **timestamp** (string): ISO timestamp of when the data was retrieved

#### Conversation Object Structure

Each conversation in the `conversations` array contains:

- **threadUrl** (string): Direct URL to the conversation thread
- **linkedInUrl** (string): LinkedIn profile URL of the contact
- **message** (string): Content of the last message in the thread
- **lastMessageFromUrl** (string): Profile URL of the last message sender
- **firstname** (string): First name of the contact
- **lastname** (string): Last name of the contact
- **occupation** (string): Current job title/occupation of the contact
- **companyName** (string): Company name where the contact works
- **isLastMessageFromMe** (boolean): Whether the last message was sent by you
- **readStatus** (boolean): Whether the conversation has been read (true = read, false = unread)
- **lastMessageDate** (string): Human-readable date of the last message (e.g., "2h", "Yesterday", "Sep 01")
- **timestamp** (string): ISO timestamp of the last message (if available)

### Output Example

```json
{
    "success": true,
    "message": "Successfully retrieved 25 conversations",
    "conversationCount": 25,
    "conversations": [
        {
            "threadUrl": "https://www.linkedin.com/messaging/thread/2-MGFjMTExN2YtOWI3NS00NmJlLWEyNjMtNjhlZDFjZWZkNDVkXzEwMA==/",
            "linkedInUrl": "https://www.linkedin.com/in/ACoAABJnny0ButYTqma7Tmq-SqQDoFJVPpqBIr8",
            "message": "Salut Pierre, j'ai vu que tu as jeté un œil à Hootsuite...",
            "lastMessageFromUrl": "https://www.linkedin.com/in/ACoAABJnny0ButYTqma7Tmq-SqQDoFJVPpqBIr8",
            "firstname": "Charlotte",
            "lastname": "Clemens",
            "occupation": "VP of Sales Enterprise Europe - Hootsuite & Talkwalker",
            "companyName": "Hootsuite",
            "isLastMessageFromMe": false,
            "readStatus": true,
            "lastMessageDate": "Sep 01",
            "timestamp": "2024-09-01T10:30:00.000Z"
        }
    ],
    "timestamp": "2025-01-15T14:23:45.123Z"
}
```

### How It Works

1. **Authentication**: Sets LinkedIn session cookies (`li_at` and optionally `JSESSIONID`)
2. **Navigation**: Opens LinkedIn messaging page (https://www.linkedin.com/messaging/)
3. **Conversation Loading**: Automatically scrolls to load all available conversations
4. **Data Extraction**: For each conversation:
   - Extracts thread URL, message content, timestamp, and read status from the messaging list
   - Navigates to the contact's profile page
   - Extracts detailed profile information (name, occupation, company)
5. **Output**: Returns all conversation data in a structured format

### Performance

- **Execution Time**: ~2-5 seconds per conversation (due to profile information extraction)
- **Scrolling**: Automatically scrolls up to 5 times to load all conversations
- **Anti-Detection**: Includes user-agent spoofing and webdriver masking

### Error Handling

The actor will throw an error if:

- The `liAtCookie` parameter is missing
- LinkedIn returns a non-200 status code
- The messaging page fails to load
- Authentication fails (invalid cookies)

### Notes

- **Cookie Expiration**: LinkedIn cookies expire periodically. If the actor fails, try getting fresh cookies from your browser.
- **Rate Limiting**: LinkedIn may rate-limit requests if you run the actor too frequently. Use reasonable delays between runs.
- **Profile Privacy**: Some profile information may not be available if the contact has restricted their profile visibility.
- **Headless Mode**: The actor runs in headless mode by default for better performance.

### Security

- Never share your `li_at` cookie publicly as it grants full access to your LinkedIn account
- Use Apify's secret input feature to store cookies securely
- Cookies are only used for authentication and are not stored or logged

### Use Cases

- Export LinkedIn conversations for backup
- Analyze messaging patterns and response rates
- Integrate LinkedIn messaging data with CRM systems
- Monitor unread messages and follow-ups
- Generate reports on networking activities

### Related Actors

- **linkedin-send-dm**: Send direct messages to LinkedIn profiles
- **linkedin-like-post**: Automatically like LinkedIn posts
- **linkedin-comment-post**: Automatically comment on LinkedIn posts
- **linkedin-quote-post**: Repost LinkedIn content with your thoughts

### Support

For issues or questions, please contact the development team.

### Version History

- **1.0.0** (2025-01-15): Initial release
  - Basic conversation retrieval
  - Profile information extraction
  - Read status detection
  - Multi-selector strategies for robust element detection

# Actor input Schema

## `liAtCookie` (type: `string`):

Your LinkedIn li\_at cookie value for authentication (REQUIRED)

## `userAgent` (type: `string`):

Custom user agent string (REQUIRED)

## `maxConversations` (type: `integer`):

Maximum number of conversations to extract (default: 50)

## Actor input object example

```json
{
  "liAtCookie": "AQEDATEtZ...",
  "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
  "maxConversations": 50
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("addeus/get-dm").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("addeus/get-dm").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call addeus/get-dm --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,addeus/get-dm"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/hpdJNgel2kUXiAPGs/builds/zbLhgVNRYyBckvaHc/openapi.json
