-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathimport_catalog_inline.py
More file actions
executable file
·49 lines (40 loc) · 1.23 KB
/
Copy pathimport_catalog_inline.py
File metadata and controls
executable file
·49 lines (40 loc) · 1.23 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
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python3
""" Inline import catalog items using Retail API
"""
from google.cloud import retail
from google.oauth2 import service_account
SERVICE_ACCOUNT_FILE = "<path to service account json file>"
PROJECT_NUM = "<project # or id>"
SCOPES = ['https://www.googleapis.com/auth/cloud-platform']
credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE, scopes=SCOPES)
client = retail.ProductServiceClient(credentials=credentials)
products = {
"products": [
{
"id": "123",
"title": "Steamed Hams",
"description": "Bulk Lot of Steamed Hams",
"categories": ["Food","Steamed & Canned"],
"price_info": {
"price": 149.95,
"currency_code": "USD"
}
},
{
"id": "456",
"title": "Canned Yams",
"description": "Bulk Lot of Canned Yams",
"categories": ["Food","Steamed & Canned"],
"price_info": {
"price": 89.95,
"currency_code": "USD"
}
}
]
}
request = {
"parent": 'projects/' + PROJECT_NUM + '/locations/global/catalogs/default_catalog/branches/0',
"input_config": {"product_inline_source": products}
}
response = client.import_products(request)