-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_ads.py
More file actions
38 lines (30 loc) · 1.03 KB
/
create_ads.py
File metadata and controls
38 lines (30 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from linkedin_api.clients.restli.client import RestliClient
bearer_token = 'Your Bearer Token'
ACCESS_TOKEN = bearer_token
# ACCESS_TOKEN = os.getenv("ACCESS_TOKEN")
if ACCESS_TOKEN is None:
raise Exception(
'A valid access token must be defined in the /examples/.env file under the variable name "ACCESS_TOKEN"'
)
AD_ACCOUNTS_RESOURCE = "/adAccounts"
AD_ACCOUNTS_ENTITY_RESOURCE = "/adAccounts/{id}"
API_VERSION = "202309"
restli_client = RestliClient()
restli_client.session.hooks["response"].append(lambda r: r.raise_for_status())
"""
Create a test ad account
"""
create_response = restli_client.create(
resource_path=AD_ACCOUNTS_RESOURCE,
entity={
"name": "Test Ad Account",
"reference": "urn:li:organization:123",
"status": "DRAFT",
"type": "BUSINESS",
"test": True,
},
access_token=ACCESS_TOKEN,
version_string=API_VERSION,
)
ad_account_id = create_response.entity_id
print(f"Successfully created ad account: {ad_account_id}\n")