universal-mcp-applications 0.1.29__py3-none-any.whl → 0.1.30rc1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of universal-mcp-applications might be problematic. Click here for more details.

@@ -1,768 +0,0 @@
1
- import json
2
- from collections.abc import Callable
3
- from typing import Any, Literal
4
-
5
- from loguru import logger
6
- from universal_mcp.applications.application import APIApplication
7
- from universal_mcp.integrations import Integration
8
-
9
-
10
- class UnipileApp(APIApplication):
11
- """
12
- Application for interacting with the LinkedIn API via Unipile.
13
- Handles operations related to chats, messages, accounts, posts, and user profiles.
14
- """
15
-
16
- def __init__(self, integration: Integration) -> None:
17
- """
18
- Initialize the LinkedinApp.
19
-
20
- Args:
21
- integration: The integration configuration containing credentials and other settings.
22
- It is expected that the integration provides the 'x-api-key'
23
- via headers in `integration.get_credentials()`, e.g.,
24
- `{"headers": {"x-api-key": "YOUR_API_KEY"}}`.
25
- """
26
- super().__init__(name="unipile", integration=integration)
27
-
28
- self._base_url = None
29
-
30
- @property
31
- def base_url(self) -> str:
32
- """
33
- A property that lazily constructs and caches the Unipile API base URL from 'subdomain' and 'port' credentials. Built on first access and used by all API methods, it raises a ValueError if credentials are missing. This is the default construction, unlike the setter which allows manual override.
34
- """
35
- if not self._base_url:
36
- credentials = self.integration.get_credentials()
37
- subdomain = credentials.get("subdomain")
38
- port = credentials.get("port")
39
- if not subdomain or not port:
40
- logger.error(
41
- "UnipileApp: Missing 'subdomain' or 'port' in integration credentials."
42
- )
43
- raise ValueError(
44
- "Integration credentials must include 'subdomain' and 'port'."
45
- )
46
- self._base_url = f"https://{subdomain}.unipile.com:{port}"
47
- return self._base_url
48
-
49
- @base_url.setter
50
- def base_url(self, base_url: str) -> None:
51
- """
52
- Sets or overrides the Unipile API's base URL. This setter allows manually changing the endpoint, bypassing the default URL that is dynamically constructed from integration credentials. It is primarily intended for testing against different environments or for custom deployments.
53
-
54
- Args:
55
- base_url: The new base URL to set.
56
- """
57
- self._base_url = base_url
58
- logger.info(f"UnipileApp: Base URL set to {self._base_url}")
59
-
60
- def _get_headers(self) -> dict[str, str]:
61
- """
62
- Get the headers for Unipile API requests.
63
- Overrides the base class method to use X-Api-Key.
64
- """
65
- if not self.integration:
66
- logger.warning(
67
- "UnipileApp: No integration configured, returning empty headers."
68
- )
69
- return {}
70
-
71
- credentials = self.integration.get_credentials()
72
-
73
- api_key = (
74
- credentials.get("api_key")
75
- or credentials.get("API_KEY")
76
- or credentials.get("apiKey")
77
- )
78
-
79
- if not api_key:
80
- logger.error(
81
- "UnipileApp: API key not found in integration credentials for Unipile."
82
- )
83
- return { # Or return minimal headers if some calls might not need auth (unlikely for Unipile)
84
- "Content-Type": "application/json",
85
- "Cache-Control": "no-cache",
86
- }
87
-
88
- logger.debug("UnipileApp: Using X-Api-Key for authentication.")
89
- return {
90
- "x-api-key": api_key,
91
- "Content-Type": "application/json",
92
- "Cache-Control": "no-cache", # Often good practice for APIs
93
- }
94
-
95
- def list_all_chats(
96
- self,
97
- unread: bool | None = None,
98
- cursor: str | None = None,
99
- before: str | None = None, # ISO 8601 UTC datetime
100
- after: str | None = None, # ISO 8601 UTC datetime
101
- limit: int | None = None, # 1-250
102
- account_type: str | None = None,
103
- account_id: str | None = None, # Comma-separated list of ids
104
- ) -> dict[str, Any]:
105
- """
106
- Retrieves a paginated list of all chat conversations across linked accounts. Supports filtering by unread status, date range, account provider, and specific account IDs, distinguishing it from functions listing messages within a single chat.
107
-
108
- Args:
109
- unread: Filter for unread chats only or read chats only.
110
- cursor: Pagination cursor for the next page of entries.
111
- before: Filter for items created before this ISO 8601 UTC datetime (exclusive).
112
- after: Filter for items created after this ISO 8601 UTC datetime (exclusive).
113
- limit: Number of items to return (1-250).
114
- account_type: Filter by provider (e.g., "linkedin").
115
- account_id: Filter by specific account IDs (comma-separated).
116
-
117
- Returns:
118
- A dictionary containing a list of chat objects and a pagination cursor.
119
-
120
- Raises:
121
- httpx.HTTPError: If the API request fails.
122
-
123
- Tags:
124
- linkedin, chat, list, messaging, api
125
- """
126
- url = f"{self.base_url}/api/v1/chats"
127
- params: dict[str, Any] = {}
128
- if unread is not None:
129
- params["unread"] = unread
130
- if cursor:
131
- params["cursor"] = cursor
132
- if before:
133
- params["before"] = before
134
- if after:
135
- params["after"] = after
136
- if limit:
137
- params["limit"] = limit
138
- if account_type:
139
- params["account_type"] = account_type
140
- if account_id:
141
- params["account_id"] = account_id
142
-
143
- response = self._get(url, params=params)
144
- return response.json()
145
-
146
- def list_chat_messages(
147
- self,
148
- chat_id: str,
149
- cursor: str | None = None,
150
- before: str | None = None, # ISO 8601 UTC datetime
151
- after: str | None = None, # ISO 8601 UTC datetime
152
- limit: int | None = None, # 1-250
153
- sender_id: str | None = None,
154
- ) -> dict[str, Any]:
155
- """
156
- Retrieves messages from a specific chat identified by `chat_id`. Supports pagination and filtering by date or sender. Unlike `list_all_messages`, which fetches from all chats, this function targets the contents of a single conversation.
157
-
158
- Args:
159
- chat_id: The ID of the chat to retrieve messages from.
160
- cursor: Pagination cursor for the next page of entries.
161
- before: Filter for items created before this ISO 8601 UTC datetime (exclusive).
162
- after: Filter for items created after this ISO 8601 UTC datetime (exclusive).
163
- limit: Number of items to return (1-250).
164
- sender_id: Filter messages from a specific sender ID.
165
-
166
- Returns:
167
- A dictionary containing a list of message objects and a pagination cursor.
168
-
169
- Raises:
170
- httpx.HTTPError: If the API request fails.
171
-
172
- Tags:
173
- linkedin, chat, message, list, messaging, api
174
- """
175
- url = f"{self.base_url}/api/v1/chats/{chat_id}/messages"
176
- params: dict[str, Any] = {}
177
- if cursor:
178
- params["cursor"] = cursor
179
- if before:
180
- params["before"] = before
181
- if after:
182
- params["after"] = after
183
- if limit:
184
- params["limit"] = limit
185
- if sender_id:
186
- params["sender_id"] = sender_id
187
-
188
- response = self._get(url, params=params)
189
- return response.json()
190
-
191
- def send_chat_message(
192
- self,
193
- chat_id: str,
194
- text: str,
195
- ) -> dict[str, Any]:
196
- """
197
- Sends a text message to a specific chat conversation using its `chat_id`. This function creates a new message via a POST request, distinguishing it from read-only functions like `list_chat_messages`. It returns the API's response, which typically confirms the successful creation of the message.
198
-
199
- Args:
200
- chat_id: The ID of the chat where the message will be sent.
201
- text: The text content of the message.
202
- attachments: Optional list of attachment objects to include with the message.
203
-
204
- Returns:
205
- A dictionary containing the ID of the sent message.
206
-
207
- Raises:
208
- httpx.HTTPError: If the API request fails.
209
-
210
- Tags:
211
- linkedin, chat, message, send, create, messaging, api
212
- """
213
- url = f"{self.base_url}/api/v1/chats/{chat_id}/messages"
214
- payload: dict[str, Any] = {"text": text}
215
-
216
- response = self._post(url, data=payload)
217
- return response.json()
218
-
219
- def retrieve_chat(
220
- self, chat_id: str, account_id: str | None = None
221
- ) -> dict[str, Any]:
222
- """
223
- Retrieves a single chat's details using its Unipile or provider-specific ID. Requires an `account_id` when using a provider ID for context. This function is distinct from `list_all_chats`, which returns a collection, by targeting one specific conversation.
224
-
225
- Args:
226
- chat_id: The Unipile or provider ID of the chat.
227
- account_id: Mandatory if the chat_id is a provider ID. Specifies the account context.
228
-
229
- Returns:
230
- A dictionary containing the chat object details.
231
-
232
- Raises:
233
- httpx.HTTPError: If the API request fails.
234
-
235
- Tags:
236
- linkedin, chat, retrieve, get, messaging, api
237
- """
238
- url = f"{self.base_url}/api/v1/chats/{chat_id}"
239
- params: dict[str, Any] = {}
240
- if account_id:
241
- params["account_id"] = account_id
242
-
243
- response = self._get(url, params=params)
244
- return response.json()
245
-
246
- def list_all_messages(
247
- self,
248
- cursor: str | None = None,
249
- before: str | None = None, # ISO 8601 UTC datetime
250
- after: str | None = None, # ISO 8601 UTC datetime
251
- limit: int | None = None, # 1-250
252
- sender_id: str | None = None,
253
- account_id: str | None = None,
254
- ) -> dict[str, Any]:
255
- """
256
- Retrieves a paginated list of messages from all chats associated with the account(s). Unlike `list_chat_messages` which targets a specific conversation, this function provides a global message view, filterable by sender, account, and date range.
257
-
258
- Args:
259
- cursor: Pagination cursor.
260
- before: Filter for items created before this ISO 8601 UTC datetime.
261
- after: Filter for items created after this ISO 8601 UTC datetime.
262
- limit: Number of items to return (1-250).
263
- sender_id: Filter messages from a specific sender.
264
- account_id: Filter messages from a specific linked account.
265
-
266
- Returns:
267
- A dictionary containing a list of message objects and a pagination cursor.
268
-
269
- Raises:
270
- httpx.HTTPError: If the API request fails.
271
-
272
- Tags:
273
- linkedin, message, list, all_messages, messaging, api
274
- """
275
- url = f"{self.base_url}/api/v1/messages"
276
- params: dict[str, Any] = {}
277
- if cursor:
278
- params["cursor"] = cursor
279
- if before:
280
- params["before"] = before
281
- if after:
282
- params["after"] = after
283
- if limit:
284
- params["limit"] = limit
285
- if sender_id:
286
- params["sender_id"] = sender_id
287
- if account_id:
288
- params["account_id"] = account_id
289
-
290
- response = self._get(url, params=params)
291
- return response.json()
292
-
293
- def list_all_accounts(
294
- self,
295
- cursor: str | None = None,
296
- limit: int | None = None, # 1-259 according to spec
297
- ) -> dict[str, Any]:
298
- """
299
- Retrieves a paginated list of all social media accounts linked to the Unipile service. This is crucial for obtaining the `account_id` required by other methods to specify which user account should perform an action, like sending a message or retrieving user-specific posts.
300
-
301
- Args:
302
- cursor: Pagination cursor.
303
- limit: Number of items to return (1-259).
304
-
305
- Returns:
306
- A dictionary containing a list of account objects and a pagination cursor.
307
-
308
- Raises:
309
- httpx.HTTPError: If the API request fails.
310
-
311
- Tags:
312
- linkedin, account, list, unipile, api, important
313
- """
314
- url = f"{self.base_url}/api/v1/accounts"
315
- params: dict[str, Any] = {}
316
- if cursor:
317
- params["cursor"] = cursor
318
- if limit:
319
- params["limit"] = limit
320
-
321
- response = self._get(url, params=params)
322
- return response.json()
323
-
324
- def retrieve_linked_account(
325
- self,
326
- account_id: str,
327
- ) -> dict[str, Any]:
328
- """
329
- Retrieves details for a specific account linked to Unipile using its ID. It fetches metadata about the connection itself (e.g., a linked LinkedIn account), differentiating it from `retrieve_user_profile` which fetches a user's profile from the external platform.
330
-
331
- Args:
332
- account_id: The ID of the account to retrieve.
333
-
334
- Returns:
335
- A dictionary containing the account object details.
336
-
337
- Raises:
338
- httpx.HTTPError: If the API request fails.
339
-
340
- Tags:
341
- linkedin, account, retrieve, get, unipile, api, important
342
- """
343
- url = f"{self.base_url}/api/v1/accounts/{account_id}"
344
- response = self._get(url)
345
- return response.json()
346
-
347
- def list_profile_posts(
348
- self,
349
- identifier: str, # User or Company provider internal ID
350
- account_id: str, # Account to perform the request from (REQUIRED)
351
- cursor: str | None = None,
352
- limit: int | None = None, # 1-100 (spec says max 250)
353
- is_company: bool | None = None,
354
- ) -> dict[str, Any]:
355
- """
356
- Retrieves a paginated list of posts from a specific user or company profile using their provider ID. An authorizing `account_id` is required, and the `is_company` flag must specify the entity type, distinguishing this from `retrieve_post` which fetches a single post by its own ID.
357
-
358
- Args:
359
- identifier: The entity's provider internal ID (LinkedIn ID).
360
- account_id: The ID of the Unipile account to perform the request from (REQUIRED).
361
- cursor: Pagination cursor.
362
- limit: Number of items to return (1-100, as per Unipile example, though spec allows up to 250).
363
- is_company: Boolean indicating if the identifier is for a company.
364
-
365
- Returns:
366
- A dictionary containing a list of post objects and pagination details.
367
-
368
- Raises:
369
- httpx.HTTPError: If the API request fails.
370
-
371
- Tags:
372
- linkedin, post, list, user_posts, company_posts, content, api, important
373
- """
374
- url = f"{self.base_url}/api/v1/users/{identifier}/posts"
375
- params: dict[str, Any] = {"account_id": account_id}
376
- if cursor:
377
- params["cursor"] = cursor
378
- if limit:
379
- params["limit"] = limit
380
- if is_company is not None:
381
- params["is_company"] = is_company
382
-
383
- response = self._get(url, params=params)
384
- return response.json()
385
-
386
- def retrieve_own_profile(
387
- self,
388
- account_id: str,
389
- ) -> dict[str, Any]:
390
- """
391
- Retrieves the profile details for the user associated with the specified Unipile account ID. This function targets the API's 'me' endpoint to fetch the authenticated user's profile, distinct from `retrieve_user_profile` which fetches profiles of other users by their public identifier.
392
-
393
- Args:
394
- account_id: The ID of the Unipile account to use for retrieving the profile (REQUIRED).
395
-
396
- Returns:
397
- A dictionary containing the user's profile details.
398
-
399
- Raises:
400
- httpx.HTTPError: If the API request fails.
401
-
402
- Tags:
403
- linkedin, user, profile, me, retrieve, get, api
404
- """
405
- url = f"{self.base_url}/api/v1/users/me"
406
- params: dict[str, Any] = {"account_id": account_id}
407
- response = self._get(url, params=params)
408
- return response.json()
409
-
410
- def retrieve_post(
411
- self,
412
- post_id: str,
413
- account_id: str,
414
- ) -> dict[str, Any]:
415
- """
416
- Fetches a specific post's details by its unique ID, requiring an `account_id` for authorization. Unlike `list_profile_posts`, which retrieves a collection of posts from a user or company profile, this function targets one specific post and returns its full object.
417
-
418
- Args:
419
- post_id: The ID of the post to retrieve.
420
- account_id: The ID of the Unipile account to perform the request from (REQUIRED).
421
-
422
- Returns:
423
- A dictionary containing the post details.
424
-
425
- Raises:
426
- httpx.HTTPError: If the API request fails.
427
-
428
- Tags:
429
- linkedin, post, retrieve, get, content, api, important
430
- """
431
- url = f"{self.base_url}/api/v1/posts/{post_id}"
432
- params: dict[str, Any] = {"account_id": account_id}
433
- response = self._get(url, params=params)
434
- return response.json()
435
-
436
- def list_post_comments(
437
- self,
438
- post_id: str,
439
- account_id: str,
440
- comment_id: str | None = None,
441
- cursor: str | None = None,
442
- limit: int | None = None,
443
- ) -> dict[str, Any]:
444
- """
445
- Fetches comments for a specific post using an `account_id` for authorization. Providing an optional `comment_id` retrieves threaded replies instead of top-level comments. This read-only operation contrasts with `create_post_comment`, which publishes new comments, and `list_content_reactions`, which retrieves 'likes'.
446
-
447
- Args:
448
- post_id: The social ID of the post.
449
- account_id: The ID of the Unipile account to perform the request from (REQUIRED).
450
- comment_id: If provided, retrieves replies to this comment ID instead of top-level comments.
451
- cursor: Pagination cursor.
452
- limit: Number of comments to return. (OpenAPI spec shows type string, passed as string if provided).
453
-
454
- Returns:
455
- A dictionary containing a list of comment objects and pagination details.
456
-
457
- Raises:
458
- httpx.HTTPError: If the API request fails.
459
-
460
- Tags:
461
- linkedin, post, comment, list, content, api, important
462
- """
463
- url = f"{self.base_url}/api/v1/posts/{post_id}/comments"
464
- params: dict[str, Any] = {"account_id": account_id}
465
- if cursor:
466
- params["cursor"] = cursor
467
- if limit is not None:
468
- params["limit"] = str(limit)
469
- if comment_id:
470
- params["comment_id"] = comment_id
471
-
472
- response = self._get(url, params=params)
473
- return response.json()
474
-
475
- def create_post(
476
- self,
477
- account_id: str,
478
- text: str,
479
- mentions: list[dict[str, Any]] | None = None,
480
- external_link: str | None = None,
481
- ) -> dict[str, Any]:
482
- """
483
- Publishes a new top-level post from a specified account, including text, user mentions, and an external link. This function creates original content, distinguishing it from `create_post_comment` which adds replies to existing posts.
484
-
485
- Args:
486
- account_id: The ID of the Unipile account that will author the post (added as query parameter).
487
- text: The main text content of the post.
488
- mentions: Optional list of dictionaries, each representing a mention.
489
- Example: `[{"entity_urn": "urn:li:person:...", "start_index": 0, "end_index": 5}]`
490
- external_link: Optional string, an external URL that should be displayed within a card.
491
-
492
- Returns:
493
- A dictionary containing the ID of the created post.
494
-
495
- Raises:
496
- httpx.HTTPError: If the API request fails.
497
-
498
- Tags:
499
- linkedin, post, create, share, content, api, important
500
- """
501
- url = f"{self.base_url}/api/v1/posts"
502
-
503
- params: dict[str, str] = {
504
- "account_id": account_id,
505
- "text": text,
506
- }
507
-
508
- if mentions:
509
- params["mentions"] = mentions
510
- if external_link:
511
- params["external_link"] = external_link
512
-
513
- response = self._post(url, data=params)
514
- return response.json()
515
-
516
- def list_content_reactions(
517
- self,
518
- post_id: str,
519
- account_id: str,
520
- comment_id: str | None = None,
521
- cursor: str | None = None,
522
- limit: int | None = None,
523
- ) -> dict[str, Any]:
524
- """
525
- Retrieves a paginated list of reactions for a given post or, optionally, a specific comment. This read-only operation uses the provided `account_id` for the request, distinguishing it from the `create_reaction` function which adds new reactions.
526
-
527
- Args:
528
- post_id: The social ID of the post.
529
- account_id: The ID of the Unipile account to perform the request from .
530
- comment_id: If provided, retrieves reactions for this comment ID.
531
- cursor: Pagination cursor.
532
- limit: Number of reactions to return (1-100, spec max 250).
533
-
534
- Returns:
535
- A dictionary containing a list of reaction objects and pagination details.
536
-
537
- Raises:
538
- httpx.HTTPError: If the API request fails.
539
-
540
- Tags:
541
- linkedin, post, reaction, list, like, content, api
542
- """
543
- url = f"{self.base_url}/api/v1/posts/{post_id}/reactions"
544
- params: dict[str, Any] = {"account_id": account_id}
545
- if cursor:
546
- params["cursor"] = cursor
547
- if limit:
548
- params["limit"] = limit
549
- if comment_id:
550
- params["comment_id"] = comment_id
551
-
552
- response = self._get(url, params=params)
553
- return response.json()
554
-
555
- def create_post_comment(
556
- self,
557
- post_social_id: str,
558
- account_id: str,
559
- text: str,
560
- comment_id: str | None = None, # If provided, replies to a specific comment
561
- mentions_body: list[dict[str, Any]] | None = None,
562
- ) -> dict[str, Any]:
563
- """
564
- Publishes a comment on a specified post. By providing an optional `comment_id`, it creates a threaded reply to an existing comment instead of a new top-level one. This function's dual capability distinguishes it from `list_post_comments`, which only retrieves comments and their replies.
565
-
566
- Args:
567
- post_social_id: The social ID of the post to comment on.
568
- account_id: The ID of the Unipile account performing the comment.
569
- text: The text content of the comment (passed as a query parameter).
570
- Supports Unipile's mention syntax like "Hey {{0}}".
571
- comment_id: Optional ID of a specific comment to reply to instead of commenting on the post.
572
- mentions_body: Optional list of mention objects for the request body if needed.
573
-
574
- Returns:
575
- A dictionary, likely confirming comment creation. (Structure depends on actual API response)
576
-
577
- Raises:
578
- httpx.HTTPError: If the API request fails.
579
-
580
- Tags:
581
- linkedin, post, comment, create, content, api, important
582
- """
583
- url = f"{self.base_url}/api/v1/posts/{post_social_id}/comments"
584
- params: dict[str, Any] = {
585
- "account_id": account_id,
586
- "text": text,
587
- }
588
-
589
- if comment_id:
590
- params["comment_id"] = comment_id
591
-
592
- if mentions_body:
593
- params = {"mentions": mentions_body}
594
-
595
- response = self._post(url, data=params)
596
-
597
- try:
598
- return response.json()
599
- except json.JSONDecodeError:
600
- return {
601
- "status": response.status_code,
602
- "message": "Comment action processed.",
603
- }
604
-
605
- def create_reaction(
606
- self,
607
- post_social_id: str,
608
- reaction_type: Literal[
609
- "like", "celebrate", "love", "insightful", "funny", "support"
610
- ],
611
- account_id: str,
612
- comment_id: str | None = None,
613
- ) -> dict[str, Any]:
614
- """
615
- Adds a specified reaction (e.g., 'like', 'love') to a LinkedIn post or, optionally, to a specific comment. This function performs a POST request to create the reaction, differentiating it from `list_content_reactions` which only retrieves existing ones.
616
-
617
- Args:
618
- post_social_id: The social ID of the post or comment to react to.
619
- reaction_type: The type of reaction. Valid values are "like", "celebrate", "love", "insightful", "funny", or "support".
620
- account_id: Account ID of the Unipile account performing the reaction.
621
- comment_id: Optional ID of a specific comment to react to instead of the post.
622
-
623
- Returns:
624
- A dictionary, likely confirming the reaction. (Structure depends on actual API response)
625
-
626
- Raises:
627
- httpx.HTTPError: If the API request fails.
628
-
629
- Tags:
630
- linkedin, post, reaction, create, like, content, api, important
631
- """
632
- url = f"{self.base_url}/api/v1/posts/reaction"
633
-
634
- params: dict[str, str] = {
635
- "account_id": account_id,
636
- "post_id": post_social_id,
637
- "reaction_type": reaction_type,
638
- }
639
-
640
- if comment_id:
641
- params["comment_id"] = comment_id
642
-
643
- response = self._post(url, data=params)
644
-
645
- try:
646
- return response.json()
647
- except json.JSONDecodeError:
648
- return {
649
- "status": response.status_code,
650
- "message": "Reaction action processed.",
651
- }
652
-
653
- def search(
654
- self,
655
- account_id: str,
656
- category: Literal["people", "companies", "posts", "jobs"],
657
- cursor: str | None = None,
658
- limit: int | None = None,
659
- keywords: str | None = None,
660
- date_posted: Literal["past_day", "past_week", "past_month"] | None = None,
661
- sort_by: Literal["relevance", "date"] = "relevance",
662
- minimum_salary_value: int = 40,
663
- ) -> dict[str, Any]:
664
- """
665
- Performs a comprehensive LinkedIn search for people, companies, posts, or jobs using keywords.
666
- Supports pagination and targets either the classic or Sales Navigator API for posts.
667
- For people, companies, and jobs, it uses the classic API.
668
-
669
- Args:
670
- account_id: The ID of the Unipile account to perform the search from (REQUIRED).
671
- category: Type of search to perform. Valid values are "people", "companies", "posts", or "jobs".
672
- cursor: Pagination cursor for the next page of entries.
673
- limit: Number of items to return (up to 50 for Classic search).
674
- keywords: Keywords to search for.
675
- date_posted: Filter by when the post was posted (posts only). Valid values are "past_day", "past_week", or "past_month".
676
- sort_by: How to sort the results (for posts and jobs). Valid values are "relevance" or "date".
677
- minimum_salary_value: The minimum salary to filter for (jobs only).
678
-
679
- Returns:
680
- A dictionary containing search results and pagination details.
681
-
682
- Raises:
683
- httpx.HTTPError: If the API request fails.
684
- ValueError: If the category is empty.
685
-
686
- Tags:
687
- linkedin, search, people, companies, posts, jobs, api, important
688
- """
689
- if not category:
690
- raise ValueError("Category cannot be empty.")
691
-
692
- url = f"{self.base_url}/api/v1/linkedin/search"
693
-
694
- params: dict[str, Any] = {"account_id": account_id}
695
- if cursor:
696
- params["cursor"] = cursor
697
- if limit is not None:
698
- params["limit"] = limit
699
-
700
- payload: dict[str, Any] = {"api": "classic", "category": category}
701
-
702
- if keywords:
703
- payload["keywords"] = keywords
704
-
705
- if category == "posts":
706
- if date_posted:
707
- payload["date_posted"] = date_posted
708
- if sort_by:
709
- payload["sort_by"] = sort_by
710
-
711
- elif category == "jobs":
712
- payload["minimum_salary"] = {
713
- "currency": "USD",
714
- "value": minimum_salary_value,
715
- }
716
- if sort_by:
717
- payload["sort_by"] = sort_by
718
-
719
- response = self._post(url, params=params, data=payload)
720
- return self._handle_response(response)
721
-
722
- def retrieve_user_profile(
723
- self,
724
- identifier: str,
725
- account_id: str,
726
- ) -> dict[str, Any]:
727
- """
728
- Retrieves a specific LinkedIn user's profile using their public or internal ID, authorized via the provided `account_id`. Unlike `retrieve_own_profile`, which fetches the authenticated user's details, this function targets and returns data for any specified third-party user profile on the platform.
729
-
730
- Args:
731
- identifier: Can be the provider's internal id OR the provider's public id of the requested user.For example, for https://www.linkedin.com/in/manojbajaj95/, the identifier is "manojbajaj95".
732
-
733
- account_id: The ID of the Unipile account to perform the request from (REQUIRED).
734
-
735
- Returns:
736
- A dictionary containing the user's profile details.
737
-
738
- Raises:
739
- httpx.HTTPError: If the API request fails.
740
-
741
- Tags:
742
- linkedin, user, profile, retrieve, get, api, important
743
- """
744
- url = f"{self.base_url}/api/v1/users/{identifier}"
745
- params: dict[str, Any] = {"account_id": account_id}
746
- response = self._get(url, params=params)
747
- return self._handle_response(response)
748
-
749
- def list_tools(self) -> list[Callable]:
750
- return [
751
- self.list_all_chats,
752
- self.list_chat_messages,
753
- self.send_chat_message,
754
- self.retrieve_chat,
755
- self.list_all_messages,
756
- self.list_all_accounts,
757
- self.retrieve_linked_account,
758
- self.list_profile_posts,
759
- self.retrieve_own_profile,
760
- self.retrieve_user_profile,
761
- self.retrieve_post,
762
- self.list_post_comments,
763
- self.create_post,
764
- self.list_content_reactions,
765
- self.create_post_comment,
766
- self.create_reaction,
767
- self.search,
768
- ]