blob: beec6c23868edf226d671620ac87ce01e5cd30f6 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001# This example uses Google APIs Client for Python, you can download it here:
2# https://developers.google.com/api-client-library/python/
3
4from __future__ import print_function
5from __future__ import division
6from __future__ import absolute_import
7
8import apiclient
9
10import httplib2
11
12from oauth2client.file import Storage
13
14
15DISCOVERY_URL = (
16 'https://monorail-staging.appspot.com/_ah/api/discovery/v1/apis/'
17 '{api}/{apiVersion}/rest')
18
19
20# Get credentials to authorize http object
21storage = Storage('Your-local-credential-file')
22credentials = storage.get()
23http = credentials.authorize(httplib2.Http())
24
25# Create monorail client using Google APIs Client for Python
26monorail = apiclient.discovery.build(
27 'monorail', 'v1',
28 discoveryServiceUrl=DISCOVERY_URL,
29 http=http)
30
31# Create a chromium project issue
32insert_response = monorail.issues().insert(projectId='chromium', body={
33 'summary': 'Strange grinding sound',
34 'status': 'Untriaged',
35 'cc': [{'name':'user1@example.org'}, {'name':'user2@example.org'}]
36}).execute()
37
38new_issue_id = insert_response['id']
39
40# Get all issues of chromium
41list_response = monorail.issues().list(projectId='chromium').execute()
42issues = list_response['items']
43total_issues = list_response['totalResults']