private AutomationInfo GetAutomationInfoFromResponse(string response) { string requestId = string.Empty; if (string.IsNullOrEmpty(response)) { return(null); } XmlDocument doc = new XmlDocument(); doc.LoadXml(response); string jsonText = JsonConvert.SerializeXmlNode(doc); JObject jObject = JObject.Parse(jsonText); string status = string.Empty; string requestResponse = string.Empty; var retrieveResponseMsg = jObject.Descendants() .Where(x => x is JObject) .Where(x => x["RetrieveResponseMsg"] != null).First(); if (retrieveResponseMsg != null) { status = (string)retrieveResponseMsg.SelectToken("$['RetrieveResponseMsg']['OverallStatus']"); requestResponse = (string)retrieveResponseMsg.SelectToken("$['RetrieveResponseMsg']['RequestID']"); } else { return(null); } if (status != "OK") { requestId = requestResponse; } AutomationInfo automationInfo = new AutomationInfo(); automationInfo.Status = status; var results = retrieveResponseMsg.SelectToken("$['RetrieveResponseMsg']['Results']"); if (results != null) { var customerKey = results.Value <string>("CustomerKey"); var objectId = results.Value <string>("ObjectID"); var name = results.Value <string>("Name"); automationInfo.CustomerKey = customerKey; automationInfo.ObjectID = objectId; automationInfo.Name = name; } return(automationInfo); }
private async Task <string> GetStartAutomationRequestMessage(AutomationInfo automationInfo) { if (accessToken == null || !accessToken.IsValid) { BearerToken tokenBuilder = new BearerToken(AuthenticationURL); accessToken = await tokenBuilder.GetAccessToken(this.clientId, this.secret); } StringBuilder builder = new StringBuilder(); builder.Append($"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Header><fueloauth xmlns=\"http://exacttarget.com\">{accessToken.Token}</fueloauth></s:Header>"); builder.Append("<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><PerformRequestMsg xmlns=\"http://exacttarget.com/wsdl/partnerAPI\">"); builder.Append($"<Options/><Action>start</Action><Definitions><Definition xsi:type=\"Automation\"><PartnerKey xsi:nil=\"true\"/><ObjectID>{automationInfo.ObjectID}</ObjectID></Definition></Definitions>"); builder.Append("</PerformRequestMsg></s:Body></s:Envelope>"); return(builder.ToString()); }
private async Task <string> GetScheduleAutomationRequestMessage(AutomationInfo automationInfo) { if (accessToken == null || !accessToken.IsValid) { BearerToken tokenBuilder = new BearerToken(AuthenticationURL); accessToken = await tokenBuilder.GetAccessToken(this.clientId, this.secret); } StringBuilder builder = new StringBuilder(); builder.Append($"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\"><s:Header><fueloauth xmlns=\"http://exacttarget.com\">{accessToken.Token}</fueloauth></s:Header>"); builder.Append("<s:Body xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><ScheduleRequestMsg xmlns=\"http://exacttarget.com/wsdl/partnerAPI\">"); builder.Append($"<Options/><Action>start</Action><Interactions><Interaction xsi:type=\"Automation\"><PartnerKey xsi:nil=\"true\"/><ObjectID>{automationInfo.ObjectID}</ObjectID></Interaction></Interactions>"); builder.Append($"<Schedule><StartDateTime>{DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss")}</StartDateTime><RecurrenceType>Hourly</RecurrenceType><RecurrenceRangeType>EndOn</RecurrenceRangeType><Occurrences>2</Occurrences></Schedule>"); builder.Append($"<ScheduleOptions>{DateTime.Now.AddDays(1).ToString("yyyy-MM-ddTHH:mm:ss")}</ScheduleOptions>"); builder.Append("</ScheduleRequestMsg></s:Body></s:Envelope>"); return(builder.ToString()); }