Skip to content

Example of how to make a request to the adAnalytics endpoint #32

@nbro10

Description

@nbro10

I was having trouble to use the.finder method to make a request to the adAnalytics endpoint, so I'll share with you an example of how to use it

from linkedin_api.clients.restli.client import RestliClient

restli_client = RestliClient()
access_token = "my-access-token"

query_params = {'accounts': ['urn:li:sponsoredAccount:my_account'],
 'dateRange': {'end': {'day': 31, 'month': 5, 'year': 2020},
               'start': {'day': 1, 'month': 5, 'year': 2020}},
 'fields': 'impressions,pivotValues,dateRange',
 'pivots': ['CREATIVE', 'CAMPAIGN'],
 'projection': '(*,elements*(*,pivotValues(*~sponsoredCreative(content(reference)),*~sponsoredCampaign(name))))',
 'timeGranularity': 'ALL'}

response = restli_client.get(
            resource_path="/adAnalytics",
            finder_name="statistics",
            access_token=access_token,
            path_keys=None,
            query_params=query_params,
            version_string="202209",
        )

This could be used to write a proper example in the examples folder. If I have some time I'll do it.

The problem I was having was that I didn't realise that I had to pass the values to the parameters in a specific format (e.g. list of accounts, or dictionary of dictionaries for the dateRange) because I was previously using the xrestli protocol 1.0.0, which requires a different syntax.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions