/// <summary> /// Gets the people based on the filters given /// </summary> public void getPeople() { Dictionary <string, object> filter_limit_select = new Dictionary <string, object> (); filter_limit_select.Add("_start", "0"); filter_limit_select.Add("_limit", "3"); filter_limit_select.Add("_sort", "id"); filter_limit_select.Add("_dir", "ASC"); filter_limit_select.Add("_ff[]", "name"); filter_limit_select.Add("_ft[]", "bg"); filter_limit_select.Add("_fc[]", "Alex"); filter_limit_select.Add("_select_columns[]", columns); try { WorkbooksApiResponse response = workbooks.get("crm/people", filter_limit_select, null); object[] allData = response.getData(); if (allData != null) { Console.WriteLine("Response Total: " + response.getTotal()); for (int i = 0; i < allData.Length; i++) { Dictionary <string, object> data = (Dictionary <string, object>)allData[i]; Console.WriteLine("Person name: " + data["name"] + " Object Ref: " + data["object_ref"]); } } } catch (Exception wbe) { Console.WriteLine("Error while getting the people record: " + wbe.Message); Console.WriteLine("Stacktrace: " + wbe); testLoginHelper.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); }
/* * 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); } }
// The equivalent using a second filter structure: a JSON-formatted string array of arrays containg 'field, comparator, contents' public WorkbooksApiResponse getOrganisationsViaFilterJson() { Dictionary <string, object> filter3 = new Dictionary <string, object> (); /* * Syntax to create array of arrays is * 1) [[a, b, c], [x,y,z], [1,2,3]]; Note the two square brackets * 2) new String[][] {new string[]{a,b,c}, new string[] {x,y,z},new string[] {1,2,3}} see the above method for this syntax */ //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("_filter_json", "[" + "['main_location[county_province_state]', 'eq', 'Berkshire']," + "['main_location[county_province_state]', 'ct', 'Yorkshire']," + "['main_location[street_address]', 'not_blank', '']" + "]"); filter3.Add("_fm", "(1 OR 2) AND 3"); try{ WorkbooksApiResponse response3 = workbooks.assertGet("crm/organisations", filter3, null); //workbooks.log("getOrganisationsViaFilterJson 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.Message); Console.WriteLine(wbe.StackTrace); login.testExit(workbooks, 1); } return(null); }
// The equivalent using a third filter structure: an array of filters, each containg 'field, comparator, contents'. public WorkbooksApiResponse getOrganisationsViaFilterArray() { Dictionary <string, object> filter3 = new Dictionary <string, object> (); /* Merge the limit_select and then add array of arrays * Syntax to create array of arrays is * 1) [[a, b, c], [x,y,z], [1,2,3]]; Note the two square brackets . See below method for example * 2) new String[][] {new string[]{a,b,c}, new string[] {x,y,z},new string[] {1,2,3}} */ //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("_filters[]", new String[][] { new string[] { "main_location[county_province_state]", "eq", "Berkshire" }, new string[] { "main_location[county_province_state]", "ct", "Yorkshire" }, new string[] { "main_location[street_address]", "not_blank", "" } }); 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); Console.WriteLine("Total: " + response3.getTotal()); //workbooks.log("getOrganisationsViaFilterArray First: ", new Object[] {response3.getFirstData()}); 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.Message); Console.WriteLine(wbe.StackTrace); login.testExit(workbooks, 1); } return(null); }