Beispiel #1
0
        /// <summary>
        /// This method is used to revoke access to a shared record that was shared to users and print the response.
        /// </summary>
        /// <param name="moduleAPIName">The API Name of the module to revoke shared record.</param>
        /// <param name="recordId">The ID of the record to be obtained.</param>
        public static void RevokeSharedRecord(string moduleAPIName, long recordId)
        {
            //example
            //string moduleAPIName = "Leads";
            //long recordId = 34770615177002;

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

            //Call RevokeSharedRecord method
            APIResponse <DeleteActionHandler> response = shareRecordsOperations.RevokeSharedRecord();

            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
                    DeleteActionHandler deleteActionHandler = response.Object;

                    if (deleteActionHandler is DeleteActionWrapper)
                    {
                        //Get the received DeleteActionWrapper instance
                        DeleteActionWrapper deleteActionWrapper = (DeleteActionWrapper)deleteActionHandler;

                        //Get the received DeleteActionResponse instance
                        DeleteActionResponse deleteActionResponse = deleteActionWrapper.Share;

                        //Check if the request is successful
                        if (deleteActionResponse is SuccessResponse)
                        {
                            //Get the received SuccessResponse instance
                            SuccessResponse successResponse = (SuccessResponse)deleteActionResponse;

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

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

                            Console.WriteLine("Details: ");

                            //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 (deleteActionResponse is APIException)
                        {
                            //Get the received APIException instance
                            APIException exception = (APIException)deleteActionResponse;

                            //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);
                        }
                    }
                    //Check if the request returned an exception
                    else if (deleteActionHandler is APIException)
                    {
                        //Get the received APIException instance
                        APIException exception = (APIException)deleteActionHandler;

                        //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);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// This method is used to update the sharing permissions of a record granted to users as Read-Write, Read-only, or grant full access.
        /// </summary>
        /// <param name="moduleAPIName">The API Name of the module to update share permissions.</param>
        /// <param name="recordId">The ID of the record to be obtained.</param>
        public static void UpdateSharePermissions(string moduleAPIName, long recordId)
        {
            //example
            //string moduleAPIName = "Leads";
            //long recordId = 34770615177002;

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

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

            //List of ShareRecord instances
            List <ShareRecord> shareList = new List <ShareRecord>();

            //Get instance of ShareRecord Class
            ShareRecord share1 = new ShareRecord();

            share1.ShareRelatedRecords = true;

            share1.Permission = "full_access";

            User user = new User();

            user.Id = 34770615791024;

            share1.User = user;

            shareList.Add(share1);

            request.Share = shareList;

            //Call UpdateSharePermissions method that takes BodyWrapper instance as parameter
            APIResponse <ActionHandler> response = shareRecordsOperations.UpdateSharePermissions(request);

            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
                    ActionHandler actionHandler = response.Object;

                    if (actionHandler is ActionWrapper)
                    {
                        //Get the received ActionWrapper instance
                        ActionWrapper actionWrapper = (ActionWrapper)actionHandler;

                        //Get the list of obtained ActionResponse instances
                        List <ActionResponse> actionResponses = actionWrapper.Share;

                        foreach (ActionResponse actionResponse in actionResponses)
                        {
                            //Check if the request is successful
                            if (actionResponse is SuccessResponse)
                            {
                                //Get the received SuccessResponse instance
                                SuccessResponse successResponse = (SuccessResponse)actionResponse;

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

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

                                Console.WriteLine("Details: ");

                                //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 APIException)
                            {
                                //Get the received APIException instance
                                APIException exception = (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);
                            }
                        }
                    }
                    //Check if the request returned an exception
                    else if (actionHandler is APIException)
                    {
                        //Get the received APIException instance
                        APIException exception = (APIException)actionHandler;

                        //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);
                        }
                    }
                }
            }
        }