Exemplo n.º 1
0
        public void RetrieveFolderStructure(string id, ET_Client etClient, string contentType, string path)
        {
            // Create the SOAP binding for call.
                BasicHttpBinding binding = new BasicHttpBinding();
                binding.Name = "UserNameSoapBinding";
                binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
                binding.MaxReceivedMessageSize = 2147483647;
                var client = new FuelSDK.SoapClient(binding, etClient.soapclient.Endpoint.Address);
                client.ClientCredentials.UserName.UserName = "******";
                client.ClientCredentials.UserName.Password = "******";

                using (var scope = new OperationContextScope(client.InnerChannel))
                {
                    // Add oAuth token to SOAP header.
                    XNamespace ns = "http://exacttarget.com";
                    var oauthElement = new XElement(ns + "oAuthToken", etClient.internalAuthToken);
                    var xmlHeader = MessageHeader.CreateHeader("oAuth", "http://exacttarget.com", oauthElement);
                    OperationContext.Current.OutgoingMessageHeaders.Add(xmlHeader);

                    List<object> folders = new List<object>();

                    String requestID;
                    String status;
                    APIObject[] results;

                    SimpleFilterPart sfp = new SimpleFilterPart();
                    sfp.Property = "ContentType";
                    sfp.SimpleOperator = SimpleOperators.equals;
                    sfp.Value = new string[] { contentType };

                    SimpleFilterPart rf = new SimpleFilterPart();
                    rf.Property = "ParentFolder.ID";
                    rf.SimpleOperator = SimpleOperators.equals;
                    rf.Value = new string[] { id };

                    ComplexFilterPart cfp = new ComplexFilterPart();
                    cfp.LeftOperand = sfp;
                    cfp.LogicalOperator = LogicalOperators.AND;
                    cfp.RightOperand = rf;

                    RetrieveRequest rr = new RetrieveRequest();

                    rr.ObjectType = "DataFolder";
                    rr.Properties = new string[] { "ID", "Name", "ParentFolder.ID", "ParentFolder.Name" };
                    rr.Filter = cfp;

                    status = client.Retrieve(rr, out requestID, out results);

                    if (results.Count() > 0)
                    {
                        foreach (DataFolder df in results)
                        {
                            RetrieveObjectsByFolderID(df.ID.ToString(), etClient, path + "/" + df.Name + "/", contentType);
                            RetrieveFolderStructure(df.ID.ToString(), etClient, contentType, path + "/" + df.Name + "/");
                        }
                    }
                }
        }
Exemplo n.º 2
0
        public IList <TrackingEvent> RetrieveTrackingEventData(Type eventType, DateTime sinceWhen, String eventTypeString, ClientID clientId = null, string TriggeredSendDefinitionObjectID = "")
        {
            //String filterField = "CreatedDate";
            String filterField = "EventDate";
            var    properties  = GetRetrivableProperties(eventTypeString).ToArray();


            SimpleFilterPart filter = new SimpleFilterPart();

            //Use this only if you are retrieving for TriggeredSend
            filter.Property = "TriggeredSendDefinitionObjectID";
            String[] vlaues = { TriggeredSendDefinitionObjectID };


            //filter.Property = "SendID";
            //String[] vlaues = { "28980" };
            filter.Value = vlaues;

            var dateFilter = new SimpleFilterPart
            {
                Property       = filterField,
                SimpleOperator = SimpleOperators.greaterThanOrEqual,
                DateValue      = new DateTime[] {
                    sinceWhen
                }
            };

            ComplexFilterPart cfilter = new ComplexFilterPart();

            cfilter.LeftOperand     = filter;
            cfilter.LogicalOperator = LogicalOperators.AND;
            cfilter.RightOperand    = dateFilter;


            RetrieveRequest retrieveRequest = new RetrieveRequest
            {
                ObjectType = eventType.Name,
                Properties = properties,
                Filter     = cfilter,
                ClientIDs  = new ClientID[] { clientId }
            };

            APIObject[] results = null;
            String      requestId = null, message;

            SoapClient client = _client;

            String status = "";
            IList <TrackingEvent> returnList = new List <TrackingEvent>();

            do
            {
                status = client.Retrieve(retrieveRequest, out requestId, out results);

                if (!client.GetResult(status, results, out message))
                {
                    //WriteToLog(PIMCO.SMS.Logging.Category.Exception, message);
                    //throw new ExactTargetException(message);
                }

                for (int i = 0; i < results.Length; i++)
                {
                    returnList.Add((TrackingEvent)results[i]);
                }

                //This calls the API again to get the next 2500 records
                retrieveRequest = new RetrieveRequest();
                retrieveRequest.ContinueRequest = requestId;
            } while (status.Equals("MoreDataAvailable"));

            return(returnList.ToList());
        }
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                // Local Variables.
                APIObject[] results = null;
                String requestId = null;
                String SOAPEndPoint = context.Session["SOAPEndPoint"].ToString();
                String internalOauthToken = context.Session["internalOauthToken"].ToString();
                String search = context.Request.QueryString["search"].ToString().Trim();

                // Create the SOAP binding for call.
                BasicHttpBinding binding = new BasicHttpBinding();
                binding.Name = "UserNameSoapBinding";
                binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
                binding.MaxReceivedMessageSize = 2147483647;
                var client = new SoapClient(binding, new EndpointAddress(new Uri(SOAPEndPoint)));
                client.ClientCredentials.UserName.UserName = "******";
                client.ClientCredentials.UserName.Password = "******";

                using (var scope = new OperationContextScope(client.InnerChannel))
                {
                    // Add oAuth token to SOAP header.
                    XNamespace ns = "http://exacttarget.com";
                    var oauthElement = new XElement(ns + "oAuthToken", internalOauthToken);
                    var xmlHeader = MessageHeader.CreateHeader("oAuth", "http://exacttarget.com", oauthElement);
                    OperationContext.Current.OutgoingMessageHeaders.Add(xmlHeader);

                    // Setup RetrieveRequest for Subscriber object.
                    RetrieveRequest retrieveRequest = new RetrieveRequest();
                    retrieveRequest.ObjectType = "Subscriber";
                    String[] props = { "ID", "EmailAddress", "SubscriberKey", "Status" };
                    retrieveRequest.Properties = props;

                    // Query filter using Simplefilter.
                    SimpleFilterPart sfp = new SimpleFilterPart();
                    sfp.Property = "SubscriberKey";
                    sfp.SimpleOperator = SimpleOperators.like;
                    sfp.Value = new String[] { search.Trim() };

                    // Query filter using Simplefilter.
                    SimpleFilterPart sfp2 = new SimpleFilterPart();
                    sfp2.Property = "EmailAddress";
                    sfp2.SimpleOperator = SimpleOperators.like;
                    sfp2.Value = new String[] { search.Trim() };

                    // Complexfilter to OR the two SimpleFilters.
                    ComplexFilterPart cfp = new ComplexFilterPart();
                    cfp.LeftOperand = sfp;
                    cfp.RightOperand = sfp2;
                    cfp.LogicalOperator = LogicalOperators.OR;

                    // Use the ComplexFilter in RetrieveRequest.
                    retrieveRequest.Filter = cfp;

                    // Retrieve the subscribers.
                    String response = client.Retrieve(retrieveRequest, out requestId, out results);

                    // If results returned, loop through them a convert to JSON.
                    if (response != null && response.ToLower().Equals("ok"))
                    {
                        String strResults = string.Empty;
                        strResults += @"{""subscribers"": [";

                        if (results != null && results.Length > 0)
                        {
                            int i = 1;
                            foreach (Subscriber sub in results)
                            {
                                // Converting desired properties into JSON.
                                strResults += @"{""ID"":" + JsonConvert.SerializeObject(sub.ID).ToString().Trim() + ", ";
                                strResults += @"""EmailAddress"":" + JsonConvert.SerializeObject(sub.EmailAddress).ToString().Trim() + ", ";
                                strResults += @"""SubscriberKey"":" + JsonConvert.SerializeObject(sub.SubscriberKey).ToString().Trim() + ", ";
                                strResults += @"""Status"":" + JsonConvert.SerializeObject(sub.Status.ToString()).ToString().Trim() + " }";
                                if (i < results.Length)
                                    strResults += ", ";
                                i++;
                            }
                            strResults += " ]}";
                            // Return the resulting JSON from handler.
                            context.Response.Write(strResults);
                        }
                        else
                            context.Response.Write(@"{""subscribers"": []}");
                    }
                    else
                    {
                        context.Response.Write(@"{""subscribers"": []}");
                    }
                }
            }
            catch (Exception ex)
            {
                context.Response.Write(ex);
            }
        }
Exemplo n.º 4
0
        public void BounceEventDetails(DateTime fromDate, DateTime toDate, string TriggeredSendDefinitionObjectID)
        {
            List <string>   BounceSubscribers;
            RetrieveRequest retrieveRequest = new RetrieveRequest();

            retrieveRequest.ObjectType = "BounceEvent";

            String[] props =
            {
                "SubscriberKey", "BounceType", "SMTPCode", "SMTPReason", "BounceCategory", "EventDate", "EventType"
            };

            retrieveRequest.Properties = props;

            SimpleFilterPart filter = new SimpleFilterPart();

            //Use this only if you are retrieving for TriggeredSend

            filter.Property = "TriggeredSendDefinitionObjectID";
            String[] vlaues = { TriggeredSendDefinitionObjectID };

            //filter.Property = "SendID";
            //String[] vlaues = { "28980" };
            filter.Value = vlaues;

            SimpleFilterPart dateFilter = new SimpleFilterPart();

            dateFilter.Property       = "EventDate";
            dateFilter.SimpleOperator = SimpleOperators.between;
            dateFilter.DateValue      = new DateTime[2];
            dateFilter.DateValue[0]   = fromDate.Date; //BeingDate;
            dateFilter.DateValue[1]   = toDate.Date;   //EndDate;


            ComplexFilterPart cfilter = new ComplexFilterPart();

            cfilter.LeftOperand     = filter;
            cfilter.LogicalOperator = LogicalOperators.AND;
            cfilter.RightOperand    = dateFilter;


            retrieveRequest.Filter = cfilter;

            /**
             * Use this only if you are retrieving data from sub-account
             */

            retrieveRequest.ClientIDs = new ClientID[] { new ClientID()
                                                         {
                                                             ID = config.ClientId.Value, IDSpecified = true
                                                         } };

            APIObject[] results     = null;
            String      requestId   = null;
            String      response    = _Client.Retrieve(retrieveRequest, out requestId, out results);
            BounceEvent bounceEvent = null;

            if (response != null && response.ToLower().Equals("ok"))
            {
                if (results != null && results.Count() > 0)
                {
                    BounceSubscribers = results.Cast <BounceEvent>().Select(a => a.SubscriberKey).ToList();
                    Console.WriteLine("*******************************************************");
                    Console.WriteLine("*******************************************************");
                    Console.WriteLine("************* List of Bounce Subscribers **************");
                    Console.WriteLine("*******************************************************");
                    Console.WriteLine("*******************************************************");
                    foreach (var sub in BounceSubscribers)
                    {
                        Console.WriteLine(string.Format("Subscriber Key: {0}", sub));
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                // Local Variables.
                APIObject[] results            = null;
                String      requestId          = null;
                String      SOAPEndPoint       = context.Session["SOAPEndPoint"].ToString();
                String      internalOauthToken = context.Session["internalOauthToken"].ToString();
                String      search             = context.Request.QueryString["search"].ToString().Trim();

                // Create the SOAP binding for call.
                BasicHttpBinding binding = new BasicHttpBinding();
                binding.Name                   = "UserNameSoapBinding";
                binding.Security.Mode          = BasicHttpSecurityMode.TransportWithMessageCredential;
                binding.MaxReceivedMessageSize = 2147483647;
                var client = new SoapClient(binding, new EndpointAddress(new Uri(SOAPEndPoint)));
                client.ClientCredentials.UserName.UserName = "******";
                client.ClientCredentials.UserName.Password = "******";

                using (var scope = new OperationContextScope(client.InnerChannel))
                {
                    // Add oAuth token to SOAP header.
                    XNamespace ns           = "http://exacttarget.com";
                    var        oauthElement = new XElement(ns + "oAuthToken", internalOauthToken);
                    var        xmlHeader    = MessageHeader.CreateHeader("oAuth", "http://exacttarget.com", oauthElement);
                    OperationContext.Current.OutgoingMessageHeaders.Add(xmlHeader);

                    // Setup RetrieveRequest for Subscriber object.
                    RetrieveRequest retrieveRequest = new RetrieveRequest();
                    retrieveRequest.ObjectType = "Subscriber";
                    String[] props = { "ID", "EmailAddress", "SubscriberKey", "Status" };
                    retrieveRequest.Properties = props;

                    // Query filter using Simplefilter.
                    SimpleFilterPart sfp = new SimpleFilterPart();
                    sfp.Property       = "SubscriberKey";
                    sfp.SimpleOperator = SimpleOperators.like;
                    sfp.Value          = new String[] { search.Trim() };

                    // Query filter using Simplefilter.
                    SimpleFilterPart sfp2 = new SimpleFilterPart();
                    sfp2.Property       = "EmailAddress";
                    sfp2.SimpleOperator = SimpleOperators.like;
                    sfp2.Value          = new String[] { search.Trim() };

                    // Complexfilter to OR the two SimpleFilters.
                    ComplexFilterPart cfp = new ComplexFilterPart();
                    cfp.LeftOperand     = sfp;
                    cfp.RightOperand    = sfp2;
                    cfp.LogicalOperator = LogicalOperators.OR;

                    // Use the ComplexFilter in RetrieveRequest.
                    retrieveRequest.Filter = cfp;

                    // Retrieve the subscribers.
                    String response = client.Retrieve(retrieveRequest, out requestId, out results);

                    // If results returned, loop through them a convert to JSON.
                    if (response != null && response.ToLower().Equals("ok"))
                    {
                        String strResults = string.Empty;
                        strResults += @"{""subscribers"": [";

                        if (results != null && results.Length > 0)
                        {
                            int i = 1;
                            foreach (Subscriber sub in results)
                            {
                                // Converting desired properties into JSON.
                                strResults += @"{""ID"":" + JsonConvert.SerializeObject(sub.ID).ToString().Trim() + ", ";
                                strResults += @"""EmailAddress"":" + JsonConvert.SerializeObject(sub.EmailAddress).ToString().Trim() + ", ";
                                strResults += @"""SubscriberKey"":" + JsonConvert.SerializeObject(sub.SubscriberKey).ToString().Trim() + ", ";
                                strResults += @"""Status"":" + JsonConvert.SerializeObject(sub.Status.ToString()).ToString().Trim() + " }";
                                if (i < results.Length)
                                {
                                    strResults += ", ";
                                }
                                i++;
                            }
                            strResults += " ]}";
                            // Return the resulting JSON from handler.
                            context.Response.Write(strResults);
                        }
                        else
                        {
                            context.Response.Write(@"{""subscribers"": []}");
                        }
                    }
                    else
                    {
                        context.Response.Write(@"{""subscribers"": []}");
                    }
                }
            }
            catch (Exception ex)
            {
                context.Response.Write(ex);
            }
        }