Skip to main content

C# SDK Samples - Blueprint Operations

Get Blueprint Details
Update Blueprint
              
              
using System;

using System.Collections.Generic;

using System.Reflection;

using Com.Zoho.Crm.API.BluePrint;

using Com.Zoho.Crm.API.Fields;

using Com.Zoho.Crm.API.Layouts;

using Com.Zoho.Crm.API.Users;

using Com.Zoho.Crm.API.Util;

using Newtonsoft.Json;

namespace Com.Zoho.Crm.Sample.BluePrint
{
    public class BluePrint
    {
        /// 
        /// This method is used to update a single record's Blueprint details with ID and print the response.
        /// 
        /// The API Name of the record's module
        /// The ID of the record to Get Blueprint
        /// The ID of the Blueprint transition Id
        public static void UpdateBlueprint (string moduleAPIName, long recordId, long transitionId)
		{
			//ID of the BluePrint to be updated
			//string moduleAPIName = "Leads";
			//long recordId = 34770614381002;
			//long transitionId = 34770610173096;

			//Get instance of BluePrintOperations Class that takes recordId and moduleAPIName as parameter
			BluePrintOperations bluePrintOperations = new BluePrintOperations (recordId, moduleAPIName);

            //Get instance of BodyWrapper Class that will contain the request body
            API.BluePrint.BodyWrapper bodyWrapper = new API.BluePrint.BodyWrapper();

			//List of BluePrint instances
			List<API.BluePrint.BluePrint> bluePrintList = new List<API.BluePrint.BluePrint>();

			//Get instance of BluePrint Class
			API.BluePrint.BluePrint bluePrint = new API.BluePrint.BluePrint();

            //Set transition_id to the BluePrint instance
            bluePrint.TransitionId = transitionId;

            //Get instance of Record Class
            Com.Zoho.Crm.API.Record.Record data = new Com.Zoho.Crm.API.Record.Record();

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

			lookup.Add("Phone", "8940372937");

			lookup.Add("id", "8940372937");

            //data.AddKeyValue("Lookup_2", lookup);

            data.AddKeyValue("Phone", "8940372937");

			data.AddKeyValue("Notes", "Updated via blueprint");

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

			List<string> fileIds = new List<string>();
			
			fileIds.Add("blojtd2d13b5f044e4041a3315e0793fb21ef");
			
			attachments.Add("$file_id", fileIds);
			
			//data.AddKeyValue("Attachments", attachments);

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

			Dictionary<string, object> checkListItem = new Dictionary<string, object>();
			
			checkListItem.Add("list 1", true);
			
			checkLists.Add(checkListItem);
			
			checkListItem = new Dictionary<string, object>();
			
			checkListItem.Add("list 2", true);
			
			checkLists.Add(checkListItem);
			
			checkListItem = new Dictionary<string, object>();
			
			checkListItem.Add("list 3", true);
			
			checkLists.Add(checkListItem);
			
			//data.AddKeyValue("CheckLists", checkLists);

            //Set data to the BluePrint instance
            bluePrint.Data = data;

            //Add BluePrint instance to the list
            bluePrintList.Add(bluePrint);

			//Set the list to bluePrint in BodyWrapper instance
			bodyWrapper.Blueprint = bluePrintList;

			//Call UpdateBlueprint method that takes BodyWrapper instance 
			APIResponse<API.BluePrint.ActionResponse> response = bluePrintOperations.UpdateBlueprint(bodyWrapper);

			if (response != null)
            {
				//Get the status code from response
				Console.WriteLine("Status Code: " + response.StatusCode);

				//Check if expected response is received
				if (response.IsExpected)
                {
                    //Get object from response
                    API.BluePrint.ActionResponse actionResponse = response.Object;

					//Check if the request is successful
					if (actionResponse is API.BluePrint.SuccessResponse)
                    {
                        //Get the received SuccessResponse instance
                        API.BluePrint.SuccessResponse successResponse = (API.BluePrint.SuccessResponse) actionResponse;

						//Get the Status
						Console.WriteLine("Status: " + successResponse.Status.Value);

						//Get the Code
						Console.WriteLine("Code: " + successResponse.Code.Value);

						Console.WriteLine("Details: ");

						if (successResponse.Details != null)
                        {
							//Get the details map
							foreach (KeyValuePair<string, object> entry in successResponse.Details)
							{
								//Get each value in the map
								Console.WriteLine(entry.Key + " : " + JsonConvert.SerializeObject(entry.Value));
							}
						}

						//Get the Message
						Console.WriteLine("Message: " + successResponse.Message.Value);
					}
					//Check if the request returned an exception
					else if (actionResponse is API.BluePrint.APIException)
                    {
                        //Get the received APIException instance
                        API.BluePrint.APIException exception = (API.BluePrint.APIException) actionResponse;

						//Get the Status
						Console.WriteLine("Status: " + exception.Status.Value);

						//Get the Code
						Console.WriteLine("Code: " + exception.Code.Value);

						Console.WriteLine("Details: ");

						//Get the details map
						foreach (KeyValuePair<string, object> entry in exception.Details)
						{
							//Get each value in the map
							Console.WriteLine(entry.Key + " : " + JsonConvert.SerializeObject(entry.Value));
						}

						//Get the Message
						Console.WriteLine("Message: " + exception.Message.Value);
					}
				} 
				else
				{ //If response is not as expected

					//Get model object from response
					Model responseObject = response.Model;

					//Get the response object's class
					Type type = responseObject.GetType();

					//Get all declared fields of the response class
					Console.WriteLine("Type is: {0}", type.Name);

					PropertyInfo[] props = type.GetProperties();

					Console.WriteLine("Properties (N = {0}):", props.Length);

					foreach (var prop in props)
					{
						if (prop.GetIndexParameters().Length == 0)
						{
							Console.WriteLine("{0} ({1}) : {2}", prop.Name, prop.PropertyType.Name, prop.GetValue(responseObject));
						}
						else
						{
							Console.WriteLine("{0} ({1}) : <Indexed>", prop.Name, prop.PropertyType.Name);
						}
					}
				}
			}
		}
    }
}