1
2 from io import StringIO
3 import urllib
4 import json
5 import requests
6 import math
7 import time
8
10 """
11 AnalyticsClient provides the python based language binding to the https based API of Zoho Analytics.
12 """
13
14 CLIENT_VERSION = "2.4.0"
15 COMMON_ENCODE_CHAR = "UTF-8"
16
17 - def __init__(self, client_id, client_secret, refresh_token):
18 """
19 Creates a new C{AnalyticsClient} instance.
20 @param client_id: User client id for OAUth
21 @type client_id:string
22 @param client_secret: User client secret for OAuth
23 @type client_secret:string
24 @param refresh_token: User's refresh token for OAUth).
25 @type refresh_token:string
26 """
27
28 self.proxy = False
29 self.proxy_host = None
30 self.proxy_port = None
31 self.proxy_user_name = None
32 self.proxy_password = None
33
34 self.accounts_server_url = "https://@@ACCOUNTS_URL"
35 self.analytics_server_url = "https://@@ANALYTICS_URL"
36
37 self.client_id = client_id
38 self.client_secret = client_secret
39 self.refresh_token = refresh_token
40 self.access_token = None
41
43 """
44 Returns a new C{OrgAPI} instance.
45 @param org_id: The id of the organization.
46 @type org_id:string
47 """
48 org_instance = AnalyticsClient.OrgAPI(self, org_id)
49 return org_instance
50
52 """
53 Returns a new C{WorkspaceAPI} instance.
54 @param org_id: The id of the organization.
55 @type org_id:string
56 @param workspace_id: The id of the workspace.
57 @type workspace_id:string
58 """
59 workspace_instance = AnalyticsClient.WorkspaceAPI(self, org_id, workspace_id)
60 return workspace_instance
61
63 """
64 Returns a new C{ViewAPI} instance.
65 @param org_id: The id of the organization.
66 @type org_id:string
67 @param workspace_id: The id of the workspace.
68 @type workspace_id:string
69 @param view_id: The id of the view.
70 @type view_id:string
71 """
72 view_instance = AnalyticsClient.ViewAPI(self, org_id, workspace_id, view_id)
73 return view_instance
74
76 """
77 Returns a new C{BulkAPI} instance.
78 @param org_id: The id of the organization.
79 @type org_id:string
80 @param workspace_id: The id of the workspace.
81 @type workspace_id:string
82 """
83 data_instance = AnalyticsClient.BulkAPI(self, org_id, workspace_id)
84 return data_instance
85
86
88 """
89 Returns list of all accessible organizations.
90 @return: Organization list.
91 @rtype:list
92 @raise ServerError: If the server has received the request but did not process the request
93 due to some error.
94 @raise ParseError: If the server has responded but client was not able to parse the response.
95 """
96 endpoint = "/restapi/v2/orgs"
97 response = self.send_api_request("GET", endpoint, None, None)
98 return response["data"]["orgs"]
99
101 """
102 Returns list of all accessible workspaces.
103 @return: Workspace list.
104 @rtype:list
105 @raise ServerError: If the server has received the request but did not process the request
106 due to some error.
107 @raise ParseError: If the server has responded but client was not able to parse the response.
108 """
109 endpoint = "/restapi/v2/workspaces"
110 response = self.send_api_request("GET", endpoint, None, None)
111 return response["data"]
112
114 """
115 Returns list of owned workspaces.
116 @return: Workspace list.
117 @rtype:list
118 @raise ServerError: If the server has received the request but did not process the request
119 due to some error.
120 @raise ParseError: If the server has responded but client was not able to parse the response.
121 """
122 endpoint = "/restapi/v2/workspaces/owned"
123 response = self.send_api_request("GET", endpoint, None, None)
124 return response["data"]["workspaces"]
125
127 """
128 Returns list of shared workspaces.
129 @return: Workspace list.
130 @rtype:list
131 @raise ServerError: If the server has received the request but did not process the request
132 due to some error.
133 @raise ParseError: If the server has responded but client was not able to parse the response.
134 """
135 endpoint = "/restapi/v2/workspaces/shared"
136 response = self.send_api_request("GET", endpoint, None, None)
137 return response["data"]["workspaces"]
138
140 """
141 Returns list of recently accessed views.
142 @return: View list.
143 @rtype:list
144 @raise ServerError: If the server has received the request but did not process the request
145 due to some error.
146 @raise ParseError: If the server has responded but client was not able to parse the response.
147 """
148 endpoint = "/restapi/v2/recentviews"
149 response = self.send_api_request("GET", endpoint, None, None)
150 return response["data"]["views"]
151
153 """
154 Returns list of all accessible dashboards.
155 @return: Dashboard list.
156 @rtype:list
157 @raise ServerError: If the server has received the request but did not process the request
158 due to some error.
159 @raise ParseError: If the server has responded but client was not able to parse the response.
160 """
161 endpoint = "/restapi/v2/dashboards"
162 response = self.send_api_request("GET", endpoint, None, None)
163 return response["data"]
164
166 """
167 Returns list of owned dashboards.
168 @return: Dashboard list.
169 @rtype:list
170 @raise ServerError: If the server has received the request but did not process the request
171 due to some error.
172 @raise ParseError: If the server has responded but client was not able to parse the response.
173 """
174 endpoint = "/restapi/v2/dashboards/owned"
175 response = self.send_api_request("GET", endpoint, None, None)
176 return response["data"]["views"]
177
179 """
180 Returns list of shared dashboards.
181 @return: Dashboard list.
182 @rtype:list
183 @raise ServerError: If the server has received the request but did not process the request
184 due to some error.
185 @raise ParseError: If the server has responded but client was not able to parse the response.
186 """
187 endpoint = "/restapi/v2/dashboards/shared"
188 response = self.send_api_request("GET", endpoint, None, None)
189 return response["data"]["views"]
190
192 """
193 Returns details of the specified workspace.
194 @param workspace_id: Id of the workspace.
195 @type workspace_id: string
196 @raise ServerError: If the server has received the request but did not process the request due to some error.
197 @raise ParseError: If the server has responded but client was not able to parse the response.
198 @return: Workspace details.
199 @rtype:dictionary
200 """
201 endpoint = "/restapi/v2/workspaces/" + workspace_id
202 response = self.send_api_request("GET", endpoint, None, None)
203 return response["data"]["workspaces"]
204
206 """
207 Returns details of the specified view.
208 @param view_id: Id of the view.
209 @type view_id: string
210 @param config: Contains any additional control parameters. Can be C{None}.
211 @type config:dictionary
212 @raise ServerError: If the server has received the request but did not process the request due to some error.
213 @raise ParseError: If the server has responded but client was not able to parse the response.
214 @return: View details.
215 @rtype:dictionary
216 """
217 endpoint = "/restapi/v2/views/" + view_id
218 response = self.send_api_request("GET", endpoint, config, None)
219 return response["data"]["views"]
220
221
223 """
224 OrgAPI contains organization level operations.
225 """
227 self.ac = ac
228 self.request_headers = {}
229 self.request_headers["ZANALYTICS-ORGID"] = org_id
230
232 """
233 Create a blank workspace in the specified organization.
234 @param workspace_name: The name of the workspace.
235 @type workspace_name:string
236 @param config: Contains any additional control parameters. Can be C{None}.
237 @type config:dictionary
238 @raise ServerError: If the server has received the request but did not process the request due to some error.
239 @raise ParseError: If the server has responded but client was not able to parse the response.
240 @return: Created workspace id.
241 @rtype:string
242 """
243 config["workspaceName"] = workspace_name
244 endpoint = "/restapi/v2/workspaces/"
245 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers)
246 return int(response["data"]["workspaceId"])
247
249 """
250 Returns list of admins for a specified organization.
251 @raise ServerError: If the server has received the request but did not process the request due to some error.
252 @raise ParseError: If the server has responded but client was not able to parse the response.
253 @return: Organization admin list.
254 @rtype:list
255 """
256 endpoint = "/restapi/v2/orgadmins"
257 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
258 return response["data"]["orgAdmins"]
259
261 """
262 Returns list of users for the specified organization.
263 @raise ServerError: If the server has received the request but did not process the request due to some error.
264 @raise ParseError: If the server has responded but client was not able to parse the response.
265 @return: User list.
266 @rtype:list
267 """
268 endpoint = "/restapi/v2/users"
269 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
270 return response["data"]["users"]
271
272 - def add_users(self, email_ids, config = {}):
273 """
274 Add users to the specified organization.
275 @param email_ids: The email address of the users to be added.
276 @type email_ids:list
277 @param config: Contains any additional control parameters. Can be C{None}.
278 @type config:dictionary
279 @raise ServerError: If the server has received the request but did not process the request due to some error.
280 @raise ParseError: If the server has responded but client was not able to parse the response.
281 """
282 config["emailIds"] = email_ids
283 endpoint = "/restapi/v2/users"
284 self.ac.send_api_request("POST", endpoint, config, self.request_headers)
285
287 """
288 Remove users from the specified organization.
289 @param email_ids: The email address of the users to be removed.
290 @type email_ids:list
291 @param config: Contains any additional control parameters. Can be C{None}.
292 @type config:dictionary
293 @raise ServerError: If the server has received the request but did not process the request due to some error.
294 @raise ParseError: If the server has responded but client was not able to parse the response.
295 """
296 config["emailIds"] = email_ids
297 endpoint = "/restapi/v2/users"
298 self.ac.send_api_request("DELETE", endpoint, config, self.request_headers)
299
301 """
302 Activate users in the specified organization.
303 @param email_ids: The email address of the users to be activated.
304 @type email_ids:list
305 @param config: Contains any additional control parameters. Can be C{None}.
306 @type config:dictionary
307 @raise ServerError: If the server has received the request but did not process the request due to some error.
308 @raise ParseError: If the server has responded but client was not able to parse the response.
309 """
310 config["emailIds"] = email_ids
311 endpoint = "/restapi/v2/users/active"
312 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
313
315 """
316 Deactivate users in the specified organization.
317 @param email_ids: The email address of the users to be deactivated.
318 @type email_ids:list
319 @param config: Contains any additional control parameters. Can be C{None}.
320 @type config:dictionary
321 @raise ServerError: If the server has received the request but did not process the request due to some error.
322 @raise ParseError: If the server has responded but client was not able to parse the response.
323 """
324 config["emailIds"] = email_ids
325 endpoint = "/restapi/v2/users/inactive"
326 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
327
329 """
330 Change role for the specified users.
331 @param email_ids: The email address of the users to be deactivated.
332 @type email_ids:list
333 @param role: New role for the users.
334 @type role:string
335 @param config: Contains any additional control parameters. Can be C{None}.
336 @type config:dictionary
337 @raise ServerError: If the server has received the request but did not process the request due to some error.
338 @raise ParseError: If the server has responded but client was not able to parse the response.
339 """
340 config["emailIds"] = email_ids
341 config["role"] = role
342 endpoint = "/restapi/v2/users/role"
343 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
344
346 """
347 Returns subscription details of the specified organization.
348 @raise ServerError: If the server has received the request but did not process the request due to some error.
349 @raise ParseError: If the server has responded but client was not able to parse the response.
350 @return: Subscription details.
351 @rtype:dictionary
352 """
353 endpoint = "/restapi/v2/subscription"
354 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
355 return response["data"]["subscription"]
356
357
359 """
360 Returns resource usage details of the specified organization.
361 @raise ServerError: If the server has received the request but did not process the request due to some error.
362 @raise ParseError: If the server has responded but client was not able to parse the response.
363 @return: Resource details.
364 @rtype:dictionary
365 """
366 endpoint = "/restapi/v2/resources"
367 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
368 return response["data"]["resourceDetails"]
369
389
390
392 """
393 WorkspaceAPI contains workspace level operations.
394 """
395 - def __init__(self, ac, org_id, workspace_id):
396 self.ac = ac
397 self.endpoint = "/restapi/v2/workspaces/" + workspace_id
398 self.request_headers = {}
399 self.request_headers["ZANALYTICS-ORGID"] = org_id
400
401 - def copy(self, new_workspace_name, config = {}, dest_org_id = None):
402 """
403 Copy the specified workspace from one organization to another or within the organization.
404 @param new_workspace_name: Name of the new workspace.
405 @type new_workspace_name: string
406 @param config: Contains any additional control parameters. Can be C{None}.
407 @type config:dictionary
408 @param dest_org_id: Id of the organization where the destination workspace is present. Can be C{None}.
409 @type dest_org_id: string
410 @raise ServerError: If the server has received the request but did not process the request due to some error.
411 @raise ParseError: If the server has responded but client was not able to parse the response.
412 @return: Copied workspace id.
413 @rtype:string
414 """
415 config["newWorkspaceName"] = new_workspace_name
416 headers = self.request_headers.copy()
417 if bool(dest_org_id):
418 headers["ZANALYTICS-DEST-ORGID"] = dest_org_id
419 response = self.ac.send_api_request("POST", self.endpoint, config, headers)
420 return int(response["data"]["workspaceId"])
421
422 - def rename(self, workspace_name, config = {}):
423 """
424 Rename a specified workspace in the organization.
425 @param workspace_name: New name for the workspace.
426 @type workspace_name: string
427 @param config: Contains any additional control parameters. Can be C{None}.
428 @type config:dictionary
429 @raise ServerError: If the server has received the request but did not process the request due to some error.
430 @raise ParseError: If the server has responded but client was not able to parse the response.
431 """
432 config["workspaceName"] = workspace_name
433 response = self.ac.send_api_request("PUT", self.endpoint, config, self.request_headers)
434
436 """
437 Delete a specified workspace in the organization.
438 @raise ServerError: If the server has received the request but did not process the request due to some error.
439 @raise ParseError: If the server has responded but client was not able to parse the response.
440 """
441 response = self.ac.send_api_request("DELETE", self.endpoint, None, self.request_headers)
442
444 """
445 Returns the secret key of the specified workspace.
446 @param config: Contains any additional control parameters. Can be C{None}.
447 @type config:dictionary
448 @raise ServerError: If the server has received the request but did not process the request due to some error.
449 @raise ParseError: If the server has responded but client was not able to parse the response.
450 @return: Workspace secret key.
451 @rtype:string
452 """
453 endpoint = self.endpoint + "/secretkey"
454 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers)
455 return response["data"]["workspaceKey"]
456
458 """
459 Adds a specified workspace as favorite.
460 @raise ServerError: If the server has received the request but did not process the request due to some error.
461 @raise ParseError: If the server has responded but client was not able to parse the response.
462 """
463 endpoint = self.endpoint + "/favorite"
464 response = self.ac.send_api_request("POST", endpoint, None, self.request_headers)
465
467 """
468 Remove a specified workspace from favorite.
469 @raise ServerError: If the server has received the request but did not process the request due to some error.
470 @raise ParseError: If the server has responded but client was not able to parse the response.
471 """
472 endpoint = self.endpoint + "/favorite"
473 response = self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
474
476 """
477 Adds a specified workspace as default.
478 @raise ServerError: If the server has received the request but did not process the request due to some error.
479 @raise ParseError: If the server has responded but client was not able to parse the response.
480 """
481 endpoint = self.endpoint + "/default"
482 response = self.ac.send_api_request("POST", endpoint, None, self.request_headers)
483
485 """
486 Remove a specified workspace from default.
487 @raise ServerError: If the server has received the request but did not process the request due to some error.
488 @raise ParseError: If the server has responded but client was not able to parse the response.
489 """
490 endpoint = self.endpoint + "/default"
491 response = self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
492
494 """
495 Returns list of admins for the specified workspace.
496 @raise ServerError: If the server has received the request but did not process the request due to some error.
497 @raise ParseError: If the server has responded but client was not able to parse the response.
498 @return: Workspace admin list.
499 @rtype:list
500 """
501 endpoint = self.endpoint + "/admins"
502 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
503 return response["data"]["workspaceAdmins"]
504
506 """
507 Add admins for the specified workspace.
508 @param email_ids: The email address of the admin users to be added.
509 @type email_ids: list
510 @param config: Contains any additional control parameters. Can be C{None}.
511 @type config:dictionary
512 @raise ServerError: If the server has received the request but did not process the request due to some error.
513 @raise ParseError: If the server has responded but client was not able to parse the response.
514 """
515 config["emailIds"] = email_ids
516 endpoint = self.endpoint + "/admins"
517 self.ac.send_api_request("POST", endpoint, config, self.request_headers)
518
520 """
521 Remove admins from the specified workspace.
522 @param email_ids: The email address of the admin users to be removed.
523 @type email_ids: list
524 @param config: Contains any additional control parameters. Can be C{None}.
525 @type config:dictionary
526 @raise ServerError: If the server has received the request but did not process the request due to some error.
527 @raise ParseError: If the server has responded but client was not able to parse the response.
528 """
529 config["emailIds"] = email_ids
530 endpoint = self.endpoint + "/admins"
531 self.ac.send_api_request("DELETE", endpoint, config, self.request_headers)
532
534 """
535 Returns shared details of the specified workspace.
536 @raise ServerError: If the server has received the request but did not process the request due to some error.
537 @raise ParseError: If the server has responded but client was not able to parse the response.
538 @return: Workspace share info.
539 @rtype:dictionary
540 """
541 endpoint = self.endpoint + "/share"
542 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
543 return response["data"]
544
545 - def share_views(self, view_ids, email_ids, permissions, config = {}):
546 """
547 Share views to the specified users.
548 @param view_ids: View ids which to be shared.
549 @type view_ids: list
550 @param email_ids: The email address of the users to whom the views need to be shared.
551 @type email_ids: list
552 @param permissions: Contains permission details.
553 @type permissions: dictionary
554 @param config: Contains any additional control parameters. Can be C{None}.
555 @type config:dictionary
556 @raise ServerError: If the server has received the request but did not process the request due to some error.
557 @raise ParseError: If the server has responded but client was not able to parse the response.
558 """
559 config["viewIds"] = view_ids
560 config["emailIds"] = email_ids
561 config["permissions"] = permissions
562 endpoint = self.endpoint + "/share"
563 self.ac.send_api_request("POST", endpoint, config, self.request_headers)
564
566 """
567 Remove shared views for the specified users.
568 @param view_ids: View ids whose sharing needs to be removed.
569 @type view_ids: list
570 @param email_ids: The email address of the users to whom the sharing need to be removed.
571 @type email_ids: list
572 @param config: Contains any additional control parameters. Can be C{None}.
573 @type config:dictionary
574 @raise ServerError: If the server has received the request but did not process the request due to some error.
575 @raise ParseError: If the server has responded but client was not able to parse the response.
576 """
577 config["emailIds"] = email_ids
578 if view_ids != None:
579 config["viewIds"] = view_ids
580 endpoint = self.endpoint + "/share"
581 self.ac.send_api_request("DELETE", endpoint, config, self.request_headers)
582
584 """
585 Returns shared details of the specified views.
586 @param view_ids: View ids for which sharing details are required.
587 @type view_ids: list
588 @raise ServerError: If the server has received the request but did not process the request due to some error.
589 @raise ParseError: If the server has responded but client was not able to parse the response.
590 @return: Shared information.
591 @rtype:list
592 """
593 config = {}
594 config["viewIds"] = view_ids
595 endpoint = self.endpoint + "/share/shareddetails"
596 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers)
597 return response["data"]["sharedDetails"]
598
600 """
601 Returns list of all accessible folders for the specified workspace.
602 @raise ServerError: If the server has received the request but did not process the request due to some error.
603 @raise ParseError: If the server has responded but client was not able to parse the response.
604 @return: Folder list.
605 @rtype:list
606 """
607 endpoint = self.endpoint + "/folders"
608 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
609 return response["data"]["folders"]
610
612 """
613 Create a folder in the specified workspace.
614 @param folder_name: Name of the folder to be created.
615 @type folder_name: string
616 @param config: Contains any additional control parameters. Can be C{None}.
617 @type config:dictionary
618 @raise ServerError: If the server has received the request but did not process the request due to some error.
619 @raise ParseError: If the server has responded but client was not able to parse the response.
620 @return: Created folder id.
621 @rtype:string
622 """
623 config["folderName"] = folder_name
624 endpoint = self.endpoint + "/folders"
625 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers)
626 return int(response["data"]["folderId"])
627
629 """
630 Returns list of all accessible views for the specified workspace.
631 @param config: Contains any additional control parameters. Can be C{None}.
632 @type config:dictionary
633 @raise ServerError: If the server has received the request but did not process the request due to some error.
634 @raise ParseError: If the server has responded but client was not able to parse the response.
635 @return: View list.
636 @rtype:list
637 """
638 endpoint = self.endpoint + "/views"
639 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers)
640 return response["data"]["views"]
641
643 """
644 Create a table in the specified workspace.
645 @param table_design: Table structure.
646 @type table_design: dictionary
647 @raise ServerError: If the server has received the request but did not process the request due to some error.
648 @raise ParseError: If the server has responded but client was not able to parse the response.
649 @return: created table id.
650 @rtype:string
651 """
652 config = {}
653 config["tableDesign"] = table_design
654 endpoint = self.endpoint + "/tables"
655 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers)
656 return int(response["data"]["viewId"])
657
659 """
660 Create a new query table in the workspace.
661 @param sql_query: SQL query to construct the query table.
662 @type sql_query: string
663 @param query_table_name: Name of the query table to be created.
664 @type query_table_name: string
665 @param config: Contains any additional control parameters. Can be C{None}.
666 @type config:dictionary
667 @raise ServerError: If the server has received the request but did not process the request due to some error.
668 @raise ParseError: If the server has responded but client was not able to parse the response.
669 @return: created table id.
670 @rtype:string
671 """
672 config["sqlQuery"] = sql_query
673 config["queryTableName"] = query_table_name
674 endpoint = self.endpoint + "/querytables"
675 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers)
676 return int(response["data"]["viewId"])
677
679 """
680 Update the mentioned query table in the workspace.
681 @param view_id: Id of the query table to be updated.
682 @type view_id: string
683 @param sql_query: New SQL query to be updated.
684 @type sql_query: string
685 @param config: Contains any additional control parameters. Can be C{None}.
686 @type config:dictionary
687 @raise ServerError: If the server has received the request but did not process the request due to some error.
688 @raise ParseError: If the server has responded but client was not able to parse the response.
689 """
690 config["sqlQuery"] = sql_query
691 endpoint = self.endpoint + "/querytables/" + view_id
692 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
693
694 - def copy_views(self, view_ids, dest_workspace_id, config = {}, dest_org_id = None):
695 """
696 Copy the specified views from one workspace to another workspace.
697 @param view_ids: The id of the views to be copied.
698 @type view_ids: list
699 @param dest_workspace_id: The destination workspace id.
700 @type dest_workspace_id: string
701 @param dest_org_id: Id of the organization where the destination workspace is present. Can be C{None}.
702 @type dest_org_id: string
703 @param config: Contains any additional control parameters. Can be C{None}.
704 @type config:dictionary
705 @raise ServerError: If the server has received the request but did not process the request due to some error.
706 @raise ParseError: If the server has responded but client was not able to parse the response.
707 @return: View list.
708 @rtype:list
709 """
710 config["viewIds"] = view_ids
711 config["destWorkspaceId"] = dest_workspace_id
712 endpoint = self.endpoint + "/views/copy"
713 headers = self.request_headers.copy()
714 if bool(dest_org_id):
715 headers["ZANALYTICS-DEST-ORGID"] = dest_org_id
716 response = self.ac.send_api_request("POST", endpoint, config, headers)
717 return response["data"]["views"]
718
720 """
721 Enable workspace to the specified white label domain.
722 @raise ServerError: If the server has received the request but did not process the request due to some error.
723 @raise ParseError: If the server has responded but client was not able to parse the response.
724 """
725 endpoint = self.endpoint + "/wlaccess"
726 response = self.ac.send_api_request("POST", endpoint, None, self.request_headers)
727
729 """
730 Disable workspace from the specified white label domain.
731 @raise ServerError: If the server has received the request but did not process the request due to some error.
732 @raise ParseError: If the server has responded but client was not able to parse the response.
733 """
734 endpoint = self.endpoint + "/wlaccess"
735 response = self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
736
738 """
739 Rename a specified folder in the workspace.
740 @param folder_id: Id of the folder.
741 @type folder_id: string
742 @param folder_name: New name for the folder.
743 @type folder_name: string
744 @param config: Contains any additional control parameters. Can be C{None}.
745 @type config:dictionary
746 @raise ServerError: If the server has received the request but did not process the request due to some error.
747 @raise ParseError: If the server has responded but client was not able to parse the response.
748 """
749 config["folderName"] = folder_name
750 endpoint = self.endpoint + "/folders/" + folder_id
751 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
752
754 """
755 Delete a specified folder in the workspace.
756 @param folder_id: Id of the folder to be deleted.
757 @type folder_id: string
758 @raise ServerError: If the server has received the request but did not process the request due to some error.
759 @raise ParseError: If the server has responded but client was not able to parse the response.
760 """
761 endpoint = self.endpoint + "/folders/" + folder_id
762 self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
763
765 """
766 Returns list of groups for the specified workspace.
767 @raise ServerError: If the server has received the request but did not process the request due to some error.
768 @raise ParseError: If the server has responded but client was not able to parse the response.
769 @return: Group list.
770 @rtype:list
771 """
772 endpoint = self.endpoint + "/groups"
773 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
774 return response["data"]["groups"]
775
776 - def create_group(self, group_name, email_ids, config = {}):
777 """
778 Create a group in the specified workspace.
779 @param group_name: Name of the group.
780 @type group_name: string
781 @param email_ids: The email address of the users to be added to the group.
782 @type email_ids: list
783 @param config: Contains any additional control parameters. Can be C{None}.
784 @type config:dictionary
785 @raise ServerError: If the server has received the request but did not process the request due to some error.
786 @raise ParseError: If the server has responded but client was not able to parse the response.
787 @return: Created group id.
788 @rtype:string
789 """
790 config["groupName"] = group_name
791 config["emailIds"] = email_ids
792 endpoint = self.endpoint + "/groups"
793 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers)
794 return int(response["data"]["groupId"])
795
797 """
798 Get the details of the specified group.
799 @param group_id: Id of the group.
800 @type group_id: string
801 @raise ServerError: If the server has received the request but did not process the request due to some error.
802 @raise ParseError: If the server has responded but client was not able to parse the response.
803 @return: Details of the specified group.
804 @rtype:dictionary
805 """
806 endpoint = self.endpoint + "/groups/" + group_id
807 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
808 return response["data"]["groups"]
809
811 """
812 Rename a specified group.
813 @param group_id: Id of the group.
814 @type group_id: string
815 @param group_name: New name for the group.
816 @type group_name: string
817 @param config: Contains any additional control parameters. Can be C{None}.
818 @type config:dictionary
819 @raise ServerError: If the server has received the request but did not process the request due to some error.
820 @raise ParseError: If the server has responded but client was not able to parse the response.
821 """
822 config["groupName"] = group_name
823 endpoint = self.endpoint + "/groups/" + group_id
824 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
825
827 """
828 Delete a specified group.
829 @param group_id: The id of the group.
830 @type group_id: string
831 @raise ServerError: If the server has received the request but did not process the request due to some error.
832 @raise ParseError: If the server has responded but client was not able to parse the response.
833 """
834 endpoint = self.endpoint + "/groups/" + group_id
835 self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
836
838 """
839 Add users to the specified group.
840 @param group_id: Id of the group.
841 @type group_id: string
842 @param email_ids: The email address of the users to be added to the group.
843 @type email_ids: list
844 @param config: Contains any additional control parameters. Can be C{None}.
845 @type config:dictionary
846 @raise ServerError: If the server has received the request but did not process the request due to some error.
847 @raise ParseError: If the server has responded but client was not able to parse the response.
848 """
849 config["emailIds"] = email_ids
850 endpoint = self.endpoint + "/groups/" + group_id + "/members"
851 self.ac.send_api_request("POST", endpoint, config, self.request_headers)
852
854 """
855 Remove users from the specified group.
856 @param group_id: Id of the group.
857 @type group_id: string
858 @param email_ids: The email address of the users to be removed from the group.
859 @type email_ids: list
860 @param config: Contains any additional control parameters. Can be C{None}.
861 @type config:dictionary
862 @raise ServerError: If the server has received the request but did not process the request due to some error.
863 @raise ParseError: If the server has responded but client was not able to parse the response.
864 """
865 config["emailIds"] = email_ids
866 endpoint = self.endpoint + "/groups/" + group_id + "/members"
867 self.ac.send_api_request("DELETE", endpoint, config, self.request_headers)
868
870 """
871 Create a slideshow in the specified workspace.
872 @param slide_name: Name of the slideshow to be created.
873 @type slide_name: string
874 @param view_ids: Ids of the view to be included in the slideshow.
875 @type view_ids: list
876 @param config: Contains any additional control parameters. Can be C{None}.
877 @type config:dictionary
878 @raise ServerError: If the server has received the request but did not process the request due to some error.
879 @raise ParseError: If the server has responded but client was not able to parse the response.
880 @return: Id of the created slideshow.
881 @rtype:string
882 """
883 endpoint = self.endpoint + "/slides"
884 config["slideName"] = slide_name
885 config["viewIds"] = view_ids
886 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers)
887 return int(response["data"]["slideId"])
888
890 """
891 Update details of the specified slideshow.
892 @param slide_id: The id of the slideshow.
893 @type slide_id: string
894 @param config - Contains the control configurations.
895 @type config:dictionary
896 @raise ServerError: If the server has received the request but did not process the request due to some error.
897 @raise ParseError: If the server has responded but client was not able to parse the response.
898 """
899 endpoint = self.endpoint + "/slides/" + slide_id
900 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
901
903 """
904 Delete a specified slideshow in the workspace.
905 @param slide_id: Id of the slideshow.
906 @type slide_id: string
907 @raise ServerError: If the server has received the request but did not process the request due to some error.
908 @raise ParseError: If the server has responded but client was not able to parse the response.
909 """
910 endpoint = self.endpoint + "/slides/" + slide_id
911 self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
912
914 """
915 Returns list of slideshows for the specified workspace.
916 @raise ServerError: If the server has received the request but did not process the request due to some error.
917 @raise ParseError: If the server has responded but client was not able to parse the response.
918 @return: Slideshow list.
919 @rtype:list
920 """
921 endpoint = self.endpoint + "/slides"
922 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
923 return response["data"]["slideshows"]
924
926 """
927 Returns slide URL to access the specified slideshow.
928 @param slide_id: Id of the slideshow.
929 @type slide_id: string
930 @param config: Contains any additional control parameters. Can be C{None}.
931 @type config:dictionary
932 @raise ServerError: If the server has received the request but did not process the request due to some error.
933 @raise ParseError: If the server has responded but client was not able to parse the response.
934 @return: Slideshow URL.
935 @rtype:string
936 """
937 endpoint = self.endpoint + "/slides/" + slide_id + "/publish"
938 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers)
939 return response["data"]["slideUrl"]
940
942 """
943 Returns details of the specified slideshow.
944 @param slide_id: Id of the slideshow.
945 @type slide_id: string
946 @raise ServerError: If the server has received the request but did not process the request due to some error.
947 @raise ParseError: If the server has responded but client was not able to parse the response.
948 @return: Slideshow details.
949 @rtype:dictionary
950 """
951 endpoint = self.endpoint + "/slides/" + slide_id
952 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
953 return response["data"]["slideInfo"]
954
955 - def create_variable(self, variable_name, variable_datatype, variable_type, config = {}):
956 """
957 Create a variable in the workspace.
958 @param variable_name: Name of the variable to be created.
959 @type variable_name: string
960 @param variable_datatype: Datatype of the variable to be created.
961 @type variable_datatype: string
962 @param variable_type: Type of the variable to be created.
963 @type variable_type: string
964 @param config: Contains the control parameters.
965 @type config:dictionary
966 @raise ServerError: If the server has received the request but did not process the request due to some error.
967 @raise ParseError: If the server has responded but client was not able to parse the response.
968 @return: Id of the created variable.
969 @rtype:string
970 """
971 endpoint = self.endpoint + "/variables"
972 config["variableName"] = variable_name
973 config["variableDataType"] = variable_datatype
974 config["variableType"] = variable_type
975 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers)
976 return int(response["data"]["variableId"])
977
978 - def update_variable(self, variable_id, variable_name, variable_datatype, variable_type, config = {}):
979 """
980 Update details of the specified variable in the workspace.
981 @param variable_id: Id of the variable.
982 @type variable_id: string
983 @param variable_name: New name for the variable.
984 @type variable_name: string
985 @param variable_datatype: New datatype for the variable.
986 @type variable_datatype: string
987 @param variable_type: New type for the variable.
988 @type variable_type: string
989 @param config: Contains the control parameters.
990 @type config:dictionary
991 @raise ServerError: If the server has received the request but did not process the request due to some error.
992 @raise ParseError: If the server has responded but client was not able to parse the response.
993 """
994 endpoint = self.endpoint + "/variables/" + variable_id
995 config["variableName"] = variable_name
996 config["variableDataType"] = variable_datatype
997 config["variableType"] = variable_type
998 response = self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
999
1001 """
1002 Delete the specified variable in the workspace.
1003 @param variable_id: Id of the variable.
1004 @type variable_id: string
1005 @raise ServerError: If the server has received the request but did not process the request due to some error.
1006 @raise ParseError: If the server has responded but client was not able to parse the response.
1007 """
1008 endpoint = self.endpoint + "/variables/" + variable_id
1009 response = self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
1010
1012 """
1013 Returns list of variables for the specified workspace.
1014 @raise ServerError: If the server has received the request but did not process the request due to some error.
1015 @raise ParseError: If the server has responded but client was not able to parse the response.
1016 @return: Variable list.
1017 @rtype:list
1018 """
1019 endpoint = self.endpoint + "/variables"
1020 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
1021 return response["data"]["variables"]
1022
1024 """
1025 Returns list of variables for the specified workspace.
1026 @param variable_id: Id of the variable.
1027 @type variable_id: string
1028 @raise ServerError: If the server has received the request but did not process the request due to some error.
1029 @raise ParseError: If the server has responded but client was not able to parse the response.
1030 @return: Variable details.
1031 @rtype:dictionary
1032 """
1033 endpoint = self.endpoint + "/variables/" + variable_id
1034 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
1035 return response["data"]
1036
1038 """
1039 Make the specified folder as default.
1040 @param folder_id: Id of the folder.
1041 @type folder_id: string
1042 @raise ServerError: If the server has received the request but did not process the request due to some error.
1043 @raise ParseError: If the server has responded but client was not able to parse the response.
1044 """
1045 endpoint = self.endpoint + "/folders/" + folder_id + "/default"
1046 response = self.ac.send_api_request("PUT", endpoint, None, self.request_headers)
1047
1049 """
1050 Returns list of datasources for the specified workspace.
1051 @raise ServerError: If the server has received the request but did not process the request due to some error.
1052 @raise ParseError: If the server has responded but client was not able to parse the response.
1053 @return: Datasource list.
1054 @rtype:list
1055 """
1056 endpoint = self.endpoint + "/datasources"
1057 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
1058 return response["data"]["dataSources"]
1059
1060 - def sync_data(self, datasource_id, config = {}):
1061 """
1062 Initiate data sync for the specified datasource.
1063 @param datasource_id: Id of the datasource.
1064 @type datasource_id: string
1065 @param config: Contains any additional control parameters. Can be C{None}.
1066 @type config:dictionary
1067 @raise ServerError: If the server has received the request but did not process the request due to some error.
1068 @raise ParseError: If the server has responded but client was not able to parse the response.
1069 """
1070 endpoint = self.endpoint + "/datasources/" + datasource_id + "/sync"
1071 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers)
1072
1074 """
1075 Update connection details for the specified datasource.
1076 @param datasource_id: Id of the datasource.
1077 @type datasource_id: string
1078 @param config: Contains the control parameters.
1079 @type config:dictionary
1080 @raise ServerError: If the server has received the request but did not process the request due to some error.
1081 @raise ParseError: If the server has responded but client was not able to parse the response.
1082 """
1083 endpoint = self.endpoint + "/datasources/" + datasource_id
1084 response = self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1085
1087 """
1088 Initiate data sync for the specified datasource.
1089 @raise ServerError: If the server has received the request but did not process the request due to some error.
1090 @raise ParseError: If the server has responded but client was not able to parse the response.
1091 @return: Trash view list.
1092 @rtype:list
1093 """
1094 endpoint = self.endpoint + "/trash"
1095 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
1096 return response["data"]["views"]
1097
1099 """
1100 Restore the specified view from trash.
1101 @param view_id: Id of the view.
1102 @type view_id: string
1103 @param config: Contains any additional control parameters. Can be C{None}.
1104 @type config:dictionary
1105 @raise ServerError: If the server has received the request but did not process the request due to some error.
1106 @raise ParseError: If the server has responded but client was not able to parse the response.
1107 """
1108 endpoint = self.endpoint + "/trash/" + view_id
1109 response = self.ac.send_api_request("POST", endpoint, None, self.request_headers)
1110
1112 """
1113 Delete the specified view permanently from trash.
1114 @param view_id: Id of the view.
1115 @type view_id: string
1116 @param config: Contains any additional control parameters. Can be C{None}.
1117 @type config:dictionary
1118 @raise ServerError: If the server has received the request but did not process the request due to some error.
1119 @raise ParseError: If the server has responded but client was not able to parse the response.
1120 """
1121 endpoint = self.endpoint + "/trash/" + view_id
1122 response = self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
1123
1125 """
1126 Swaps the hierarchy of a parent folder and a subfolder.
1127 @param folder_id: Id of the folder.
1128 @type folder_id: string
1129 @param hierarchy: New hierarchy for the folder. (0 - Parent; 1 - Child).
1130 @type hierarchy: string
1131 @param config: Contains any additional control parameters. Can be C{None}.
1132 @type config:dictionary
1133 @raise ServerError: If the server has received the request but did not process the request due to some error.
1134 @raise ParseError: If the server has responded but client was not able to parse the response.
1135 """
1136 endpoint = self.endpoint + "/folders/" + folder_id + "/move";
1137 config["hierarchy"] = hierarchy
1138 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1139
1141 """
1142 Place the folder above the reference folder.
1143 @param folder_id: Id of the folder.
1144 @type folder_id: string
1145 @param reference_folder_id: Id of the reference folder.
1146 @type reference_folder_id: string
1147 @param config: Contains any additional control parameters. Can be C{None}.
1148 @type config:dictionary
1149 @raise ServerError: If the server has received the request but did not process the request due to some error.
1150 @raise ParseError: If the server has responded but client was not able to parse the response.
1151 """
1152 endpoint = self.endpoint + "/folders/" + folder_id + "/reorder";
1153 config["referenceFolderId"] = reference_folder_id
1154 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1155
1157 """
1158 Move views to the mentioned folder.
1159 @param folder_id: Id of the folder.
1160 @type folder_id: string
1161 @param view_ids: View ids to be moved.
1162 @type view_ids: list
1163 @param config: Contains any additional control parameters. Can be C{None}.
1164 @type config:dictionary
1165 @raise ServerError: If the server has received the request but did not process the request due to some error.
1166 @raise ParseError: If the server has responded but client was not able to parse the response.
1167 """
1168 endpoint = self.endpoint + "/views/movetofolder";
1169 config["folderId"] = folder_id
1170 config["viewIds"] = view_ids
1171 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1172
1174 """
1175 Export the mentioned views as templates.
1176 @param view_ids: Ids of the views to be exported.
1177 @type view_ids: list
1178 @param file_path: Path of the file where the data exported to be stored. ( Should be in 'atpt' format )
1179 @type file_path: string
1180 @param config: Contains any additional control parameters. Can be C{None}.
1181 @type config:dictionary
1182 @raise ServerError: If the server has received the request but did not process the request due to some error.
1183 @raise ParseError: If the server has responded but client was not able to parse the response.
1184 """
1185 endpoint = self.endpoint + "/template/data"
1186 config["viewIds"] = view_ids
1187 self.ac.send_export_api_request(endpoint, config, self.request_headers, file_path)
1188
1190 """
1191 Returns list of users for the specified workspace.
1192 @raise ServerError: If the server has received the request but did not process the request due to some error.
1193 @raise ParseError: If the server has responded but client was not able to parse the response.
1194 @return: User list.
1195 @rtype:list
1196 """
1197 endpoint = self.endpoint + "/users";
1198 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
1199 return response["data"]["users"]
1200
1202 """
1203 Add users to the specified workspace.
1204 @param email_ids: The email address of the users to be added.
1205 @type email_ids:list
1206 @param role: Role of the user to be added.
1207 @type role:string
1208 @param config: Contains any additional control parameters. Can be C{None}.
1209 @type config:dictionary
1210 @raise ServerError: If the server has received the request but did not process the request due to some error.
1211 @raise ParseError: If the server has responded but client was not able to parse the response.
1212 """
1213 config["emailIds"] = email_ids
1214 config["role"] = role
1215 endpoint = self.endpoint + "/users";
1216 self.ac.send_api_request("POST", endpoint, config, self.request_headers)
1217
1219 """
1220 Remove users from the specified workspace.
1221 @param email_ids: The email address of the users to be removed.
1222 @type email_ids:list
1223 @param config: Contains any additional control parameters. Can be C{None}.
1224 @type config:dictionary
1225 @raise ServerError: If the server has received the request but did not process the request due to some error.
1226 @raise ParseError: If the server has responded but client was not able to parse the response.
1227 """
1228 config["emailIds"] = email_ids
1229 endpoint = self.endpoint + "/users";
1230 self.ac.send_api_request("DELETE", endpoint, config, self.request_headers)
1231
1233 """
1234 Change users staus in the specified workspace.
1235 @param email_ids: The email address of the users.
1236 @type email_ids:list
1237 @param operation: New status for the users ( Values - activate | deactivate ).
1238 @type operation:string
1239 @param config: Contains any additional control parameters. Can be C{None}.
1240 @type config:dictionary
1241 @raise ServerError: If the server has received the request but did not process the request due to some error.
1242 @raise ParseError: If the server has responded but client was not able to parse the response.
1243 """
1244 config["emailIds"] = email_ids
1245 config["operation"] = operation
1246 endpoint = self.endpoint + "/users/status";
1247 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1248
1250 """
1251 Change role for the specified users.
1252 @param email_ids: The email address of the users.
1253 @type email_ids:list
1254 @param role: New role for the users.
1255 @type role:string
1256 @param config: Contains any additional control parameters. Can be C{None}.
1257 @type config:dictionary
1258 @raise ServerError: If the server has received the request but did not process the request due to some error.
1259 @raise ParseError: If the server has responded but client was not able to parse the response.
1260 """
1261 config["emailIds"] = email_ids
1262 config["role"] = role
1263 endpoint = self.endpoint + "/users/role";
1264 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1265
1266
1268 """
1269 ViewAPI contains view level operations.
1270 """
1271 - def __init__(self, ac, org_id, workspace_id, view_id):
1272 self.ac = ac
1273 self.endpoint = "/restapi/v2/workspaces/" + workspace_id + "/views/" + view_id
1274 self.request_headers = {}
1275 self.request_headers["ZANALYTICS-ORGID"] = org_id
1276
1277 - def rename(self, view_name, config = {}):
1278 """
1279 Rename a specified view in the workspace.
1280 @param view_name: New name of the view.
1281 @type view_name: string
1282 @param config: Contains any additional control parameters. Can be C{None}.
1283 @type config:dictionary
1284 @raise ServerError: If the server has received the request but did not process the request due to some error.
1285 @raise ParseError: If the server has responded but client was not able to parse the response.
1286 """
1287 config["viewName"] = view_name
1288 response = self.ac.send_api_request("PUT", self.endpoint, config, self.request_headers)
1289
1290 - def delete(self, config = {}):
1291 """
1292 Delete a specified view in the workspace.
1293 @param config: Contains any additional control parameters. Can be C{None}.
1294 @type config:dictionary
1295 @raise ServerError: If the server has received the request but did not process the request due to some error.
1296 @raise ParseError: If the server has responded but client was not able to parse the response.
1297 """
1298 response = self.ac.send_api_request("DELETE", self.endpoint, config, self.request_headers)
1299
1300 - def save_as(self, new_view_name, config = {}):
1301 """
1302 Copy a specified view within the workspace.
1303 @param new_view_name: The name of the new view.
1304 @type new_view_name: string
1305 @param config: Contains any additional control parameters. Can be C{None}.
1306 @type config:dictionary
1307 @raise ServerError: If the server has received the request but did not process the request due to some error.
1308 @raise ParseError: If the server has responded but client was not able to parse the response.
1309 @return: Created view id.
1310 @rtype:string
1311 """
1312 config["viewName"] = new_view_name
1313 endpoint = self.endpoint + "/saveas"
1314 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers)
1315 return int(response["data"]["viewId"])
1316
1338
1340 """
1341 Adds a specified view as favorite.
1342 @raise ServerError: If the server has received the request but did not process the request due to some error.
1343 @raise ParseError: If the server has responded but client was not able to parse the response.
1344 """
1345 endpoint = self.endpoint + "/favorite"
1346 response = self.ac.send_api_request("POST", endpoint, None, self.request_headers)
1347
1349 """
1350 Remove a specified view from favorite.
1351 @raise ServerError: If the server has received the request but did not process the request due to some error.
1352 @raise ParseError: If the server has responded but client was not able to parse the response.
1353 """
1354 endpoint = self.endpoint + "/favorite"
1355 response = self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
1356
1358 """
1359 Create reports for the specified table based on the reference table.
1360 @param ref_view_id: The ID of the reference view.
1361 @type ref_view_id: string
1362 @param folder_id: The folder id where the views to be saved.
1363 @type folder_id: string
1364 @param config: Contains any additional control parameters. Can be C{None}.
1365 @type config:dictionary
1366 @raise ServerError: If the server has received the request but did not process the request due to some error.
1367 @raise ParseError: If the server has responded but client was not able to parse the response.
1368 """
1369 config["referenceViewId"] = ref_view_id
1370 config["folderId"] = folder_id
1371 endpoint = self.endpoint + "/similarviews"
1372 self.ac.send_api_request("POST", endpoint, config, self.request_headers)
1373
1375 """
1376 Auto generate reports for the specified table.
1377 @param config: Contains any additional control parameters. Can be C{None}.
1378 @type config:dictionary
1379 @raise ServerError: If the server has received the request but did not process the request due to some error.
1380 @raise ParseError: If the server has responded but client was not able to parse the response.
1381 """
1382 endpoint = self.endpoint + "/autoanalyse"
1383 self.ac.send_api_request("POST", endpoint, config, self.request_headers)
1384
1386 """
1387 Returns permissions for the specified view.
1388 @raise ServerError: If the server has received the request but did not process the request due to some error.
1389 @raise ParseError: If the server has responded but client was not able to parse the response.
1390 @return: Permission details.
1391 @rtype:dictionary
1392 """
1393 endpoint = self.endpoint + "/share/userpermissions"
1394 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
1395 return response["data"]["permissions"]
1396
1398 """
1399 Returns the URL to access the specified view.
1400 @param config: Contains any additional control parameters. Can be C{None}.
1401 @type config:dictionary
1402 @raise ServerError: If the server has received the request but did not process the request due to some error.
1403 @raise ParseError: If the server has responded but client was not able to parse the response.
1404 @return: View URL.
1405 @rtype:string
1406 """
1407 endpoint = self.endpoint + "/publish"
1408 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers)
1409 return response["data"]["viewUrl"]
1410
1412 """
1413 Returns embed URL to access the specified view.
1414 @param config: Contains any additional control parameters. Can be C{None}.
1415 @type config:dictionary
1416 @raise ServerError: If the server has received the request but did not process the request due to some error.
1417 @raise ParseError: If the server has responded but client was not able to parse the response.
1418 @return: Embed URL.
1419 @rtype:string
1420 """
1421 endpoint = self.endpoint + "/publish/embed"
1422 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers)
1423 return response["data"]["embedUrl"]
1424
1426 """
1427 Returns private URL to access the specified view.
1428 @param config: Contains any additional control parameters. Can be C{None}.
1429 @type config:dictionary
1430 @raise ServerError: If the server has received the request but did not process the request due to some error.
1431 @raise ParseError: If the server has responded but client was not able to parse the response.
1432 @return: Private URL.
1433 @rtype:string
1434 """
1435 endpoint = self.endpoint + "/publish/privatelink"
1436 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers)
1437 return response["data"]["privateUrl"]
1438
1440 """
1441 Create a private URL for the specified view.
1442 @param config: Contains any additional control parameters. Can be C{None}.
1443 @type config:dictionary
1444 @raise ServerError: If the server has received the request but did not process the request due to some error.
1445 @raise ParseError: If the server has responded but client was not able to parse the response.
1446 @return: Private URL.
1447 @rtype:string
1448 """
1449 endpoint = self.endpoint + "/publish/privatelink"
1450 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers)
1451 return response["data"]["privateUrl"]
1452
1454 """
1455 Remove private link access for the specified view.
1456 @raise ServerError: If the server has received the request but did not process the request due to some error.
1457 @raise ParseError: If the server has responded but client was not able to parse the response.
1458 """
1459 endpoint = self.endpoint + "/publish/privatelink"
1460 response = self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
1461
1463 """
1464 Make the specified view publically accessible.
1465 @param config: Contains any additional control parameters. Can be C{None}.
1466 @type config:dictionary
1467 @raise ServerError: If the server has received the request but did not process the request due to some error.
1468 @raise ParseError: If the server has responded but client was not able to parse the response.
1469 @return: Public URL.
1470 @rtype:string
1471 """
1472 endpoint = self.endpoint + "/publish/public"
1473 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers)
1474 return response["data"]["publicUrl"]
1475
1477 """
1478 Remove public access for the specified view.
1479 @raise ServerError: If the server has received the request but did not process the request due to some error.
1480 @raise ParseError: If the server has responded but client was not able to parse the response.
1481 """
1482 response = endpoint = self.endpoint + "/publish/public"
1483 self.ac.send_api_request("DELETE", endpoint, None, self.request_headers)
1484
1486 """
1487 Returns publish configurations for the specified view.
1488 @raise ServerError: If the server has received the request but did not process the request due to some error.
1489 @raise ParseError: If the server has responded but client was not able to parse the response.
1490 @return: Publish details.
1491 @rtype:dictionary
1492 """
1493 endpoint = self.endpoint + "/publish/config"
1494 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
1495 return response["data"]
1496
1498 """
1499 Update publish configurations for the specified view.
1500 @param config: Contains the control parameters.
1501 @type config:dictionary
1502 @raise ServerError: If the server has received the request but did not process the request due to some error.
1503 @raise ParseError: If the server has responded but client was not able to parse the response.
1504 """
1505 endpoint = self.endpoint + "/publish/config"
1506 response = self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1507
1508 - def add_column(self, column_name, data_type, config = {}):
1509 """
1510 Add a column in the specified table.
1511 @param column_name: The name of the column.
1512 @type column_name: string
1513 @param data_type: The data-type of the column.
1514 @type data_type: string
1515 @param config: Contains any additional control parameters. Can be C{None}.
1516 @type config:dictionary
1517 @raise ServerError: If the server has received the request but did not process the request due to some error.
1518 @raise ParseError: If the server has responded but client was not able to parse the response.
1519 @return: Created column id.
1520 @rtype:string
1521 """
1522 config["columnName"] = column_name
1523 config["dataType"] = data_type
1524 endpoint = self.endpoint + "/columns"
1525 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers)
1526 return int(response["data"]["columnId"])
1527
1529 """
1530 Hide the specified columns in the table.
1531 @param column_ids: Ids of the columns to be hidden.
1532 @type column_ids: list
1533 @raise ServerError: If the server has received the request but did not process the request due to some error.
1534 @raise ParseError: If the server has responded but client was not able to parse the response.
1535 """
1536 config = {}
1537 config["columnIds"] = column_ids
1538 endpoint = self.endpoint + "/columns/hide"
1539 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1540
1542 """
1543 Show the specified hidden columns in the table.
1544 @param column_ids: Ids of the columns to be shown.
1545 @type column_ids: list
1546 @raise ServerError: If the server has received the request but did not process the request due to some error.
1547 @raise ParseError: If the server has responded but client was not able to parse the response.
1548 """
1549 config = {}
1550 config["columnIds"] = column_ids
1551 endpoint = self.endpoint + "/columns/show"
1552 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1553
1554 - def add_row(self, column_values, config = {}):
1555 """
1556 Add a single row in the specified table.
1557 @param column_values: Contains the values for the row. The column names are the key.
1558 @type column_values: dictionary
1559 @param config: Contains any additional control parameters. Can be C{None}.
1560 @type config:dictionary
1561 @raise ServerError: If the server has received the request but did not process the request due to some error.
1562 @raise ParseError: If the server has responded but client was not able to parse the response.
1563 @return: Column Names and Added Row Values.
1564 @rtype:dictionary
1565 """
1566 config["columns"] = column_values
1567 endpoint = self.endpoint + "/rows"
1568 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers)
1569 return response["data"]
1570
1571 - def update_row(self, column_values, criteria, config = {}):
1572 """
1573 Update rows in the specified table.
1574 @param column_values: Contains the values for the row. The column names are the key.
1575 @type column_values: dictionary
1576 @param criteria: The criteria to be applied for updating data. Only rows matching the criteria will be updated. Should be null for update all rows.
1577 @type criteria: string
1578 @param config: Contains any additional control parameters. Can be C{None}.
1579 @type config:dictionary
1580 @raise ServerError: If the server has received the request but did not process the request due to some error.
1581 @raise ParseError: If the server has responded but client was not able to parse the response.
1582 @return: Updated Columns List and Updated Rows Count.
1583 @rtype:dictionary
1584 """
1585 config["columns"] = column_values
1586 if criteria != None:
1587 config["criteria"] = criteria
1588 endpoint = self.endpoint + "/rows"
1589 response = self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1590 return response["data"]
1591
1593 """
1594 Delete rows in the specified table.
1595 @param criteria: The criteria to be applied for deleting data. Only rows matching the criteria will be deleted. Should be null for delete all rows.
1596 @type criteria: string
1597 @param config: Contains any additional control parameters. Can be C{None}.
1598 @type config:dictionary
1599 @raise ServerError: If the server has received the request but did not process the request due to some error.
1600 @raise ParseError: If the server has responded but client was not able to parse the response.
1601 @return: Deleted rows details.
1602 @rtype:string
1603 """
1604 if criteria != None:
1605 config["criteria"] = criteria
1606 endpoint = self.endpoint + "/rows"
1607 response = self.ac.send_api_request("DELETE", endpoint, config, self.request_headers)
1608 return response["data"]["deletedRows"]
1609
1611 """
1612 Rename a specified column in the table.
1613 @param column_id: Id of the column.
1614 @type column_id: string
1615 @param column_name: New name for the column.
1616 @type column_name: string
1617 @param config: Contains any additional control parameters. Can be C{None}.
1618 @type config:dictionary
1619 @raise ServerError: If the server has received the request but did not process the request due to some error.
1620 @raise ParseError: If the server has responded but client was not able to parse the response.
1621 """
1622 config["columnName"] = column_name
1623 endpoint = self.endpoint + "/columns/" + column_id
1624 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1625
1627 """
1628 Delete a specified column in the table.
1629 @param column_id: Id of the column.
1630 @type column_id: string
1631 @param config: Contains any additional control parameters. Can be C{None}.
1632 @type config:dictionary
1633 @raise ServerError: If the server has received the request but did not process the request due to some error.
1634 @raise ParseError: If the server has responded but client was not able to parse the response.
1635 """
1636 endpoint = self.endpoint + "/columns/" + column_id
1637 self.ac.send_api_request("DELETE", endpoint, config, self.request_headers)
1638
1639 - def add_lookup(self, column_id, ref_view_id, ref_column_id, config = {}):
1640 """
1641 Add a lookup in the specified child table.
1642 @param column_id: Id of the column.
1643 @type column_id: string
1644 @param ref_view_id: The id of the table contains the parent column.
1645 @type ref_view_id: string
1646 @param ref_column_id: The id of the parent column.
1647 @type ref_column_id: string
1648 @param config: Contains any additional control parameters. Can be C{None}.
1649 @type config:dictionary
1650 @raise ServerError: If the server has received the request but did not process the request due to some error.
1651 @raise ParseError: If the server has responded but client was not able to parse the response.
1652 """
1653 config["referenceViewId"] = ref_view_id;
1654 config["referenceColumnId"] = ref_column_id
1655 endpoint = self.endpoint + "/columns/" + column_id + "/lookup"
1656 self.ac.send_api_request("POST", endpoint, config, self.request_headers)
1657
1659 """
1660 Remove the lookup for the specified column in the table.
1661 @param column_id: Id of the column.
1662 @type column_id: string
1663 @param config: Contains any additional control parameters. Can be C{None}.
1664 @type config:dictionary
1665 @raise ServerError: If the server has received the request but did not process the request due to some error.
1666 @raise ParseError: If the server has responded but client was not able to parse the response.
1667 """
1668 endpoint = self.endpoint + "/columns/" + column_id + "/lookup"
1669 self.ac.send_api_request("DELETE", endpoint, config, self.request_headers)
1670
1672 """
1673 Auto generate reports for the specified column.
1674 @param column_id: Id of the column.
1675 @type column_id: string
1676 @param config: Contains any additional control parameters. Can be C{None}.
1677 @type config:dictionary
1678 @raise ServerError: If the server has received the request but did not process the request due to some error.
1679 @raise ParseError: If the server has responded but client was not able to parse the response.
1680 """
1681 endpoint = self.endpoint + "/columns/" + column_id + "/autoanalyse"
1682 self.ac.send_api_request("POST", endpoint, config, self.request_headers)
1683
1685 """
1686 Sync data from available datasource for the specified view.
1687 @param config: Contains any additional control parameters. Can be C{None}.
1688 @type config:dictionary
1689 @raise ServerError: If the server has received the request but did not process the request due to some error.
1690 @raise ParseError: If the server has responded but client was not able to parse the response.
1691 """
1692 endpoint = self.endpoint + "/sync"
1693 response = self.ac.send_api_request("POST", endpoint, config, self.request_headers)
1694
1696 """
1697 Returns last import details of the specified view.
1698 @raise ServerError: If the server has received the request but did not process the request due to some error.
1699 @raise ParseError: If the server has responded but client was not able to parse the response.
1700 @return: Last import details.
1701 @rtype:dictionary
1702 """
1703 endpoint = self.endpoint + "/importdetails"
1704 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
1705 return response["data"]
1706
1718
1738
1754
1767
1779
1799
1815
1828
1830 """
1831 Returns list of dependents views for the specified view.
1832 @raise ServerError: If the server has received the request but did not process the request due to some error.
1833 @raise ParseError: If the server has responded but client was not able to parse the response.
1834 @return: Dependent view list.
1835 @rtype:list
1836 """
1837 endpoint = self.endpoint + "/dependents"
1838 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
1839 return response["data"]["views"]
1840
1842 """
1843 Returns list of dependents views and formulas for the specified column.
1844 @raise ServerError: If the server has received the request but did not process the request due to some error.
1845 @raise ParseError: If the server has responded but client was not able to parse the response.
1846 @return: Dependent details.
1847 @rtype:dictionary
1848 """
1849 endpoint = self.endpoint + "/columns/" + column_id + "/dependents"
1850 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
1851 return response["data"]
1852
1854 """
1855 Update shared details of the specified view.
1856 @param config: Contains the control parameters.
1857 @type config:dictionary
1858 @raise ServerError: If the server has received the request but did not process the request due to some error.
1859 @raise ParseError: If the server has responded but client was not able to parse the response.
1860 """
1861 endpoint = self.endpoint + "/share"
1862 self.ac.send_api_request("PUT", endpoint, config, self.request_headers)
1863
1864
1866 """
1867 BulkAPI contains data operations.
1868 """
1869 - def __init__(self, ac, org_id, workspace_id):
1870 self.ac = ac
1871 self.endpoint = "/restapi/v2/workspaces/" + workspace_id
1872 self.bulk_endpoint = "/restapi/v2/bulk/workspaces/" + workspace_id
1873 self.request_headers = {}
1874 self.request_headers["ZANALYTICS-ORGID"] = org_id
1875
1877 """
1878 Create a new table and import the data contained in the mentioned file into the created table.
1879 @param table_name: Name of the new table to be created.
1880 @type table_name: string
1881 @param file_type: Type of the file to be imported.
1882 @type file_type: string
1883 @param auto_identify: Used to specify whether to auto identify the CSV format. Allowable values - true/false.
1884 @type auto_identify: string
1885 @param file_path: Path of the file to be imported.
1886 @type file_path: string
1887 @param config: Contains any additional control parameters. Can be C{None}.
1888 @type config:dictionary
1889 @raise ServerError: If the server has received the request but did not process the request due to some error.
1890 @raise ParseError: If the server has responded but client was not able to parse the response.
1891 @return Import result
1892 @rtype:dictionary
1893 """
1894 endpoint = self.endpoint + "/data"
1895 config["tableName"] = table_name
1896 config["fileType"] = file_type
1897 config["autoIdentify"] = auto_identify
1898 response = self.ac.send_import_api_request(endpoint, config, self.request_headers, file_path)
1899 return response["data"]
1900
1903 """
1904 Create a new table and import the data contained in the mentioned file into the created table.
1905 @param table_name: Name of the new table to be created.
1906 @type table_name: string
1907 @param auto_identify: Used to specify whether to auto identify the CSV format. Allowable values - true/false.
1908 @type auto_identify: string
1909 @param file_path: Path of the file to be imported.
1910 @type file_path: string
1911 @param batch_size: Number of lines per batch.
1912 @type batch_size:int
1913 @param config: Contains any additional control parameters. Can be C{None}.
1914 @type config:dictionary
1915 @param tool_config: Contains any additional control parameters for the library. Can be C{None}.
1916 @type tool_config:dictionary
1917 @raise ServerError: If the server has received the request but did not process the request due to some error.
1918 @raise ParseError: If the server has responded but client was not able to parse the response.
1919 @return Import job id
1920 @rtype:string
1921 """
1922 endpoint = self.bulk_endpoint + "/data/batch"
1923 config["tableName"] = table_name
1924 config["autoIdentify"] = auto_identify
1925 response = self.ac.send_batch_import_api_request(endpoint, config, self.request_headers, file_path,
1926 batch_size, tool_config)
1927 return response["data"]["jobId"]
1928
1930 """
1931 Create a new table and import the raw data provided into the created table.
1932 @param table_name: Name of the new table to be created.
1933 @type table_name: string
1934 @param file_type: Type of the file to be imported.
1935 @type file_type: string
1936 @param auto_identify: Used to specify whether to auto identify the CSV format. Allowable values - true/false.
1937 @type auto_identify: string
1938 @param data: Raw data to be imported.
1939 @type data: string
1940 @param config: Contains any additional control parameters. Can be C{None}.
1941 @type config:dictionary
1942 @raise ServerError: If the server has received the request but did not process the request due to some error.
1943 @raise ParseError: If the server has responded but client was not able to parse the response.
1944 @return Import result
1945 @rtype:dictionary
1946 """
1947 endpoint = self.endpoint + "/data"
1948 config["tableName"] = table_name
1949 config["fileType"] = file_type
1950 config["autoIdentify"] = auto_identify
1951 response = self.ac.send_import_api_request(endpoint, config, self.request_headers, None, data)
1952 return response["data"]
1953
1954 - def import_data(self, view_id, import_type, file_type, auto_identify, file_path, config = {}):
1955 """
1956 Import the data contained in the mentioned file into the table.
1957 @param view_id: Id of the view where the data to be imported.
1958 @type view_id: string
1959 @param import_type: The type of import. Can be one of - append, truncateadd, updateadd.
1960 @type import_type: string
1961 @param file_type: Type of the file to be imported.
1962 @type file_type: string
1963 @param auto_identify: Used to specify whether to auto identify the CSV format. Allowable values - true/false.
1964 @type auto_identify: string
1965 @param file_path: Path of the file to be imported.
1966 @type file_path: string
1967 @param config: Contains any additional control parameters. Can be C{None}.
1968 @type config:dictionary
1969 @raise ServerError: If the server has received the request but did not process the request due to some error.
1970 @raise ParseError: If the server has responded but client was not able to parse the response.
1971 @return Import result
1972 @rtype:dictionary
1973 """
1974 endpoint = self.endpoint + "/views/" + view_id + "/data"
1975 config["fileType"] = file_type
1976 config["autoIdentify"] = auto_identify
1977 config["importType"] = import_type
1978 response = self.ac.send_import_api_request(endpoint, config, self.request_headers, file_path)
1979 return response["data"]
1980
1981 - def import_raw_data(self, view_id, import_type, file_type, auto_identify, data, config = {}):
1982 """
1983 Import the raw data provided into the table.
1984 @param view_id: Id of the view where the data to be imported.
1985 @type view_id: string
1986 @param import_type: The type of import. Can be one of - append, truncateadd, updateadd.
1987 @type import_type: string
1988 @param file_type: Type of the file to be imported.
1989 @type file_type: string
1990 @param auto_identify: Used to specify whether to auto identify the CSV format. Allowable values - true/false.
1991 @type auto_identify: string
1992 @param data: Raw data to be imported.
1993 @type data: string
1994 @param config: Contains any additional control parameters. Can be C{None}.
1995 @type config:dictionary
1996 @raise ServerError: If the server has received the request but did not process the request due to some error.
1997 @raise ParseError: If the server has responded but client was not able to parse the response.
1998 @return Import result
1999 @rtype:dictionary
2000 """
2001 endpoint = self.endpoint + "/views/" + view_id + "/data"
2002 config["fileType"] = file_type
2003 config["autoIdentify"] = auto_identify
2004 config["importType"] = import_type
2005 response = self.ac.send_import_api_request(endpoint, config, self.request_headers, None, data)
2006 return response["data"]
2007
2009 """
2010 Asynchronously create a new table and import the data contained in the mentioned file into the created table.
2011 @param table_name: Name of the new table to be created.
2012 @type table_name: string
2013 @param file_type: Type of the file to be imported.
2014 @type file_type: string
2015 @param auto_identify: Used to specify whether to auto identify the CSV format. Allowable values - true/false.
2016 @type auto_identify: string
2017 @param file_path: Path of the file to be imported.
2018 @type file_path: string
2019 @param config: Contains any additional control parameters. Can be C{None}.
2020 @type config:dictionary
2021 @raise ServerError: If the server has received the request but did not process the request due to some error.
2022 @raise ParseError: If the server has responded but client was not able to parse the response.
2023 @return Import job id
2024 @rtype:string
2025 """
2026 endpoint = self.bulk_endpoint + "/data"
2027 config["tableName"] = table_name
2028 config["fileType"] = file_type
2029 config["autoIdentify"] = auto_identify
2030 response = self.ac.send_import_api_request(endpoint, config, self.request_headers, file_path)
2031 return response["data"]["jobId"]
2032
2033 - def import_bulk_data(self, view_id, import_type, file_type, auto_identify, file_path, config = {}):
2034 """
2035 Asynchronously import the data contained in the mentioned file into the table.
2036 @param view_id: Id of the view where the data to be imported.
2037 @type view_id: string
2038 @param import_type: The type of import. Can be one of - append, truncateadd, updateadd.
2039 @type import_type: string
2040 @param file_type: Type of the file to be imported.
2041 @type file_type: string
2042 @param auto_identify: Used to specify whether to auto identify the CSV format. Allowable values - true/false.
2043 @type auto_identify: string
2044 @param file_path: Path of the file to be imported.
2045 @type file_path: string
2046 @param config: Contains any additional control parameters. Can be C{None}.
2047 @type config:dictionary
2048 @raise ServerError: If the server has received the request but did not process the request due to some error.
2049 @raise ParseError: If the server has responded but client was not able to parse the response.
2050 @return Import job id
2051 @rtype:string
2052 """
2053 endpoint = self.bulk_endpoint + "/views/" + view_id + "/data"
2054 config["fileType"] = file_type
2055 config["autoIdentify"] = auto_identify
2056 config["importType"] = import_type
2057 response = self.ac.send_import_api_request(endpoint, config, self.request_headers, file_path)
2058 return response["data"]["jobId"]
2059
2060 - def import_data_as_batches(self, view_id, import_type, auto_identify, file_path, batch_size,
2061 config={}, tool_config={}):
2062 """
2063 Asynchronously import the data contained in the mentioned file into the table.
2064 @param view_id: Id of the view where the data to be imported.
2065 @type view_id: string
2066 @param import_type: The type of import. Can be one of - append, truncateadd, updateadd.
2067 @type import_type: string
2068 @param auto_identify: Used to specify whether to auto identify the CSV format. Allowable values - true/false.
2069 @type auto_identify: string
2070 @param file_path: Path of the file to be imported.
2071 @type file_path: string
2072 @param batch_size: Number of lines per batch.
2073 @type batch_size:int
2074 @param config: Contains any additional control parameters. Can be C{None}.
2075 @type config:dictionary
2076 @param tool_config: Contains any additional control parameters for the library. Can be C{None}.
2077 @type tool_config:dictionary
2078 @raise ServerError: If the server has received the request but did not process the request due to some error.
2079 @raise ParseError: If the server has responded but client was not able to parse the response.
2080 @return Import job id
2081 @rtype:string
2082 """
2083 endpoint = self.bulk_endpoint + "/views/" + view_id + "/data/batch"
2084 config["importType"] = import_type
2085 config["autoIdentify"] = auto_identify
2086 response = self.ac.send_batch_import_api_request(endpoint, config, self.request_headers, file_path,
2087 batch_size, tool_config)
2088 return response["data"]["jobId"]
2089
2091 """
2092 Returns the details of the import job.
2093 @param job_id: Id of the job.
2094 @type job_id: string
2095 @raise ServerError: If the server has received the request but did not process the request due to some error.
2096 @raise ParseError: If the server has responded but client was not able to parse the response.
2097 @return Import job details
2098 @rtype:dictionary
2099 """
2100 endpoint = self.bulk_endpoint + "/importjobs/" + job_id
2101 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
2102 return response["data"]
2103
2104 - def export_data(self, view_id, response_format, file_path, config = {}):
2105 """
2106 Export the mentioned table (or) view data.
2107 @param view_id: Id of the view to be exported.
2108 @type view_id: string
2109 @param response_format: The format in which the data is to be exported.
2110 @type response_format: string
2111 @param file_path: Path of the file where the data exported to be stored.
2112 @type file_path: string
2113 @param config: Contains any additional control parameters. Can be C{None}.
2114 @type config:dictionary
2115 @raise ServerError: If the server has received the request but did not process the request due to some error.
2116 @raise ParseError: If the server has responded but client was not able to parse the response.
2117 """
2118 endpoint = self.endpoint + "/views/" + view_id + "/data"
2119 config["responseFormat"] = response_format
2120 self.ac.send_export_api_request(endpoint, config, self.request_headers, file_path)
2121
2123 """
2124 Initiate asynchronous export for the mentioned table (or) view data.
2125 @param view_id: Id of the view to be exported.
2126 @type view_id: string
2127 @param response_format: The format in which the data is to be exported.
2128 @type response_format: string
2129 @param config: Contains any additional control parameters. Can be C{None}.
2130 @type config:dictionary
2131 @raise ServerError: If the server has received the request but did not process the request due to some error.
2132 @raise ParseError: If the server has responded but client was not able to parse the response.
2133 @return Export job id
2134 @rtype:string
2135 """
2136 endpoint = self.bulk_endpoint + "/views/" + view_id + "/data"
2137 config["responseFormat"] = response_format
2138 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers)
2139 return response["data"]["jobId"]
2140
2142 """
2143 Initiate asynchronous export with the given SQL Query.
2144 @param sql_query: SQL Query.
2145 @type sql_query: string
2146 @param response_format: The format in which the data is to be exported.
2147 @type response_format: string
2148 @param config: Contains any additional control parameters. Can be C{None}.
2149 @type config:dictionary
2150 @raise ServerError: If the server has received the request but did not process the request due to some error.
2151 @raise ParseError: If the server has responded but client was not able to parse the response.
2152 @return Export job id
2153 @rtype:string
2154 """
2155 endpoint = self.bulk_endpoint + "/data"
2156 config["responseFormat"] = response_format
2157 config["sqlQuery"] = sql_query
2158 response = self.ac.send_api_request("GET", endpoint, config, self.request_headers)
2159 return response["data"]["jobId"]
2160
2162 """
2163 Returns the details of the export job.
2164 @param job_id: Id of the export job.
2165 @type job_id: string
2166 @raise ServerError: If the server has received the request but did not process the request due to some error.
2167 @raise ParseError: If the server has responded but client was not able to parse the response.
2168 @return Export job details
2169 @rtype:dictionary
2170 """
2171 endpoint = self.bulk_endpoint + "/exportjobs/" + job_id
2172 response = self.ac.send_api_request("GET", endpoint, None, self.request_headers)
2173 return response["data"]
2174
2176 """
2177 Download the exported data for the mentioned job id.
2178 @param job_id: Id of the job to be exported.
2179 @type job_id: string
2180 @param file_path: Path of the file where the data exported to be stored.
2181 @type file_path: string
2182 @raise ServerError: If the server has received the request but did not process the request due to some error.
2183 @raise ParseError: If the server has responded but client was not able to parse the response.
2184 """
2185 endpoint = self.bulk_endpoint + "/exportjobs/" + job_id + "/data"
2186 self.ac.send_export_api_request(endpoint, None, self.request_headers, file_path)
2187
2188
2189 - def set_proxy(self, proxy_host, proxy_port, proxy_user_name, proxy_password):
2190 """
2191 Internal method to handle proxy details.
2192 """
2193 self.proxy = True
2194 self.proxy_host = proxy_host
2195 self.proxy_port = proxy_port
2196 self.proxy_user_name = proxy_user_name
2197 self.proxy_password = proxy_password
2198
2200 if self.access_token is None:
2201 self.regenerate_analytics_oauth_token()
2202
2203 file_header = open(file_path, 'r').readline()
2204 file_content = open(file_path, 'r').readlines()
2205 file_content.__delitem__(0)
2206 total_lines = len(file_content)
2207 total_batch_count = math.ceil(total_lines / batch_size)
2208 config["batchKey"] = "start"
2209 request_url = self.analytics_server_url + request_url
2210
2211 for i in range(total_batch_count):
2212 batch = ("".join(file_content[batch_size * i:batch_size + (i * batch_size)]))
2213 batch_file = StringIO( file_header + batch )
2214 files = {'FILE': batch_file}
2215
2216 config["isLastBatch"] = "true" if (i == (total_batch_count - 1)) else "false"
2217 config_data = "CONFIG=" + urllib.parse.quote_plus(json.dumps(config))
2218
2219 resp_obj = self.submit_import_request(request_url, config_data, request_headers, self.access_token, files)
2220
2221 if not (str(resp_obj.status_code).startswith("2")):
2222 if self.is_oauth_expired(resp_obj):
2223 self.regenerate_analytics_oauth_token()
2224 resp_obj = self.submit_import_request(request_url, config_data, request_headers, self.access_token,
2225 files)
2226 if not (str(resp_obj.status_code).startswith("2")):
2227 raise ServerError(resp_obj.resp_content, False)
2228 else:
2229 raise ServerError(resp_obj.resp_content, False)
2230
2231 response = resp_obj.resp_content
2232 response = json.loads(response)
2233 config["batchKey"] = response["data"]["batchKey"]
2234 time.sleep(2)
2235
2236 return response
2237
2239 """
2240 Internal method to handle HTTP request.
2241 """
2242 if self.access_token == None:
2243 self.regenerate_analytics_oauth_token()
2244
2245 request_url = self.analytics_server_url + request_url
2246 config_data = None
2247 if bool(config):
2248 config_data = "CONFIG=" + urllib.parse.quote_plus(json.dumps(config))
2249
2250 if bool(data):
2251 if(bool(config_data)):
2252 config_data += "&"
2253 else:
2254 config_data = ""
2255
2256 config_data += "DATA=" + urllib.parse.quote_plus(json.dumps(data))
2257 resp_obj = self.submit_import_request(request_url, config_data, request_headers, self.access_token)
2258 else:
2259 files = {'FILE': open(file_path,'rb')}
2260 resp_obj = self.submit_import_request(request_url, config_data, request_headers, self.access_token, files)
2261
2262
2263 if not (str(resp_obj.status_code).startswith("2")):
2264 if(self.is_oauth_expired(resp_obj)):
2265 self.regenerate_analytics_oauth_token()
2266 if bool(data):
2267 resp_obj = self.submit_import_request(request_url, config_data, request_headers, self.access_token)
2268 else:
2269 resp_obj = self.submit_import_request(request_url, config_data, request_headers, self.access_token, files)
2270 if not (str(resp_obj.status_code).startswith("2")):
2271 raise ServerError(resp_obj.resp_content, False)
2272 else:
2273 raise ServerError(resp_obj.resp_content, False)
2274
2275 response = resp_obj.resp_content
2276 response = json.loads(response)
2277 return response
2278
2279
2280 - def submit_import_request(self, request_url, parameters, request_headers = {}, access_token = None, files = None):
2281 """
2282 Internal method to send request to server.
2283 """
2284 try:
2285 if request_headers == None:
2286 request_headers = {}
2287
2288 if access_token != None:
2289 request_headers["Authorization"] = "Zoho-oauthtoken " + access_token
2290
2291 request_headers["User-Agent"] = "Analytics Python Client v" + self.CLIENT_VERSION
2292
2293 req_obj = req_obj = requests.Session()
2294 if self.proxy:
2295 proxy_details = {
2296 "http" : "http://" + self.proxy_host + ":" + self.proxy_port,
2297 "https": "http://" + self.proxy_host + ":" + self.proxy_port
2298 }
2299 req_obj.proxies = proxy_details
2300 if self.proxy_user_name != None and self.proxy_password != None:
2301 proxy_auth_details = HTTPProxyDigestAuth(self.proxy_user_name, self.proxy_password)
2302 req_obj.auth = proxy_auth_details
2303
2304 if bool(files):
2305 resp_obj = req_obj.post(request_url, params = parameters, files = files, headers = request_headers)
2306 else:
2307 resp_obj = req_obj.post(request_url, params = parameters, headers = request_headers)
2308
2309 resp_obj = response_obj(resp_obj)
2310 except Exception as ex:
2311 resp_obj = response_obj(ex)
2312
2313 return resp_obj
2314
2316 """
2317 Internal method to handle HTTP request.
2318 """
2319 file = open(file_path,"wb")
2320
2321 if self.access_token == None:
2322 self.regenerate_analytics_oauth_token()
2323
2324 request_url = self.analytics_server_url + request_url
2325 config_data = None
2326 if bool(config):
2327 config_data = "CONFIG=" + urllib.parse.quote_plus(json.dumps(config))
2328
2329 resp_obj = self.submit_export_request(request_url, config_data, request_headers, self.access_token)
2330
2331 if not (str(resp_obj.status_code).startswith("2")):
2332 resp_obj = response_obj(resp_obj)
2333 if(self.is_oauth_expired(resp_obj)):
2334 self.regenerate_analytics_oauth_token()
2335 resp_obj = self.submit_export_request(request_url, config_data, request_headers, self.access_token)
2336 if not (str(resp_obj.status_code).startswith("2")):
2337 raise ServerError(resp_obj.resp_content, False)
2338 else:
2339 raise ServerError(resp_obj.resp_content, False)
2340
2341 file.write(resp_obj.content)
2342 file.close()
2343 return
2344
2345
2347 """
2348 Internal method to send request to server.
2349 """
2350 try:
2351 if request_headers == None:
2352 request_headers = {}
2353
2354 if access_token != None:
2355 request_headers["Authorization"] = "Zoho-oauthtoken " + access_token
2356
2357 request_headers["User-Agent"] = "Analytics Python Client v" + self.CLIENT_VERSION
2358
2359 req_obj = req_obj = requests.Session()
2360 if self.proxy:
2361 proxy_details = {
2362 "http" : "http://" + self.proxy_host + ":" + self.proxy_port,
2363 "https": "http://" + self.proxy_host + ":" + self.proxy_port
2364 }
2365 req_obj.proxies = proxy_details
2366 if self.proxy_user_name != None and self.proxy_password != None:
2367 proxy_auth_details = HTTPProxyDigestAuth(self.proxy_user_name, self.proxy_password)
2368 req_obj.auth = proxy_auth_details
2369
2370 resp_obj = req_obj.get(request_url, params = parameters, headers = request_headers)
2371
2372 except Exception as ex:
2373 resp_obj = response_obj(ex)
2374
2375 return resp_obj
2376
2377 - def send_api_request(self, request_method, request_url, config, request_headers, is_json_response = True):
2378 """
2379 Internal method to handle HTTP request.
2380 """
2381 if self.access_token == None:
2382 self.regenerate_analytics_oauth_token()
2383
2384 request_url = self.analytics_server_url + request_url
2385 config_data = None
2386 if bool(config):
2387 config_data = "CONFIG=" + urllib.parse.quote_plus(json.dumps(config))
2388
2389 resp_obj = self.submit_request(request_method, request_url, config_data, request_headers, self.access_token)
2390
2391 if not (str(resp_obj.status_code).startswith("2")):
2392 if(self.is_oauth_expired(resp_obj)):
2393 self.regenerate_analytics_oauth_token()
2394 resp_obj = self.submit_request(request_method, request_url, config_data, request_headers, self.access_token)
2395 if not (str(resp_obj.status_code).startswith("2")):
2396 raise ServerError(resp_obj.resp_content, False)
2397 else:
2398 raise ServerError(resp_obj.resp_content, False)
2399
2400
2401 if (str(resp_obj.status_code) != "200"):
2402 return
2403
2404 response = resp_obj.resp_content
2405 if is_json_response:
2406 response = json.loads(response)
2407 return response
2408
2409
2410 - def submit_request(self, request_method, request_url, parameters, request_headers = {}, access_token = None):
2411 """
2412 Internal method to send request to server.
2413 """
2414 try:
2415 if request_headers == None:
2416 request_headers = {}
2417
2418 if access_token != None:
2419 request_headers["Authorization"] = "Zoho-oauthtoken " + access_token
2420
2421 request_headers["User-Agent"] = "Analytics Python Client v" + self.CLIENT_VERSION
2422
2423 req_obj = req_obj = requests.Session()
2424 if self.proxy:
2425 proxy_details = {
2426 "http" : "http://" + self.proxy_host + ":" + self.proxy_port,
2427 "https": "http://" + self.proxy_host + ":" + self.proxy_port
2428 }
2429 req_obj.proxies = proxy_details
2430 if self.proxy_user_name != None and self.proxy_password != None:
2431 proxy_auth_details = HTTPProxyDigestAuth(self.proxy_user_name, self.proxy_password)
2432 req_obj.auth = proxy_auth_details
2433
2434 resp_obj = None
2435
2436 if request_method == "GET":
2437 resp_obj = req_obj.get(request_url, params = parameters, headers = request_headers)
2438 elif request_method == "POST":
2439 resp_obj = req_obj.post(request_url, params = parameters, headers = request_headers)
2440 elif request_method == "PUT":
2441 resp_obj = req_obj.put(request_url, params = parameters, headers = request_headers)
2442 elif request_method == "DELETE":
2443 resp_obj = req_obj.delete(request_url, params = parameters, headers = request_headers)
2444
2445 resp_obj = response_obj(resp_obj)
2446 except Exception as ex:
2447 resp_obj = response_obj(ex)
2448
2449 return resp_obj
2450
2452 """
2453 Internal method for getting OAuth token.
2454 """
2455 req_obj = requests.Session()
2456
2457 if self.proxy:
2458 proxy_details = {
2459 "http" : "http://" + self.proxy_host + ":" + self.proxy_port,
2460 "https": "http://" + self.proxy_host + ":" + self.proxy_port
2461 }
2462 req_obj.proxies = proxy_details
2463 if self.proxy_user_name != None and self.proxy_password != None:
2464 proxy_auth_details = HTTPProxyDigestAuth(self.proxy_user_name, self.proxy_password)
2465 req_obj.auth = proxy_auth_details
2466 return req_obj
2467
2468
2470 """
2471 Internal method to check whether the accesstoken expired or not.
2472 """
2473 try:
2474 resp_content = json.loads(resp_obj.resp_content)
2475 err_code = resp_content["data"]["errorCode"]
2476 return err_code == 8535
2477 except Exception:
2478 return False
2479
2480
2482 """
2483 Internal method for getting OAuth token.
2484 """
2485 oauth_params = {}
2486 oauth_params["client_id"] = self.client_id
2487 oauth_params["client_secret"] = self.client_secret
2488 oauth_params["refresh_token"] = self.refresh_token
2489 oauth_params["grant_type"] = "refresh_token"
2490 oauth_params = urllib.parse.urlencode(oauth_params)
2491 req_url = self.accounts_server_url + "/oauth/v2/token"
2492 oauth_resp_obj = self.submit_request("POST", req_url, oauth_params)
2493
2494 if(oauth_resp_obj.status_code == 200):
2495 oauth_json_resp = json.loads(oauth_resp_obj.resp_content)
2496 if("access_token" in oauth_json_resp):
2497 self.access_token = oauth_json_resp["access_token"]
2498 return
2499
2500 raise ServerError(oauth_resp_obj.resp_content, True)
2501
2502
2504 """
2505 Internal class.
2506 """
2508 self.resp_content = resp_obj.text
2509 self.status_code = resp_obj.status_code
2510 self.headers = resp_obj.headers
2511
2512
2514 """
2515 ServerError is thrown if the analytics server has received the request but did not process the
2516 request due to some error. For example if authorization failure.
2517 """
2518
2519 - def __init__(self, response, is_IAM_Error):
2520 self.errorCode = 0
2521 self.message = response
2522
2523 try:
2524 error_data = json.loads(response)
2525 if is_IAM_Error :
2526 self.message = "Exception while generating oauth token. Response - " + response
2527 else:
2528 self.errorCode = error_data["data"]["errorCode"]
2529 self.message = error_data["data"]["errorMessage"]
2530 except Exception as inst :
2531 print(inst)
2532 self.parseError = inst
2533
2535 return repr(self.message)
2536
2537
2539 """
2540 ParseError is thrown if the server has responded but client was not able to parse the response.
2541 Possible reasons could be version mismatch.The client might have to be updated to a newer version.
2542 """
2543 - def __init__(self, responseContent, message, origExcep):
2544 self.responseContent= responseContent
2545 self.message=message
2546 self.origExcep= origExcep
2547
2549 return repr(self.message)
2550