Example #1
0
        public ActionResult auth(string shop, string code)
        {
            string u = string.Format("https://{0}/admin/oauth/access_token", shop);

            var client = new RestClient(u);

            var request = new RestRequest(Method.POST);

            request.RequestFormat = DataFormat.Json;
            request.AddHeader("Content-Type", "application/json");

            request.AddParameter("application/x-www-form-urlencoded", "client_id=" + apiKey + "&client_secret=" + secretKey + "&code=" + code, ParameterType.RequestBody);

            var response = client.Execute(request);

            var r           = JsonConvert.DeserializeObject <dynamic>(response.Content);
            var accessToken = r.access_token;

            //Part 5
            //create a un-install web hook
            //you want to know when customers delete your app from their shop

            string unInstallUrlCallback = "https://549653d4.ngrok.io/fulfillment/uninstall";

            string shopAdmin = string.Format("https://{0}/admin/", shop);

            var webHook = new WebHookBucket();

            webHook.Whook = new WebHook {
                Format = "json", Topic = "app/uninstalled", Address = unInstallUrlCallback
            };

            CreateUninstallHook(shopAdmin, "webhooks.json", Method.POST, (string)accessToken, webHook);
            return(View());
        }
Example #2
0
        public string CreateUninstallHook(string baseUrl, string endPoint, RestSharp.Method method, string token, WebHookBucket webhook)
        {
            var client = new RestClient(baseUrl);

            var request = new RestRequest(endPoint, method);

            request.RequestFormat = DataFormat.Json;

            request.AddHeader("X-Shopify-Access-Token", token);

            string json = JsonConvert.SerializeObject(webhook, Formatting.Indented);

            request.AddParameter("application/json", json, ParameterType.RequestBody);

            // execute the request
            var r = client.Execute(request);

            return(r.Content);
        }