Monday, 30 October 2017

Sitecore Experience Accelerator :: Restrict the Search Result only for Given Template :: Search Result Component

In case you are in love in SXA and using the Search result component in order to display the result.

Here are quick notes before you start.

Fist and foremost you need to Enable the Lucene or  Solr Search configuration so we can go ahead and index the data.

By Default, all the template which inherits from _searchable is getting displayed in  the

search result.




However, we had a requirement to limit for only given template type so only those search result is displayed.


Cool, this can be achieved using SXA in build scope setting as shown below.


Happy Sitecore SXA.

Wednesday, 25 October 2017

How to call the Subscribe Mail Chimp API from C#


I wanted to do MailChimp subscription. I wanted to do using C# so I did a quick google and get Reference of below Code.

Here are the Steps:

Create one Mail Chimp Account and get the API Key 





Get the list ID as shown below;



using System;
using System.IO;
using System.Net;
using Newtonsoft.Json;
using System.Diagnostics;

namespace MailChimpConfiguration
{
    class Program
    {
        static void Main(string[] args)
        {
            var apiKey = "-us17"; // your API key here
            var listId = ""; // your list ID here
            var subscribeRequest = new
            {
                apikey = apiKey,
                id = listId,
                email = new
                {
                    email = "pradsir@gmail.com"
                },
                double_optin = true,
            };
            var requestJson = JsonConvert.SerializeObject(subscribeRequest);



            var responseString = CallMailChimpApi("lists/subscribe.json", requestJson);
            dynamic responseObject = JsonConvert.DeserializeObject(responseString);
            if ((responseObject.email != null) && (responseObject.euid != null))
            {
                // successful!
            }
            else
            {
                string name = responseObject.name;
                if (name == "List_AlreadySubscribed")
                {
                    Trace.TraceInformation("Mailchimp already subscribed");
                }
                else
                {
                    Trace.TraceError("Mailchimp subscribe error {0}", responseObject.error);
                }
            }

        }


        private static string CallMailChimpApi(string method, string requestJson)
        {
            var endpoint = String.Format("https://{0}.api.mailchimp.com/2.0/{1}", "us17", method);
            var wc = new WebClient();
            try
            {
                return wc.UploadString(endpoint, requestJson);
            }
            catch (WebException we)
            {
                using (var sr = new StreamReader(we.Response.GetResponseStream()))
                {
                    return sr.ReadToEnd();
                }
            }
        }
    }
}

Credit :http://markheath.net/post/how-to-call-the-mailchimp-api-from-c 

Featured post

Getting Started With SOLR

Getting Started with Solr ·           Features o    Hit highlighting o    Auto correction o    Faceted Search o    Multi lan...