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;)

5 comments:

  1. If you're an entrepreneur who would like to begin an internet business, Shopify is a terrific option. Click here for more interesting information on Contact - Niche Tyrant.

    ReplyDelete
  2. Thanks! this helped start me off

    ReplyDelete
  3. Boost your marketing by google pay integration on your website. if you are looking for a partner to help api integration to your website with your salesforce api integration, or to help you to migrate to Salesforce? We have integrated many websites with custom api integration, third party integration and shopify api integration, visit our website for more information.

    ReplyDelete
  4. Beeindruckende und kraftvolle Vorschläge des Autors dieses Blogs sind für mich sehr hilfreich.
    Shopify Experten

    ReplyDelete