Example #1
0
        private static bool PublishContactToMautic(string json, string crmStoredMauticId, out string mauticID, out string mauticStage,
                                                   out string mauticUpdateDateTime)
        {
            // string webCall = "http://54.210.98.34/api/contacts" + crmStoredMauticId + "/edit";
            string webCall = Globals.MauticHostAddress + "api/contacts/" + crmStoredMauticId + "/edit";
            var    client  = new RestClient(webCall);
            var    request = new RestRequest(Method.PUT);

            //var client = new RestClient("http://54.210.98.34/api/contacts/new");
            //var request = new RestRequest(Method.POST);
            request.AddHeader("postman-token", "67fe23d3-9eb7-b749-d607-dfd9440c5fae");
            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("content-type", "application/json");
            request.AddHeader("authorization", "Basic Y2FybG9zOmlsb3ZlYXRsYXNrcGk=");
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);

            var rc         = response.StatusCode;
            var jsonReturn = response.Content;

            mauticID             = "0";
            mauticStage          = "Blank";
            mauticUpdateDateTime = "Blank";

            if (rc == HttpStatusCode.OK || rc == HttpStatusCode.Created)
            {
                var data = MauticContactObject.FromJson(jsonReturn);

                mauticID = data.Contact.Id.ToString();


                mauticUpdateDateTime =
                    data.Contact.DateModified != null
                        ? data.Contact.DateModified.ToString()
                        : data.Contact.DateAdded;

                mauticStage = data.Contact.Stage != null?data.Contact.Stage.ToString() : "Blank";

                return(true);
            }
            {
                return(false);
            }
        }
Example #2
0
 public static string ToJson(this MauticContactObject self) => JsonConvert.SerializeObject(self, MauticContactObjectConverter.Settings);