public void fetchSummary() { string[] classNames = { "Private::Searchable", "Private::Crm::Person", "Private::Crm::Organisation", "Private::Crm::Case" }; Dictionary <string, object> classMetaData = new Dictionary <string, object> (); classMetaData.Add("class_names[]", classNames); classMetaData.Add("_select_columns[]", columns); try { WorkbooksApiResponse response = workbooks.assertGet("metadata/types", classMetaData, null); workbooks.log("fetchSummary Total: ", new Object[] { response.getTotal() }); // if (response.getTotal() != null && response.getTotal() > 0) { // workbooks.log("fetchSummary First: ", new Object[] {response.getFirstData()}); // } } catch (Exception e) { Console.WriteLine("Error while getting the metadata: " + e.Message); Console.WriteLine(e.StackTrace); login.testExit(workbooks, 1); } }
/* * Fetch four of them back, all available fields */ public void getAPIData() { Dictionary <string, object> filter3 = new Dictionary <string, object> (); //Merge the limit_select and then add array of arrays filter3.Add("_sort", "id"); filter3.Add("_dir", "ASC"); filter3.Add("_ff[]", new String[] { "key", "key", "key", "key" }); filter3.Add("_ft[]", new String[] { "eq", "eq", "eq", "eq" }); filter3.Add("_fc[]", new String[] { "api_data_example: the answer", "api_data_example: null", "api_data_example: ten thousand characters", "api_data_example: multibyte characters" }); filter3.Add("_fm", "or"); try { WorkbooksApiResponse response = workbooks.assertGet("automation/api_data", filter3, null); workbooks.log("getAPIData Total fetched", new Object[] { response.getTotal() }); workbooks.log("getAPIData First Data", new Object[] { response.getFirstData() }); } catch (Exception e) { workbooks.log("Error while getting the apiData:", new Object[] { e }); Console.WriteLine(e.StackTrace); login.testExit(workbooks, 1); } }
// First filter structure: specify arrays for Fields ('_ff[]'), comparaTors ('_ft[]'), Contents ('_fc[]'). // Note that 'ct' (contains) is MUCH slower than equals. 'not_blank' requires Contents to compare with, but this is ignored. public WorkbooksApiResponse getOrganisationsViaFilter() { Dictionary <string, object> filter3 = new Dictionary <string, object> (); //Merge the limit_select and then add array of arrays foreach (string limitKey in limit_select.Keys) { filter3.Add(limitKey, limit_select [limitKey]); } filter3.Add("_ff[]", new String[] { "main_location[county_province_state]", "main_location[county_province_state]", "main_location[street_address]" }); filter3.Add("_ft[]", new String[] { "eq", "ct", "not_blank" }); filter3.Add("_fc[]", new String[] { "Berkshire", "Yorkshire", "" }); filter3.Add("_fm", "(1 OR 2) AND 3"); // How to combine the above clauses, without this: 'AND'. try { WorkbooksApiResponse response3 = workbooks.assertGet("crm/organisations", filter3, null); //workbooks.log("getOrganisationsViaFilter First ", new Object[] {response3.getFirstData()}); Console.WriteLine("Total: " + response3.getTotal()); object[] allData = response3.getData(); for (int i = 0; i < allData.Length; i++) { Dictionary <string, object> data = (Dictionary <string, object>)allData[i]; Console.WriteLine(i + ") " + data["name"] + " - " + data["main_location[county_province_state]"]); } return(response3); } catch (Exception wbe) { Console.WriteLine("Error while getting the Organisations record: " + wbe); Console.WriteLine(wbe.StackTrace); login.testExit(workbooks, 1); } return(null); }
private void getOrganisations() { String[] columns = { "id", "lock_version", "name", "object_ref", "main_location[town]", "updated_at", "updated_by_user[person_name]" }; Dictionary <string, object> filter_limit_select = new Dictionary <string, object> (); filter_limit_select.Add("_start", "0"); // Starting from the 'zeroth' record filter_limit_select.Add("_limit", "100"); // fetch up to 100 records filter_limit_select.Add("_sort", "id"); // Sort by 'id' filter_limit_select.Add("_dir", "ASC"); // in ascending order filter_limit_select.Add("_ff[]", "main_location[county_province_state]"); // Filter by this column filter_limit_select.Add("_ft[]", "ct"); // containing filter_limit_select.Add("_fc[]", "Berkshire"); // 'Berkshire' filter_limit_select.Add("_select_columns[]", columns); // An array, of columns to select try { WorkbooksApiResponse response = workbooks.assertGet("crm/organisations", filter_limit_select, null); workbooks.log("Total organisations: ", new Object[] { response.getTotal() }); workbooks.log("First Organisation: ", new object[] { response.print(response.getFirstData()) }); } catch (Exception e) { Console.WriteLine(e.StackTrace); } }
/* * In order to generate a PDF you need to know the ID of the transaction document (the * order, quotation, credit note etc) and the ID of a PDF template. You can find these out * for a particular PDF by using the Workbooks Desktop, generating a PDF and examining the * URL used to generate the PDF. You will see something like * * https://secure.workbooks.com/accounting/sales_orders/11941.pdf?template=232 * * which implies a document ID of 11941 and a template ID of 232. The 'sales_orders' part * indicates the type of transaction document you want to reference; see the Workbooks API * Reference for a list of the available API endpoints. */ public void generatePDFs() { Dictionary <string, object> filter_limit_select = new Dictionary <string, object> (); filter_limit_select.Add("_start", "0"); filter_limit_select.Add("_limit", "1"); filter_limit_select.Add("_sort", "id"); filter_limit_select.Add("_dir", "ASC"); filter_limit_select.Add("_select_columns[]", new String[] { "id" }); try { WorkbooksApiResponse response = workbooks.assertGet("accounting/sales_orders", filter_limit_select, null); object[] allData = response.getData(); if (allData != null) { if (allData.Length != 1) { workbooks.log("generatePDFs: Did not find any orders: ", new Object[] { allData }); login.testExit(workbooks, 1); } else { int orderId = (int)((Dictionary <string, object>)allData[0])["id"]; // Now generate the PDF String url = "accounting/sales_orders/" + orderId + ".pdf"; // Important to add the decode_json as false for PDFs Dictionary <string, object> options = new Dictionary <string, object> (); options.Add("decode_json", false); Dictionary <string, object> templateParams = new Dictionary <string, object> (); templateParams.Add("template", pdfTemplateId); workbooks.get(url, templateParams, options); workbooks.log("generatePDFs finished"); } } } catch (Exception wbe) { workbooks.log("Exception while generating PDF", new Object[] { wbe }, "error"); Console.WriteLine(wbe.StackTrace); login.testExit(workbooks, 1); } }