Code Examples

Objects (for organizations, people, cases, etc.) have similar API calls (list, get, add, update, delete)

Use the code examples below as a guide for coding proper API calls specific to each BlueCamroo object. The examples show how to get, add, update, and search for Organizations. Objects differ in terms of URL, HTTP method (GET, POST, HTTP return status code, and object properties you can get/set. Consult the API documentation for these object specifics.

Get


		public Organization GetOrganization(int organizationId) {
			var organization = new Organization();
			var url = baseUrl + "api/account/get/" + organizationId;

			int status = WebRequest(method:"GET", url, data:null, ref result, contentType: "application/json");

			if (status == HttpStatusCode.OK) {
				organization = JsonDeserialize(result);
				Console.Write("id is: " + organization.Id);
			}
			else {
				// error handling
			}

			return organization;
		}

Add

		 
		public void AddOrganization() {
			var organization = new Organization();
			organization.Id = 0; // this is important when adding, the id is 0
			organization.Name = "My client company name";
			organization.PriceBookId = 1;

			// set other properties.

			var url = baseUrl + "api/account/add";

			var data = JsonSerialize(organization);

			int status = WebRequest(methdod:"POST", url, data, ref result, contentType: "application/json");

			if (status == HttpStatusCode.Created) {
				organization = JsonDeserialize(result);
				Console.Write("New organization id is: " + organization.Id);
			}
			else {
				// error handling
			}
		}

Update


		public void UpdateOrganizaion() {
			var organizationId = 1;
			var organization = GetOrganization(organizationId);

			// modify properties, for example:

			organization.PriceBookId = 2 //new price book id

			var data = JsonSerialize(organization);
			var url = baseUrl + "api/account/update";

			int status = WebRequest(methdod:"PUT", url, data, ref result, contentType: "application/json");

			if (status == HttpStatusCode.OK) {
				organization = JsonDeserialize(result);				
			}
			else {
				// error handling
			}
		}

Delete


		public void DeleteOrganization(int organizationId) {
			var url = baseUrl + "api/account/delete/" + organizationId;

			int status = WebRequest(method:"DELETE", url, data:null, ref result, contentType:"application/json");

			if (status == HttpStatusCode.NoContent) {
				// success
			}
			else {
				// error handling
			}
		}

Search


		public void SearchOrganization() {
			var searchCriteria = new UserSearchCriteria();

			searchCriteria.CriteriaGroupList.Add(new CriteriaGroup());
			searchCriteria.CriteriaGroupList[0].CriteriaFieldList.Add(new CriteriaField());

			var criteriaField = searchCriteria.CriteriaGroupList[0].CriteriaFieldList[0];
			
			// this will search for organization where ownerId = 1

			criteriaField.FieldName = "ownerId";
			criteriaField.Operator = "=";
			criteriaField.FieldValue = "1";

			var url = baseUrl + "api/account/search";
			var data = JsonSerialize(searchCriteria);

			int status = WebRequest(method:"POST", url, data, ref result, contentType:"application/json");

			if (status == HttpStatusCode.OK) {
				// success;

				List<Organization> organizationList = JsonDeserialize(result);

				for (int i=0; i<= organziationList.Count; i++) {
					// loop through each organziation
				}
			}
		}