Exemplo n.º 1
0
        //Send an updated Contact to Zoho
        public string UpdateContact(Contact contact, string orgId)
        {
            if (OAuthTokenTime.AddMinutes(59) > DateTime.Now)
            {
                OAuthToken = GetRestOAuthToken();
            }
            string authToken  = OAuthToken;
            string serviceURL = Properties.Settings.Default.ZohoAPIURL;

            RestClient  restClient = new RestClient(serviceURL);
            RestRequest request    = new RestRequest("contact/" + contact.id)
            {
                Method = Method.PATCH
            };

            request.AddHeader("orgId", orgId);
            request.AddHeader("Authorization", authToken);
            request.AddJsonBody(JsonConvert.SerializeObject(contact));
            var tResponse = restClient.Execute(request);

            if (tResponse.ResponseStatus == ResponseStatus.Completed)
            {
                return(tResponse.Content);
            }
            else
            {
                throw new RestRequestException()
                      {
                          HttpStatusCode = tResponse.StatusCode, ResponseStatus = tResponse.ResponseStatus
                      };
            }
        }
Exemplo n.º 2
0
        //Returns a string Rest response based on the path sent, and an optional orgId
        //OrgId is needed for all requests other than getting Organization Ids
        public string GetRestResponse(string requestPath, string orgId = null)
        {
            if (OAuthTokenTime.AddMinutes(59) > DateTime.Now)
            {
                OAuthToken = GetRestOAuthToken();
            }
            string      authToken  = OAuthToken;
            string      serviceURL = Properties.Settings.Default.ZohoAPIURL;
            RestClient  restClient = new RestClient(serviceURL);
            RestRequest request    = new RestRequest("requestPath");

            if (orgId != null)
            {
                request.AddHeader("orgId", orgId);
            }
            request.AddHeader("Authorization", authToken);
            var tResponse = restClient.Execute(request);

            if (tResponse.ResponseStatus == ResponseStatus.Completed)
            {
                return(tResponse.Content);
            }
            else
            {
                throw new RestRequestException()
                      {
                          HttpStatusCode = tResponse.StatusCode, ResponseStatus = tResponse.ResponseStatus
                      };
            }
        }