### Run Tests or Examples Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Execute tests or example scripts within the activated virtual environment. For example, running the get-profile script. ```bash python3 examples/get-profile.py ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Install all necessary project dependencies using Poetry from the project root directory. ```bash poetry install ``` -------------------------------- ### Install linkedin-api-client Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Install the library using pip. Requires Python 3.7 or higher. ```sh pip install linkedin-api-client ``` -------------------------------- ### Environment Variables for Examples Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/examples/README.md These environment variables are required for running the example scripts. Ensure your .env file contains these values. ```sh ACCESS_TOKEN="your_valid_access_token" CLIENT_ID="your_app_client_id" CLIENT_SECRET="your_app_client_secret" OAUTH2_REDIRECT_URL="your_app_oauth2_redirect_url" ``` -------------------------------- ### Install Test Package Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Install the published test package from TestPyPI into a local project to verify its functionality. Adjust version as needed. ```bash python -m pip install -i https://test.pypi.org/simple linkedin-api-client==0.1.1a0 ``` -------------------------------- ### Install Poetry Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Install the Poetry dependency manager, which is used for managing project dependencies and packaging. ```bash pip install --user poetry ``` -------------------------------- ### Install Git Hooks Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Install pre-commit git hook scripts to automate code checks before commits. ```bash poetry run pre-commit install ``` -------------------------------- ### Fetch All Entities with GET_ALL Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Use this method to retrieve all entities for a given resource. It supports pagination with 'start' and 'count' query parameters. ```python response = restli_client.get_all( resource_path="/fieldsOfStudy", query_params={ "start": 0, "count": 15 }, access_token=MY_ACCESS_TOKEN, version_string="202212" ) fields_of_study = response.elements total = response.paging.total ``` -------------------------------- ### Make a Rest.li GET Request Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Use the 'get' method to fetch a specific entity from a resource. This method supports base request parameters and query tunneling. ```python response = restli_client.get( resource_path="/adAccounts/{id}" path_keys={ "id": 123 }, query_params={ "fields": "id,name" } access_token=MY_ACCESS_TOKEN, version_string="202212" ) ad_account = response.entity ``` -------------------------------- ### Simple GET Request to Fetch User Info Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Use RestliClient to make a simple GET request to fetch the current user's information. Requires a 3-legged access token with 'openid' and 'profile' scope. ```python from linkedin_api.clients.restli.client import RestliClient restli_client = RestliClient() response = restli_client.get( resource_path="/userinfo", access_token= ) print(response.entity) ``` -------------------------------- ### RestliClient.get Method Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Makes a Rest.li GET request to fetch a specified entity on a resource. Supports query tunneling and uses base request parameters. ```APIDOC ## `get (resource_path, access_token, path_keys=None, query_params=None, version_string=None)` Makes a Rest.li GET request to fetch the specified entity on a resource. This method will perform query tunneling if necessary. ### Parameters: This method only uses the [base request parameters](#base-request-parameters) defined above. ### Return value: Returns [GetResponse](#class-getresponse) object ### Example: ```python response = restli_client.get( resource_path="/adAccounts/{id}" path_keys={ "id": 123 }, query_params={ "fields": "id,name" } access_token=MY_ACCESS_TOKEN, version_string="202212" ) ad_account = response.entity ``` ``` -------------------------------- ### Tag Release Commit Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Tag the last commit with a version number and a descriptive message for release management. Example uses v0.1.0. ```bash git tag -a v0.1.0 -m "Release 0.1.0" 043cc4ea ``` -------------------------------- ### Get Two-Legged Access Token Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Retrieve a 2-legged access token using the client credential flow for accessing non-member-specific APIs. This flow must be enabled in your application's settings. ```python access_token_2l_response = auth_client.get_two_legged_access_token() ``` -------------------------------- ### Build Package Archives Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Create source archives and wheels for the package, preparing it for distribution. ```bash poetry build ``` -------------------------------- ### Clone the Project Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Clone the project repository to your local machine to begin development. ```bash git clone https://github.com/linkedin-developers/linkedin-api-python-client.git ``` -------------------------------- ### Configure Test PyPI Token Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Store the authentication token for Test PyPI in the Poetry configuration. Replace 'pypi-XXXX' with your actual token. ```bash poetry config pypi-token.test-pypi pypi-XXXX ``` -------------------------------- ### Configure PyPI Token Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Store the authentication token for the main PyPI repository in the Poetry configuration. Replace 'pypi-XXXX' with your actual token. ```bash poetry config pypi-token.pypi pypi-XXXX ``` -------------------------------- ### Bump Version (Prerelease) Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Bump the project version to a prerelease for testing purposes. Use a specific version rule for stable releases. ```bash poetry version prerelease ``` -------------------------------- ### introspect_access_token (access_token) Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Introspect a 2-legged, 3-legged or Enterprise access token to get information on status, expiry, and other details. ```APIDOC ## Method: introspect_access_token (access_token) ### Description Introspect a 2-legged, 3-legged or Enterprise access token to get information on status, expiry, and other details. ### Parameters - **access_token** (str) - Required - A 2-legged, 3-legged or Enterprise access token. ### Return Value Returns an [IntrospectTokenResponse](#class-introspecttokenresponse) object ``` -------------------------------- ### Activate Virtual Environment Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Activate the project's virtual environment using Poetry to ensure consistent development and testing environments. ```bash poetry shell ``` -------------------------------- ### Configure Test PyPI Repository Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Configure Poetry to use the Test PyPI repository for uploading and testing package releases. ```bash poetry config repositories.test-pypi https://test.pypi.org/legacy/ ``` -------------------------------- ### Initialize AuthClient Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Instantiate the AuthClient with your LinkedIn developer application credentials. Ensure your client ID, client secret, and redirect URL are correctly configured in the Developer Portal. ```python from linkedin_api.clients.auth.client import AuthClient auth_client = AuthClient(client_id=MY_CLIENT_ID, client_secret=MY_CLIENT_SECRET, redirect_url=MY_REDIRECT_URL) ``` -------------------------------- ### Publish to PyPI Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Publish the final package to the main PyPI repository after successful testing on TestPyPI. ```bash poetry publish ``` -------------------------------- ### Initialize RestliClient Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Create an instance of the RestliClient to begin making API requests. This initializes a session object for subsequent calls. ```python from linkedin_api.clients.restli.client import RestliClient restli_client = RestliClient() ``` -------------------------------- ### Upload to TestPyPI Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Publish the package to the TestPyPI repository using the previously configured token for testing the upload process. ```bash poetry publish -r test-pypi ``` -------------------------------- ### Run Pre-commit Checks Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Perform pre-commit checks on all project files to ensure code quality and consistency. ```bash poetry run pre-commit run --all-files ``` -------------------------------- ### RestliClient Constructor and Session Configuration Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Instantiate the RestliClient and configure its session object for making HTTP requests, including setting up event hooks. ```APIDOC ## Constructor An instance of the API client must be created before using. This creates a session object that will be used for making all subsequent requests. ```python from linkedin_api.clients.restli.client import RestliClient restli_client = RestliClient() ``` The Requests library [session](https://requests.readthedocs.io/en/latest/user/advanced/#session-objects) object is accessible to configure any additional global settings (e.g. configuring event hooks). ```python restli_client.session.hooks = { 'response': [do_something_fn, do_something_2_fn] } ``` ### Properties | Property | |---| | `session` | The session object used for making http requests. This is exposed to allow for additional configuration (e.g. adding custom request/response event hooks). | ``` -------------------------------- ### Push Tags to Origin Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Push all local tags, including the newly created release tag, to the remote repository. ```bash git push origin --tags ``` -------------------------------- ### Create New Resource Entity with CREATE Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Use the create method to add a new entity to a resource. The 'entity' parameter should be a dictionary representing the entity to be created. ```python response = restli_client.create( resource_path="/adAccountsV2", entity={ "name": "Test Ad Account", "type": "BUSINESS", "test": True }, access_token=MY_ACCESS_TOKEN ) created_entity_id = response.entity_id ``` -------------------------------- ### Update Dependencies Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Upgrade project dependencies to their latest compatible versions and update the poetry.lock file accordingly. ```bash poetry update ``` -------------------------------- ### Run Pytest Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Execute all project tests using the pytest framework from the project root directory. ```bash poetry run pytest ``` -------------------------------- ### create Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Makes a Rest.li CREATE request to create a new resource entity. It accepts the resource path, entity data, and access token, returning a CreateResponse object. ```APIDOC ## create ### Description Creates a new resource entity using a Rest.li CREATE request. ### Method POST (implied by Rest.li CREATE) ### Endpoint [resource_path] ### Parameters #### Path Parameters - **resource_path** (str) - Required - The path to the resource. - **access_token** (str) - Required - The access token for authentication. #### Request Body - **entity** (Dict[str,Any]) - Required - A dictionary representation of the entity to create. #### Query Parameters - **path_keys** (dict) - Optional - Additional path keys. - **query_params** (dict) - Optional - Query parameters for the request. - **version_string** (str) - Optional - The API version string. ### Request Example ```python response = restli_client.create( resource_path="/adAccountsV2", entity={ "name": "Test Ad Account", "type": "BUSINESS", "test": True }, access_token=MY_ACCESS_TOKEN ) ``` ### Response #### Success Response - Returns a [CreateResponse](#class-createresponse) object. #### Response Example ```json { "entity_id": "some_unique_id" } ``` ``` -------------------------------- ### Batch Create Entities with Rest.li Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Use batch_create to create multiple entities in a single Rest.li request. Ensure entities are provided as a list of dictionaries. ```python response = restli_client.batch_create( resource_path="/adCampaignGroups", entities=[ { account: 'urn:li:sponsoredAccount:111', name: 'CampaignGroupTest1', status: 'DRAFT' }, { account: 'urn:li:sponsoredAccount:222', name: 'CampaignGroupTest2', status: 'DRAFT' } ], access_token=MY_ACCESS_TOKEN, version_string="202212" ) created_elements = response.elements first_created_element_id = response.elements[0].id ``` -------------------------------- ### AuthClient(client_id, client_secret, redirect_url) Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Initializes the AuthClient for managing LinkedIn API authentication. Requires client credentials and an optional redirect URL. ```APIDOC ## Method: AuthClient(client_id, client_secret, redirect_url) ### Description Initializes the AuthClient for managing LinkedIn API authentication. Requires client credentials and an optional redirect URL. ### Parameters - **client_id** (str) - Required - Client ID of your developer application. This can be found on your application auth settings page in the Developer Portal. - **client_secret** (str) - Required - Client secret of your developer application. This can be found on your application auth settings page in the Developer Portal. - **redirect_url** (str) - Optional - If your integration will be using the authorization code flow to obtain 3-legged access tokens, this should be provided. This redirect URL must match one of the redirect URLs configured in the app auth settings page in the Developer Portal. ### Return Value An instance of AuthClient ``` -------------------------------- ### Find Entities with FINDER Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Use the finder method to locate entities based on specific criteria. The 'finder_name' and 'query_params' are essential for defining the search. ```python response = restli_client.finder( resource_path="/adAccounts", finder_name="search", query_params={ "search": { "status": { "values": ["ACTIVE", "DRAFT", "CANCELED"] }, "reference": { "values": ["urn:li:organization:123"] }, "test": False }, "start": 0, "count": 5 }, access_token=MY_ACCESS_TOKEN, version_string="202212" ) ad_accounts = response.elements total = response.paging.total ``` -------------------------------- ### Check Package Metadata Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/CONTRIBUTING.md Verify that the package metadata will be rendered correctly on PyPI, especially after changes to pyproject.toml. ```bash twine check dist/* ``` -------------------------------- ### batch_create Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Makes a Rest.li BATCH_CREATE request to create multiple entities in a single call. It takes a resource path, a list of entities to create, and an access token. It returns a BatchCreateResponse object. ```APIDOC ## batch_create ### Description Makes a Rest.li BATCH_CREATE request to create multiple entities in a single call. ### Method POST (Assumed based on BATCH_CREATE operation) ### Endpoint `/{resource_path}` ### Parameters #### Path Parameters - **resource_path** (string) - Required - The path of the resource to create entities for. #### Query Parameters - **version_string** (string) - Optional - The API version string. #### Request Body - **entities** (List[Dict[str,Any]]) - Required - A list of entities to create. ### Request Example ```python response = restli_client.batch_create( resource_path="/adCampaignGroups", entities=[ { account: 'urn:li:sponsoredAccount:111', name: 'CampaignGroupTest1', status: 'DRAFT' }, { account: 'urn:li:sponsoredAccount:222', name: 'CampaignGroupTest2', status: 'DRAFT' } ], access_token=MY_ACCESS_TOKEN, version_string="202212" ) ``` ### Response #### Success Response (200) - **elements** (List[Dict[str,Any]]) - A list of created elements, each with an `id`. #### Response Example ```json { "elements": [ { "id": "urn:li:adCampaignGroup:1" }, { "id": "urn:li:adCampaignGroup:2" } ] } ``` ``` -------------------------------- ### AuthClient Methods Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Provides utilities for managing OAuth2 access tokens, including generation, exchange, and introspection. ```APIDOC ## AuthClient Methods ### Description Provides utilities for managing OAuth2 access tokens, including generation, exchange, and introspection. ### Methods #### `generate_member_auth_url(scopes, state=None)` - **Description**: Generates a URL for member authentication. - **Parameters**: - `scopes` (list) - Required - A list of OAuth2 scopes. - `state` (string, optional) - An opaque value used to maintain state between the request and the callback. #### `exchange_auth_code_for_access_token(code)` - **Description**: Exchanges an authorization code for an access token. - **Parameters**: - `code` (string) - Required - The authorization code received. #### `exchange_refresh_token_for_access_token(refresh_token)` - **Description**: Exchanges a refresh token for a new access token. - **Parameters**: - `refresh_token` (string) - Required - The refresh token. #### `get_two_legged_access_token()` - **Description**: Retrieves a 2-legged OAuth2 access token. - **Parameters**: None #### `introspect_access_token(access_token)` - **Description**: Introspects an access token to get its details. - **Parameters**: - `access_token` (string) - Required - The access token to introspect. ``` -------------------------------- ### Perform a Custom Action Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Use the action method to execute custom actions on a resource that do not fit standard REST verbs. Provide the action name and any necessary parameters. ```python response = restli_client.action( resource_path="/liveAssetActions", action_name="register", action_params={ "registerLiveEventRequest": { "owner": "urn:li:person:12345", "recipes": ["urn:li:digitalmediaRecipe:feedshare-live-video"], "region": "WEST_US" } }, access_token=MY_ACCESS_TOKEN ) status_code = response.status_code ``` -------------------------------- ### Make a Rest.li BATCH_GET Request Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Use the 'batch_get' method to efficiently fetch multiple entities from a resource in a single request. This method also supports query tunneling. ```python response = restli_client.batch_get( resource_path="/adCampaignGroups", ids=[123, 456, 789], access_token=MY_ACCESS_TOKEN, version_string="202212" ) campaign_groups = response.results.items() ``` -------------------------------- ### get_all Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Makes a Rest.li GET_ALL request to fetch all entities on a resource. It utilizes base request parameters and returns a CollectionResponse object. ```APIDOC ## get_all ### Description Fetches all entities on a resource using a Rest.li GET_ALL request. ### Method GET (implied by Rest.li GET_ALL) ### Endpoint [resource_path] ### Parameters #### Path Parameters - **resource_path** (str) - Required - The path to the resource. - **access_token** (str) - Required - The access token for authentication. #### Query Parameters - **path_keys** (dict) - Optional - Additional path keys. - **query_params** (dict) - Optional - Query parameters for the request. - **version_string** (str) - Optional - The API version string. ### Request Example ```python response = restli_client.get_all( resource_path="/fieldsOfStudy", query_params={ "start": 0, "count": 15 }, access_token=MY_ACCESS_TOKEN, version_string="202212" ) ``` ### Response #### Success Response - Returns a [CollectionResponse](#class-collectionresponse) object. #### Response Example ```json { "elements": [...], "paging": { "total": 100 } } ``` ``` -------------------------------- ### finder Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Makes a Rest.li FINDER request to find entities by specified criteria. It accepts base request parameters plus a finder name and returns a CollectionResponse object. ```APIDOC ## finder ### Description Finds entities by specified criteria using a Rest.li FINDER request. ### Method GET (implied by Rest.li FINDER) ### Endpoint [resource_path] ### Parameters #### Path Parameters - **resource_path** (str) - Required - The path to the resource. - **access_token** (str) - Required - The access token for authentication. #### Query Parameters - **finder_name** (str) - Required - The Rest.li finder name. - **path_keys** (dict) - Optional - Additional path keys. - **query_params** (dict) - Optional - Query parameters for the request, including finder-specific criteria. - **version_string** (str) - Optional - The API version string. ### Request Example ```python response = restli_client.finder( resource_path="/adAccounts", finder_name="search", query_params={ "search": { "status": { "values": ["ACTIVE", "DRAFT", "CANCELED"] }, "reference": { "values": ["urn:li:organization:123"] }, "test": False }, "start": 0, "count": 5 }, access_token=MY_ACCESS_TOKEN, version_string="202212" ) ``` ### Response #### Success Response - Returns a [CollectionResponse](#class-collectionresponse) object. #### Response Example ```json { "elements": [...], "paging": { "total": 50 } } ``` ``` -------------------------------- ### Exchange Authorization Code for Access Token Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Use this method after a member has authorized your application and been redirected back to your site with an authorization code. The code is exchanged for a 3-legged access token. ```python access_token_response = auth_client.exchange_auth_code_for_access_token(code='AUTHORIZATION_CODE') ``` -------------------------------- ### Batch Find Entities with BATCH_FINDER Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md This method allows finding entities using multiple sets of criteria in a single request. The 'finder_criteria' parameter is a tuple containing the criteria name and a list of criteria objects. ```python response = restli_client.batch_finder( resource_path="/organizationAuthorizations", finder_name="authorizationActionsAndImpersonator", finder_criteria=("authorizationActions", [ { "OrganizationRoleAuthorizationAction": { actionType: "ADMINISTRATOR_READ" } }, { "OrganizationContentAuthorizationAction": { actionType: "ORGANIC_SHARE_DELETE" } } ] ), access_token=MY_ACCESS_TOKEN, version_string="202212" ) admin_read_authorizations = response.results[0].elements organic_share_delete_authorizations = response.results[1].elements ``` -------------------------------- ### batch_finder Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Makes a Rest.li BATCH_FINDER request to find entities by multiple sets of criteria. It accepts base request parameters, a finder name, and specific finder criteria, returning a BatchFinderResponse object. ```APIDOC ## batch_finder ### Description Finds entities by multiple sets of criteria using a Rest.li BATCH_FINDER request. ### Method GET (implied by Rest.li BATCH_FINDER) ### Endpoint [resource_path] ### Parameters #### Path Parameters - **resource_path** (str) - Required - The path to the resource. - **access_token** (str) - Required - The access token for authentication. #### Query Parameters - **finder_name** (str) - Required - The Rest.li batch finder name. - **finder_criteria** (Tuple[str, List[Dict[str,Any]]]) - Required - The batch finder criteria information. - **path_keys** (dict) - Optional - Additional path keys. - **query_params** (dict) - Optional - Additional query parameters. - **version_string** (str) - Optional - The API version string. ### Request Example ```python response = restli_client.batch_finder( resource_path="/organizationAuthorizations", finder_name="authorizationActionsAndImpersonator", finder_criteria=("authorizationActions", [ { "OrganizationRoleAuthorizationAction": { actionType: "ADMINISTRATOR_READ" } }, { "OrganizationContentAuthorizationAction": { actionType: "ORGANIC_SHARE_DELETE" } } ] ), access_token=MY_ACCESS_TOKEN, version_string="202212" ) ``` ### Response #### Success Response - Returns a [BatchFinderResponse](#class-batchfinderresponse) object. #### Response Example ```json { "results": [ { "elements": [...] }, { "elements": [...] } ] } ``` ``` -------------------------------- ### RestliClient.batch_get Method Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Makes a Rest.li BATCH_GET request to fetch multiple entities on a resource. Supports query tunneling and uses base request parameters along with a list of IDs. ```APIDOC ## `batch_get (resource_path, ids, access_token, path_keys=None, query_params=None, version_string=None)` Makes a Rest.li BATCH_GET request to fetch multiple entities on a resource. This method will perform query tunneling if necessary. ### Parameters: The additional parameters besides the [base request parameters](#base-request-parameters) are: | Parameter | |---| | `ids` | List[Union[str,int,Dict[str,Any]]] - Required - The list of entity ids to fetch on the resource. These will be encoded and added to the query parameters. | ### Return value: Returns a [BatchGetResponse](#class-batchgetresponse) object. ### Example: ```python response = restli_client.batch_get( resource_path="/adCampaignGroups", ids=[123, 456, 789], access_token=MY_ACCESS_TOKEN, version_string="202212" ) campaign_groups = response.results.items() ``` ``` -------------------------------- ### action Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Makes a Rest.li ACTION request to perform an action on a specified resource. This method is flexible and generally used when the action does not fit within the standard behavior defined by the other Rest.li methods. ```APIDOC ## action ### Description Makes a Rest.li ACTION request to perform an action on a specified resource. This method is flexible and generally used when the action does not fit within the standard behavior defined by the other Rest.li methods. ### Method ACTION ### Endpoint [resource_path] ### Parameters #### Path Parameters None explicitly defined. #### Query Parameters - **action_name** (str) - Required - The action method name. This will be added to the query parameters. #### Request Body - **action_params** (Dict[str,Any]) - Optional - An optional map of action parameters and their values. This will be sent in the request body. ### Request Example ```python response = restli_client.action( resource_path="/liveAssetActions", action_name="register", action_params={ "registerLiveEventRequest": { "owner": "urn:li:person:12345", "recipes": ["urn:li:digitalmediaRecipe:feedshare-live-video"], "region": "WEST_US" } }, access_token=MY_ACCESS_TOKEN ) status_code = response.status_code ``` ### Response #### Success Response (200) - **status_code** (int) - Response status code. #### Response Example (Refer to example for structure, actual response object is ActionResponse) ``` -------------------------------- ### Batch Update Entities with Rest.li Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Perform a batch update to modify multiple entities simultaneously. Ensure the 'ids' and 'entities' lists are in the same order. ```python response = restli_client.batch_update( resource_path="/campaignConversions", ids=[ { "campaign": "urn:li:sponsoredCampaign:123", "conversion": "urn:lla:llaPartnerConversion:456" }, { "campaign": "urn:li:sponsoredCampaign:123", "conversion": "urn:lla:llaPartnerConversion:789" } ], entities=[ { "campaign": "urn:li:sponsoredCampaign:123", "conversion": "urn:lla:llaPartnerConversion:456" }, { "campaign": "urn:li:sponsoredCampaign:123", "conversion": "urn:lla:llaPartnerConversion:789" } ], access_token=MY_ACCESS_TOKEN, version_string="202212" ) batch_results = response.results.items() ``` -------------------------------- ### Finder Request to Find Ad Accounts Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Use RestliClient's finder method to search for ad accounts based on criteria. Requires a 3-legged access token with 'r_ads' scope. The 'search' query parameter can be a complex object represented as a dictionary. ```python from linkedin_api.clients.restli.client import RestliClient restli_client = RestliClient() response = restli_client.finder( resource_path="/adAccounts", finder_name="search", query_params={ "search": { "status": { "values": ["ACTIVE", "DRAFT"] }, "reference": { "values": ["urn:li:organization:123"] }, "test": True } }, version_string="202212", acccess_token= ) ad_accounts = response.elements ``` -------------------------------- ### Configure Request Session Hooks Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Access the underlying Requests library session object to configure global settings, such as adding custom event hooks for responses. ```python restli_client.session.hooks = { 'response': [do_something_fn, do_something_2_fn] } ``` -------------------------------- ### Update Entity with Rest.li Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Use the update method to completely overwrite an existing entity. Provide the resource path, the entity's new value, and necessary authentication details. ```python response = restli_client.update( resource_path="/adAccountUsers/{id}", path_keys={ "id": { "account": "urn:li:sponsoredAccount:123", "user": "urn:li:person:foobar" } }, entity: { "account": "urn:li:sponsoredAccount:123", "user": "urn:li:person:foobar", "role": "VIEWER" }, access_token=MY_ACCESS_TOKEN, version_string="202212" ) status = response.status_code ``` -------------------------------- ### exchange_auth_code_for_access_token (code) Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Exchanges an authorization code for a 3-legged access token. After member authorization, the browser redirects to the provided redirect URL, setting the authorization code on the `code` query parameter. ```APIDOC ## Method: exchange_auth_code_for_access_token (code) ### Description Exchanges an authorization code for a 3-legged access token. After member authorization, the browser redirects to the provided redirect URL, setting the authorization code on the `code` query parameter. ### Parameters - **code** (str) - Required - The authorization code to exchange for an access token ### Return Value Returns an [AccessToken3LResponse](#class-accesstoken3lresponse) object ``` -------------------------------- ### RestliClient Methods Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Provides interfaces for making various types of requests to LinkedIn APIs using the Rest.li protocol. ```APIDOC ## RestliClient Methods ### Description Provides interfaces for making various types of requests to LinkedIn APIs using the Rest.li protocol. ### Methods #### `get(resource_path, access_token, path_keys=None, query_params=None, version_string=None)` - **Description**: Retrieves a resource. - **Parameters**: - `resource_path` (string) - Required - The path to the resource. - `access_token` (string) - Required - The access token for authentication. - `path_keys` (dict, optional) - Key-value pairs for path parameters. - `query_params` (dict, optional) - Key-value pairs for query parameters. - `version_string` (string, optional) - The API version string. #### `batch_get(resource_path, ids, access_token, path_keys=None, query_params=None, version_string=None)` - **Description**: Retrieves multiple resources by their IDs in a batch. - **Parameters**: - `resource_path` (string) - Required - The path to the resource. - `ids` (list) - Required - A list of resource IDs. - `access_token` (string) - Required - The access token for authentication. - `path_keys` (dict, optional) - Key-value pairs for path parameters. - `query_params` (dict, optional) - Key-value pairs for query parameters. - `version_string` (string, optional) - The API version string. #### `get_all(resource_path, access_token, path_keys=None, query_params=None, version_string=None)` - **Description**: Retrieves all resources of a given type. - **Parameters**: - `resource_path` (string) - Required - The path to the resource. - `access_token` (string) - Required - The access token for authentication. - `path_keys` (dict, optional) - Key-value pairs for path parameters. - `query_params` (dict, optional) - Key-value pairs for query parameters. - `version_string` (string, optional) - The API version string. #### `finder(resource_path, finder_name, access_token, path_keys=None, query_params=None, version_string=None)` - **Description**: Executes a specific finder method on a resource. - **Parameters**: - `resource_path` (string) - Required - The path to the resource. - `finder_name` (string) - Required - The name of the finder method. - `access_token` (string) - Required - The access token for authentication. - `path_keys` (dict, optional) - Key-value pairs for path parameters. - `query_params` (dict, optional) - Key-value pairs for query parameters. - `version_string` (string, optional) - The API version string. #### `batch_finder(resource_path, finder_name, finder_criteria, access_token, path_keys=None, query_params=None, version_string=None)` - **Description**: Executes a finder method with specific criteria on multiple resources in a batch. - **Parameters**: - `resource_path` (string) - Required - The path to the resource. - `finder_name` (string) - Required - The name of the finder method. - `finder_criteria` (dict) - Required - Criteria for the finder. - `access_token` (string) - Required - The access token for authentication. - `path_keys` (dict, optional) - Key-value pairs for path parameters. - `query_params` (dict, optional) - Key-value pairs for query parameters. - `version_string` (string, optional) - The API version string. #### `create(resource_path, entity, access_token, path_keys=None, query_params=None, version_string=None)` - **Description**: Creates a new resource. - **Parameters**: - `resource_path` (string) - Required - The path to the resource. - `entity` (dict) - Required - The entity data to create. - `access_token` (string) - Required - The access token for authentication. - `path_keys` (dict, optional) - Key-value pairs for path parameters. - `query_params` (dict, optional) - Key-value pairs for query parameters. - `version_string` (string, optional) - The API version string. #### `batch_create(resource_path, entities, access_token, path_keys=None, query_params=None, version_string=None)` - **Description**: Creates multiple resources in a batch. - **Parameters**: - `resource_path` (string) - Required - The path to the resource. - `entities` (list) - Required - A list of entity data to create. - `access_token` (string) - Required - The access token for authentication. - `path_keys` (dict, optional) - Key-value pairs for path parameters. - `query_params` (dict, optional) - Key-value pairs for query parameters. - `version_string` (string, optional) - The API version string. #### `update(resource_path, entity, access_token, path_keys=None, query_params=None, version_string=None)` - **Description**: Updates an existing resource. - **Parameters**: - `resource_path` (string) - Required - The path to the resource. - `entity` (dict) - Required - The entity data to update. - `access_token` (string) - Required - The access token for authentication. - `path_keys` (dict, optional) - Key-value pairs for path parameters. - `query_params` (dict, optional) - Key-value pairs for query parameters. - `version_string` (string, optional) - The API version string. #### `batch_update(resource_path, ids, entities, access_token, path_keys=None, query_params=None, version_string=None)` - **Description**: Updates multiple resources in a batch. - **Parameters**: - `resource_path` (string) - Required - The path to the resource. - `ids` (list) - Required - A list of resource IDs to update. - `entities` (list) - Required - A list of entity data to update. - `access_token` (string) - Required - The access token for authentication. - `path_keys` (dict, optional) - Key-value pairs for path parameters. - `query_params` (dict, optional) - Key-value pairs for query parameters. - `version_string` (string, optional) - The API version string. #### `partial_update(resource_path, patch_set_object, access_token, path_keys=None, query_params=None, version_string=None)` - **Description**: Partially updates an existing resource. - **Parameters**: - `resource_path` (string) - Required - The path to the resource. - `patch_set_object` (dict) - Required - The patch set object for partial update. - `access_token` (string) - Required - The access token for authentication. - `path_keys` (dict, optional) - Key-value pairs for path parameters. - `query_params` (dict, optional) - Key-value pairs for query parameters. - `version_string` (string, optional) - The API version string. #### `batch_partial_update(resource_path, ids, patch_set_objects, access_token, path_keys=None, query_params=None, version_string=None)` - **Description**: Partially updates multiple resources in a batch. - **Parameters**: - `resource_path` (string) - Required - The path to the resource. - `ids` (list) - Required - A list of resource IDs for partial update. - `patch_set_objects` (list) - Required - A list of patch set objects for partial update. - `access_token` (string) - Required - The access token for authentication. - `path_keys` (dict, optional) - Key-value pairs for path parameters. - `query_params` (dict, optional) - Key-value pairs for query parameters. - `version_string` (string, optional) - The API version string. #### `delete(resource_path, access_token, path_keys=None, query_params=None, version_string=None)` - **Description**: Deletes a resource. - **Parameters**: - `resource_path` (string) - Required - The path to the resource. - `access_token` (string) - Required - The access token for authentication. - `path_keys` (dict, optional) - Key-value pairs for path parameters. - `query_params` (dict, optional) - Key-value pairs for query parameters. - `version_string` (string, optional) - The API version string. #### `batch_delete(resource_path, ids, access_token, path_keys=None, query_params=None, version_string=None)` - **Description**: Deletes multiple resources by their IDs in a batch. - **Parameters**: - `resource_path` (string) - Required - The path to the resource. - `ids` (list) - Required - A list of resource IDs to delete. - `access_token` (string) - Required - The access token for authentication. - `path_keys` (dict, optional) - Key-value pairs for path parameters. - `query_params` (dict, optional) - Key-value pairs for query parameters. - `version_string` (string, optional) - The API version string. #### `action(resource_path, action_name, access_token, action_params=None, path_keys=None, query_params=None, version_string=None)` - **Description**: Executes a custom action on a resource. - **Parameters**: - `resource_path` (string) - Required - The path to the resource. - `action_name` (string) - Required - The name of the action to execute. - `access_token` (string) - Required - The access token for authentication. - `action_params` (dict, optional) - Parameters for the action. - `path_keys` (dict, optional) - Key-value pairs for path parameters. - `query_params` (dict, optional) - Key-value pairs for query parameters. - `version_string` (string, optional) - The API version string. ``` -------------------------------- ### get_two_legged_access_token () Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Use client credential flow (2-legged OAuth) to retrieve a 2-legged access token for accessing APIs that are not member-specific. Developer applications do not have the client credential flow enabled by default. ```APIDOC ## Method: get_two_legged_access_token () ### Description Use client credential flow (2-legged OAuth) to retrieve a 2-legged access token for accessing APIs that are not member-specific. Developer applications do not have the client credential flow enabled by default. ### Parameters None ### Return Value Returns an [AccessToken2LResponse](#class-accesstoken2Lresponse) object ``` -------------------------------- ### Generate Member Authorization URL Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Create a URL to redirect members for OAuth authorization. This URL includes the scopes your application requests and an optional state parameter for CSRF protection. ```python scopes = ['r_liteprofile', 'r_emailaddress'] auth_url = auth_client.generate_member_auth_url(scopes=scopes, state='YOUR_STATE_STRING') ``` -------------------------------- ### BaseAuthResponse Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md The base class for all authentication-related responses. It includes standard response data and the raw response object. ```APIDOC ## Class: BaseAuthResponse ### Description The base class for all authentication-related responses. It includes standard response data and the raw response object. ### Properties - `status_code` (int) - Response status code - `url` (str) - The final URL location of the response - `headers` (CaseInsensitiveDict) - A case-insensitive dictionary of response headers - `response` (Response) - The raw requests.Response object ``` -------------------------------- ### batch_update Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Makes a Rest.li BATCH_UPDATE request to update multiple entities in a single call. It requires the resource path, lists of IDs and entities to update, and an access token. It returns a BatchUpdateResponse object. ```APIDOC ## batch_update ### Description Makes a Rest.li BATCH_UPDATE request to update multiple entities in a single call. ### Method PUT (Assumed based on BATCH_UPDATE operation) ### Endpoint `/{resource_path}` ### Parameters #### Path Parameters - **resource_path** (string) - Required - The path of the resource to update. #### Query Parameters - **version_string** (string) - Optional - The API version string. #### Request Body - **ids** (List[Union[str,int,Dict[str,Any]]]) - Required - The ids of the entities to update. - **entities** (List[Dict[str,Any]]) - Required - The values to update the specified entities to. This should be the same order as the `ids` argument. ### Request Example ```python response = restli_client.batch_update( resource_path="/campaignConversions", ids=[ { "campaign": "urn:li:sponsoredCampaign:123", "conversion": "urn:lla:llaPartnerConversion:456" }, { "campaign": "urn:li:sponsoredCampaign:123", "conversion": "urn:lla:llaPartnerConversion:789" } ], entities=[ { "campaign": "urn:li:sponsoredCampaign:123", "conversion": "urn:lla:llaPartnerConversion:456" }, { "campaign": "urn:li:sponsoredCampaign:123", "conversion": "urn:lla:llaPartnerConversion:789" } ], access_token=MY_ACCESS_TOKEN, version_string="202212" ) ``` ### Response #### Success Response (200) - **results** (Dict[str,Any]) - A dictionary containing the results of the batch update operation. #### Response Example ```json { "results": { "urn:li:sponsoredCampaign:123:urn:lla:llaPartnerConversion:456": {"status": "SUCCESS"}, "urn:li:sponsoredCampaign:123:urn:lla:llaPartnerConversion:789": {"status": "SUCCESS"} } } ``` ``` -------------------------------- ### AccessToken3LResponse Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Represents the response for a 3-legged access token request. Includes the access token, its expiration, and optional refresh token details. ```APIDOC ## Class: AccessToken3LResponse ### Description Represents the response for a 3-legged access token request. Includes the access token, its expiration, and optional refresh token details. ### Base Class [BaseAuthResponse](#class-baseauthresponse) ### Properties - `access_token` (str) - The 3-legged access token - `expires_in` (int) - The TTL of the access token, in seconds - `refresh_token` (str) - The refresh token value. This is only present if refresh tokens are enabled for the application. - `refresh_token_expires_in` (Number) - The TTL of the refresh token, in seconds. This is only present if refresh tokens are enabled for the application. - `scope` (str) - A comma-separated list of scopes authorized by the member (e.g. "r_liteprofile,r_ads") ``` -------------------------------- ### AccessToken2LResponse Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Represents the response for a 2-legged access token request. Includes the access token and its expiration time. ```APIDOC ## Class: AccessToken2LResponse ### Description Represents the response for a 2-legged access token request. Includes the access token and its expiration time. ### Base Class [BaseAuthResponse](#class-baseauthresponse) ### Properties - `access_token` (str) - The 2-legged access token - `expires_in` (int) - The TTL of the access token, in seconds ``` -------------------------------- ### Perform Batch Delete Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Use batch_delete to remove multiple entities at once by providing a list of their IDs. This is efficient for bulk deletion operations. ```python response = restli_client.batch_delete( resource_path="/adAccounts", ids=["123", "456"], access_token=MY_ACCESS_TOKEN, version_string="202212" ) status_code = response.results["123"].status ``` -------------------------------- ### Exchange Refresh Token for Access Token Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Refresh a 3-legged access token using a refresh token. This avoids requiring the member to reauthorize your application for continued access. ```python new_access_token_response = auth_client.exchange_refresh_token_for_access_token(refresh_token='YOUR_REFRESH_TOKEN') ``` -------------------------------- ### generate_member_auth_url (scopes, state=None) Source: https://github.com/linkedin-developers/linkedin-api-python-client/blob/main/README.md Generates the member authorization URL to direct members to. Once redirected, the member will be presented with LinkedIn's OAuth consent page showing the OAuth scopes your application is requesting on behalf of the user. ```APIDOC ## Method: generate_member_auth_url (scopes, state=None) ### Description Generates the member authorization URL to direct members to. Once redirected, the member will be presented with LinkedIn's OAuth consent page showing the OAuth scopes your application is requesting on behalf of the user. ### Parameters - **scopes** (List[str]) - Required - An array of OAuth scopes (3-legged member permissions) your application is requesting on behalf of the user. - **state** (str) - Optional - An optional string that can be provided to test against CSRF attacks. ### Return Value The member authorization URL string ```