Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
 public void testExit(WorkbooksApi workbooks, int exitcode)
 {
     if (exitcode == 0) {
     //Console.WriteLine ("Scripted exited OK");
     workbooks.log("Script exited", new Object[] {"OK"}, "info");
     } else {
     //Console.WriteLine ("Scripted exited with error");
     workbooks.log("Script exited with error", new Object[] {(int)exitcode}, "error");
     }
     System.Environment.Exit(exitcode);
 }
Esempio n. 3
0
        /// <summary>
        /// Choose a template and a Case then use it to Send an email about the Case.
        /// You can pass additional placeholders as JSON; these are merged into the template.
        /// </summary>
        public static void sendTemplatedEmail()
        {
            List <Dictionary <string, object> > templatedEmailList = new List <Dictionary <string, object> >();

            Dictionary <string, object> templatedEmail = new Dictionary <string, object>();

            templatedEmail.Add("render_with_template_name", "Autotest Template");
            templatedEmail.Add("render_with_resource_type", "Private::Crm::Case");
            templatedEmail.Add("render_with_resource_id", 2);
            templatedEmail.Add("from_address", "*****@*****.**");
            templatedEmail.Add("to_addresses", "[email protected], [email protected]");
            templatedEmail.Add("cc_addresses", "[email protected], [email protected]");
            templatedEmail.Add("bcc_addresses", "*****@*****.**");
            templatedEmail.Add("render_with_placeholders", "{\"today_date\":\"10 Jun 2014\",\"contract_value\":\"&pound;420.42\",\"credits_used\":\"42\"}");
            templatedEmail.Add("status", "SEND");

            templatedEmailList.Add(templatedEmail);
            try {
                workbooks.assertCreate("email/emails", templatedEmailList, null, null);
                workbooks.log("sendTemplatedEmail() : Email is sent successfully");
            } catch (Exception e) {
                workbooks.log("Error while sending templated Email " + e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
Esempio n. 4
0
 public void testExit(WorkbooksApi workbooks, int exitcode)
 {
     if (exitcode == 0)
     {
         //Console.WriteLine ("Scripted exited OK");
         workbooks.log("Script exited", new Object[] { "OK" }, "info");
     }
     else
     {
         //Console.WriteLine ("Scripted exited with error");
         workbooks.log("Script exited with error", new Object[] { (int)exitcode }, "error");
     }
     System.Environment.Exit(exitcode);
 }
 public void testExit(WorkbooksApi workbooks, int exitcode)
 {
     try {
     Dictionary<string, object> logout = workbooks.logout();
     if (!logout.ContainsKey("success") ) {
       workbooks.log("Logout failed", new Object[] {logout}, "error");
       System.Environment.Exit(0);
     }
     workbooks.log("Logout Complete", new Object[] {this.GetType()}, "info");
       } catch(Exception e) {
     workbooks.log("Errors while logging out: ", new Object[] {e}, "error");
       }
       if (exitcode == 0) {
     workbooks.log("Script exited", new Object[] {"OK"}, "info");
       } else {
     workbooks.log("Script exited with error", new Object[] {exitcode}, "error");
       }
       System.Environment.Exit(exitcode);
 }
Esempio n. 6
0
        /*
         * 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);
            }
        }
        public WorkbooksApi testLogin()
        {
            loginParams = new Dictionary <string, object>();
            loginParams.Add("username", username);
            loginParams.Add("password", password);
            if (System.Environment.GetEnvironmentVariable("DATABASE_ID") != null)
            {
                loginParams.Add("logical_database_id", System.Environment.GetEnvironmentVariable("DATABASE_ID"));
            }
            workbooks.log("Login commences", new Object[] { this.GetType().Name });
            Dictionary <string, object> response = null;

            try {
                response = workbooks.login(loginParams);
                int http_status = (int)response["http_status"];
                Dictionary <string, object> responseData = (Dictionary <string, object>)response["response"];
                if (response.ContainsKey("failure_reason"))
                {
                    String failure_reason = response["failure_reason"].ToString();
                    if (http_status == WorkbooksApi.HTTP_STATUS_FORBIDDEN && failure_reason.Equals("no_database_selection_made"))
                    {
                        String default_database_id = responseData["default_database_id"].ToString();
                        loginParams.Add("logical_database_id", default_database_id);

                        response    = workbooks.login(loginParams);
                        http_status = (int)response["http_status"];
                        if (http_status != WorkbooksApi.HTTP_STATUS_OK)
                        {
                            workbooks.log("Login has failed", new Object[] { response }, "error");
                            System.Environment.Exit(0);
                        }
                    }
                }
                workbooks.log("Login complete", new Object[] { this.GetType().ToString() }, "info");
            } catch (Exception e) {
                workbooks.log("Exception: ", new Object[] { e }, "error");
            }
            return(workbooks);
        }
 public void testExit(WorkbooksApi workbooks, int exitcode)
 {
     try {
         Dictionary <string, object> logout = workbooks.logout();
         if (!logout.ContainsKey("success"))
         {
             workbooks.log("Logout failed", new Object[] { logout }, "error");
             System.Environment.Exit(0);
         }
         workbooks.log("Logout Complete", new Object[] { this.GetType() }, "info");
     } catch (Exception e) {
         workbooks.log("Errors while logging out: ", new Object[] { e }, "error");
     }
     if (exitcode == 0)
     {
         workbooks.log("Script exited", new Object[] { "OK" }, "info");
     }
     else
     {
         workbooks.log("Script exited with error", new Object[] { exitcode }, "error");
     }
     System.Environment.Exit(exitcode);
 }
Esempio n. 9
0
 public WorkbooksApi testLogin()
 {
     if (service != null) {
         loginParams.Add("service", service);
     }
     loginParams.Add("application_name", application_name);
     loginParams.Add("user_agent", user_agent);
     loginParams.Add("verify_peer", verify_peer);
     if (api_key != null && api_key != "") {
         loginParams.Add("api_key", api_key);
     }
     try {
         workbooks = new WorkbooksApi(loginParams);
         Console.WriteLine("Workbooks: " + workbooks.Service);
         //				workbooks.log("Logged in with these loginParams: ", new Object[] {loginParams} );
     } catch(Exception e) {
         workbooks.log("Error while creating the Workbooks API object: ", new Object[] {e}, "error", WorkbooksApi.DEFAULT_LOG_LIMIT);
         Console.WriteLine ("Stacktrace: " + e.StackTrace);
     }
     return workbooks;
 }
Esempio n. 10
0
 public WorkbooksApi testLogin()
 {
     if (service != null)
     {
         loginParams.Add("service", service);
     }
     loginParams.Add("application_name", application_name);
     loginParams.Add("user_agent", user_agent);
     loginParams.Add("verify_peer", verify_peer);
     if (api_key != null && api_key != "")
     {
         loginParams.Add("api_key", api_key);
     }
     try {
         workbooks = new WorkbooksApi(loginParams);
         Console.WriteLine("Workbooks: " + workbooks.Service);
         //				workbooks.log("Logged in with these loginParams: ", new Object[] {loginParams} );
     } catch (Exception e) {
         workbooks.log("Error while creating the Workbooks API object: ", new Object[] { e }, "error", WorkbooksApi.DEFAULT_LOG_LIMIT);
         Console.WriteLine("Stacktrace: " + e.StackTrace);
     }
     return(workbooks);
 }
Esempio n. 11
0
    private void createOrganisations(bool doUpdate, bool doDelete, bool doBatch)
    {
        List <Dictionary <string, object> > objectIdLockVersion = null;

        try{
            //*************Multiple Organisations
            Dictionary <string, object>         org2 = new Dictionary <string, object>();
            Dictionary <string, object>         org3 = new Dictionary <string, object>();
            Dictionary <string, object>         org4 = new Dictionary <string, object>();
            List <Dictionary <string, object> > multipleOrganisations = new List <Dictionary <string, object> >();

            org2.Add("name", "Freedom & Light Ltd");
            org2.Add("created_through_reference", "12345");
            org2.Add("industry", "Media & Entertainment");
            org2.Add("main_location[country]", "United Kingdom");
            org2.Add("main_location[county_province_state]", "Berkshire");
            org2.Add("main_location[fax]", "0234 567890");
            org2.Add("main_location[postcode]", "RG99 9RG");
            org2.Add("main_location[street_address]", "100 Main Street");
            org2.Add("main_location[telephone]", "0123 456789");
            org2.Add("main_location[town]", "Beading");
            org2.Add("no_phone_soliciting", true);
            org2.Add("no_post_soliciting", true);
            org2.Add("organisation_annual_revenue", "10000000");
            org2.Add("organisation_category", "Marketing Agency");
            org2.Add("organisation_company_number", "12345678");
            org2.Add("organisation_num_employees", 250);
            org2.Add("organisation_vat_number", "GB123456");
            org2.Add("website", "www.freedomandlight.com");

            org3.Add("name", "Freedom Power Tools Limited");
            org3.Add("created_through_reference", "12346");

            org4.Add("name", "Freedom o\" the Seas Recruitment");
            org4.Add("created_through_reference", "12347");

            multipleOrganisations.Add(org2);
            multipleOrganisations.Add(org3);
            multipleOrganisations.Add(org4);

            WorkbooksApiResponse response = workbooks.assertCreate("crm/organisations", multipleOrganisations, null, null);

            workbooks.log("createOrganisations Multiple: ", new Object[] { response.print(response.getFirstAffectedObject()) });
            objectIdLockVersion = workbooks.idVersions(response);

            // **************** UPDATE THE CREATED ORGANISATION RECORDS
            if (doUpdate)
            {
                // Clear the hashmaps to populate with the details to update
                multipleOrganisations.Clear();
                org2.Clear();
                org3.Clear();
                org4.Clear();

                org2.Add("id", ((Dictionary <string, object>)objectIdLockVersion[0])["id"]);
                org2.Add("lock_version", ((Dictionary <string, object>)objectIdLockVersion[0])["lock_version"]);
                org2.Add("name", "Freedom & Light Unlimited");
                org2.Add("main_location[postcode]", "RG66 6RG");
                org2.Add("main_location[street_address]", "199 High Street");

                org3.Add("id", ((Dictionary <string, object>)objectIdLockVersion[1])["id"]);
                org3.Add("lock_version", ((Dictionary <string, object>)objectIdLockVersion[1])["lock_version"]);
                org3.Add("name", "Freedom Power");

                org4.Add("id", ((Dictionary <string, object>)objectIdLockVersion[2])["id"]);
                org4.Add("lock_version", ((Dictionary <string, object>)objectIdLockVersion[2])["lock_version"]);
                org4.Add("name", "Sea Recruitment");

                multipleOrganisations.Add(org2);
                multipleOrganisations.Add(org3);
                multipleOrganisations.Add(org4);

                response = workbooks.assertUpdate("crm/organisations", multipleOrganisations, null, null);
                workbooks.log("Updated organisations ", new Object[] { response.print(response.getFirstAffectedObject()) });
            }
            objectIdLockVersion = workbooks.idVersions(response);

            if (doBatch)
            {
                //************** BATCH ALL
                Dictionary <string, object>         createAction        = new Dictionary <string, object> ();
                Dictionary <string, object>         updateAction        = new Dictionary <string, object> ();
                Dictionary <string, object>         deleteAction        = new Dictionary <string, object> ();
                Dictionary <string, object>         deleteAnotherAction = new Dictionary <string, object> ();
                List <Dictionary <string, object> > batchActions        = new List <Dictionary <string, object> >();


                createAction.Add("method", "CREATE");
                createAction.Add("name", "Abercrombie Pies");
                createAction.Add("industry", "Food");
                createAction.Add("main_location[country]", "United Kingdom");
                createAction.Add("main_location[county_province_state]", "Berkshire");
                createAction.Add("main_location[town]", "Beading");

                updateAction.Add("method", "UPDATE");
                updateAction.Add("id", ((Dictionary <string, object>)objectIdLockVersion[0])["id"]);
                updateAction.Add("lock_version", ((Dictionary <string, object>)objectIdLockVersion[0])["lock_version"]);
                updateAction.Add("name", "Lights \'R Us");
                updateAction.Add("main_location[postcode]", null);

                deleteAction.Add("method", "DELETE");
                deleteAction.Add("id", ((Dictionary <string, object>)objectIdLockVersion[1])["id"]);
                deleteAction.Add("lock_version", ((Dictionary <string, object>)objectIdLockVersion[1])["lock_version"]);

                deleteAnotherAction.Add("id", ((Dictionary <string, object>)objectIdLockVersion[2])["id"]);
                deleteAnotherAction.Add("lock_version", ((Dictionary <string, object>)objectIdLockVersion[2])["lock_version"]);
                deleteAnotherAction.Add("method", "DELETE");

                batchActions.Add(createAction);
                batchActions.Add(updateAction);
                batchActions.Add(deleteAction);
                batchActions.Add(deleteAnotherAction);

                response = workbooks.assertBatch("crm/organisations", batchActions, null, null, null);
                workbooks.log("Batch Actions: ", new Object[] { response.print(response.getFirstAffectedObject()) });
            }
            objectIdLockVersion = workbooks.idVersions(response);

            //************** CREATE A SINGLE ORGANISATION
            List <Dictionary <string, object> > singleOrganisation = new List <Dictionary <string, object> >();
            Dictionary <string, object>         org1 = new Dictionary <string, object>();

            org1.Add("name", "Birkbeck Burgers");
            org1.Add("industry", "Food");
            org1.Add("main_location[country]", "United Kingdom");
            org1.Add("main_location[county_province_state]", "Oxfordshire");
            org1.Add("main_location[town]", "Oxford");

            singleOrganisation.Add(org1);
            response = workbooks.assertCreate("crm/organisations", singleOrganisation, null, null);
            workbooks.log("createOrganisations Single: ", new Object[] { response.getFirstAffectedObject() });
            List <Dictionary <string, object> > createdObjectIdLockVersion = workbooks.idVersions(response);

            createdObjectIdLockVersion.Add((Dictionary <string, object>)objectIdLockVersion[0]);
            createdObjectIdLockVersion.Add((Dictionary <string, object>)objectIdLockVersion[1]);
            //***************** DELETE THE REMAIIG ORGANISATIONS CREATED IN THIS CLASS
            if (doDelete)
            {
                workbooks.assertDelete("crm/organisations", createdObjectIdLockVersion, null, null);
                workbooks.log("Delete Organisations ");
            }
        } catch (Exception e) {
            Console.WriteLine(e.StackTrace);
        }
    }
Esempio n. 12
0
        public void createAPIData()
        {
            Dictionary <string, object> testValues = new Dictionary <string, object> ();

            testValues.Add("the answer", 42);
            testValues.Add("poppins", "Supercalifragilisticexpealidocious");
            testValues.Add("null", null);
            testValues.Add("ten thousand characters", repeat("123456789", 1000));
            testValues.Add("multibyte_characters", " 'д е ё ж з и й к л  字 字");

            Dictionary <string, object> apiData = null;

            List <Dictionary <string, object> > apiDataList = new List <Dictionary <string, object> >();

            foreach (string key in testValues.Keys)
            {
                apiData = new Dictionary <string, object> ();
                apiData.Add("key", "api_data_example: " + key);
                apiData.Add("value", testValues[key]);

                apiDataList.Add(apiData);
            }

            WorkbooksApiResponse response;

            try {
                response = workbooks.assertCreate("automation/api_data", apiDataList, null, null);
                List <Dictionary <string, object> > idVersionObjects = workbooks.idVersions(response);

                workbooks.log("createAPIData: First Object- ", new Object[] { response.getFirstAffectedObject() });

                apiData.Clear();
                apiDataList.Clear();

                // Update two API Data entries
                apiData.Add("id", ((Dictionary <string, object>)idVersionObjects[0])["id"]);
                apiData.Add("lock_version", ((Dictionary <string, object>)idVersionObjects[0])["lock_version"]);
                apiData.Add("value", 17);
                apiDataList.Add(apiData);

                Dictionary <string, object> apiData1 = new Dictionary <string, object> ();
                apiData1.Add("id", ((Dictionary <string, object>)idVersionObjects[2])["id"]);
                apiData1.Add("lock_version", ((Dictionary <string, object>)idVersionObjects[2])["lock_version"]);
                apiData1.Add("value", "null points");
                apiDataList.Add(apiData1);

                response = workbooks.assertUpdate("automation/api_data", apiDataList, null, null);

                workbooks.log("Updated API Data: First Object- ", new Object[] { response.getFirstAffectedObject() });
            } catch (Exception e) {
                workbooks.log("Exception while creating apidata", new Object[] { e }, "error");
                Console.WriteLine(e.StackTrace);
                login.testExit(workbooks, 1);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Create two people, tagging with their identifiers in the external system. Up to 100 can be done in one batch.
        /// </summary>
        /// <param name="doUpdate">If set to <c>true</c> do update on the created people record.</param>
        /// <param name="doDelete">If set to <c>true</c> do delete on the created people record.</param>
        private void createTwoPeople(bool doUpdate, bool doDelete)
        {
            List <Dictionary <string, object> > twoPeople = new List <Dictionary <string, object> >();

            Dictionary <string, object>         person1             = new Dictionary <string, object>();
            List <Dictionary <string, object> > objectIdLockVersion = null;

            person1.Add("name", "Csharp Rich Richards");
            person1.Add("created_through_reference", "101");
            person1.Add("main_location[country]", "UK");
            person1.Add("main_location[county_province_state]", "Berkshire");
            person1.Add("main_location[fax]", "01234 54646");
            person1.Add("main_location[postcode]", "RG6 1AZ");
            person1.Add("main_location[street_address]", "100 Civvy Street");
            person1.Add("main_location[telephone]", "011897656");
            person1.Add("main_location[town]", "Reading");
            person1.Add("no_email_soliciting", false);
            person1.Add("no_phone_soliciting", true);
            person1.Add("no_post_soliciting", true);
            person1.Add("person_first_name", "Richard");
            person1.Add("person_middle_name", "");
            person1.Add("person_last_name", "Richards");
            person1.Add("person_personal_title", "Mr.");
            person1.Add("website", "www.richards.me.uk");

            Dictionary <string, object> person2 = new Dictionary <string, object>();

            //String[][] person2 = ...
            person2.Add("name", "Csharp Stevie Stephens");
            person2.Add("created_through_reference", "102");
            person2.Add("main_location[country]", "UK");
            person2.Add("main_location[county_province_state]", "Berkshire");
            person2.Add("main_location[fax]", "01234 54646");
            person2.Add("main_location[postcode]", "RG6 1AZ");
            person2.Add("main_location[street_address]", "102 Castle Street");
            person2.Add("main_location[telephone]", "011897656");
            person2.Add("main_location[town]", "Reading");
            person2.Add("no_email_soliciting", false);
            person2.Add("no_phone_soliciting", true);
            person2.Add("no_post_soliciting", true);
            person2.Add("person_first_name", "Steve");
            person2.Add("person_middle_name", "");
            person2.Add("person_last_name", "Stephens");
            person2.Add("person_personal_title", "Mr.");
            person2.Add("website", "www.steve.me.uk");


            twoPeople.Add(person1);
            twoPeople.Add(person2);
            try {
                WorkbooksApiResponse response = workbooks.assertCreate("crm/people", twoPeople, null, null);

                object[] allData = response.getAffectedObjects();

                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"]);
                }

                // **************** UPDATE THE TWO CREATED PEOPLE RECORDS
                if (doUpdate)
                {
                    objectIdLockVersion = workbooks.idVersions(response);

                    // Clear the hashmaps to populate with the details to update
                    twoPeople.Clear();
                    person1.Clear();
                    person2.Clear();

                    person1.Add("id", ((Dictionary <string, object>)objectIdLockVersion[0])["id"]);
                    person1.Add("lock_version", ((Dictionary <string, object>)objectIdLockVersion[0])["lock_version"]);
                    person1.Add("main_location[email]", "*****@*****.**");

                    person2.Add("id", ((Dictionary <string, object>)objectIdLockVersion[1])["id"]);
                    person2.Add("lock_version", ((Dictionary <string, object>)objectIdLockVersion[1])["lock_version"]);
                    person2.Add("main_location[email]", "*****@*****.**");

                    twoPeople.Add(person1);
                    twoPeople.Add(person2);

                    workbooks.assertUpdate("crm/people", twoPeople, null, null);
                    Console.WriteLine("Updated people. ");
                    //workbooks.log("update_two_people", new Object[] {responseUpdate.getFirstAffectedObjects()});
                }
                //***************** DELETE THE TWO CREATED PEOPLE
                if (doDelete)
                {
                    objectIdLockVersion = workbooks.idVersions(response);

                    WorkbooksApiResponse responseDelete = workbooks.assertDelete("crm/people", objectIdLockVersion, null, null);

                    workbooks.log("delete_two_people", new Object[] { responseDelete.getFirstAffectedObject() });
                }
            } catch (Exception wbe) {
                Console.WriteLine("Error while creating the people record: " + wbe.Message);
                Console.WriteLine(wbe.StackTrace);
                testLoginHelper.testExit(workbooks, 1);
            }
        }