Showing posts with label Shopify Api. Show all posts
Showing posts with label Shopify Api. Show all posts

Friday, 30 January 2015

Shopify API Integration from .NET

To Integrate Shopify first You need Key and Password

So to generate an API key and password, go to http://store.myshopify.com/admin/apps, and click "Create a private API key" at the bottom.It will generate password and key for you.



Then copy and paste this code ....

  public string GetCustomers()
        {
            const string url = "https://store.myshopify.com/admin/customers.json";

            var req = (HttpWebRequest)WebRequest.Create(url);
            req.Method = "GET";
            req.ContentType = "application/json";
            req.Credentials = GetCredential(url);
            req.PreAuthenticate = true;

            using (var resp = (HttpWebResponse)req.GetResponse())
            {
                if (resp.StatusCode != HttpStatusCode.OK)
                {
                    string message = String.Format("Call failed. Received HTTP {0}", resp.StatusCode);
                    throw new ApplicationException(message);
                }

                var sr = new StreamReader(resp.GetResponseStream());
                return sr.ReadToEnd();
            }
        }

        private static CredentialCache GetCredential(string url)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
            var credentialCache = new CredentialCache();
            credentialCache.Add(new Uri(url), "Basic", new NetworkCredential("api-key", "password"));
            return credentialCache;
        }




Done;)