protected void Button2_Click(object sender, EventArgs e) { ShopifyAuthorizationState authState = new ShopifyAuthorizationState(); authState.AccessToken = accessToken; authState.ShopName = shopName; ShopifyAPIClient api = new ShopifyAPIClient(authState); // by default JSON string is returned dynamic data = new JavaScriptSerializer().DeserializeObject(api.Get("/admin/orders.json").ToString()); //dynamic orders = new JavaScriptSerializer().DeserializeObject(data); }
public object DeleteEntity(string entity, string token, string shopName, string id) { var authState = new ShopifyAuthorizationState { AccessToken = token, ShopName = shopName }; var api = new ShopifyAPIClient(authState, new JsonDataTranslator()); var res = api.Delete($"/admin/{entity}/{id}.json"); return res; }
public object CreateEntity(string entity, string token, string shopName, object body) { var authState = new ShopifyAuthorizationState { AccessToken = token, ShopName = shopName }; var api = new ShopifyAPIClient(authState, new JsonDataTranslator()); var res = api.Post($"/admin/{entity}.json", body); return res; }
public void FulfillOrder(int UserKey, UserAccount userAccount, string orderID, string trackingNumber, string itemID) { ShopifyAuthorizationState authState = new ShopifyAuthorizationState(); authState.AccessToken = userAccount.Config_Value1; authState.ShopName = userAccount.Application_Name; ShopifyAPIClient api = new ShopifyAPIClient(authState, new JsonDataTranslator()); string inputData = @"{""fulfillment"": {""tracking_number"": """ + trackingNumber + @""",""line_items"": [{id: """ + itemID + @"""}]}}"; dynamic _inputData = new JavaScriptSerializer().DeserializeObject(inputData); // by default JSON string is returned dynamic data = new JavaScriptSerializer().DeserializeObject(api.Post("/admin/orders/" + orderID + "/fulfillments.json", _inputData).ToString()); }
public dynamic GetEntities(string entity, string token, string shopName, string[] fields, int top, string collectionId) { var authState = new ShopifyAuthorizationState { AccessToken = token, ShopName = shopName }; var api = new ShopifyAPIClient(authState, new JsonDataTranslator()); var fieldQuery = ""; var summary = new JArray(); if (fields.Length != 0) { var commaSeparatedFields = string.Join(",", fields); fieldQuery = "fields=" + commaSeparatedFields + "&"; } if (collectionId != null) { fieldQuery = fieldQuery + "collection_id=" + collectionId + "&"; } if (top == 0 || top > 250) { dynamic count = api.Get($"/admin/{entity}/count.json"); var json = count; double realCount = int.Parse(json.GetValue("count").ToString()); realCount = realCount / 250; var loops = (int)Math.Ceiling(realCount); if (entity == "webhooks") loops = 1; for (var i = 1; i <= loops; i++) { CollectEntities(api, summary, entity, 250, i, fieldQuery); } } else { CollectEntities(api, summary, entity, top, 1, fieldQuery); } return summary; }
public JArray GetCustomerSavedSearches(string token, string shopName) { var summary = new JArray(); var authState = new ShopifyAuthorizationState(); authState.AccessToken = token; authState.ShopName = shopName; var api = new ShopifyAPIClient(authState, new JsonDataTranslator()); var filterObject = (JObject)api.Get("/admin/customer_saved_searches.json"); var filtersObject = filterObject.GetValue("customer_saved_searches"); foreach (JObject filter in filtersObject) { summary.Add(filter); } return summary; }
public JArray GetEntities(string entity, string token, string shopName, int top, string[] fields) { var authState = new ShopifyAuthorizationState(); authState.AccessToken = token; authState.ShopName = shopName; var api = new ShopifyAPIClient(authState, new JsonDataTranslator()); dynamic data; var fieldQuery = ""; var summary = new JArray(); if (fields.Length != 0) { var commaSeparatedFields = string.Join(",", fields); fieldQuery = "fields=" + commaSeparatedFields + "&"; } if (top == 0 || top > 250) { dynamic count = api.Get(string.Format("/admin/{0}/count.json", entity)); var json = count; data = count; double realCount = int.Parse(json.GetValue("count").ToString()); realCount = realCount / 250; var loops = (int)Math.Ceiling(realCount); for (int i = 1; i <= loops; i++) { collectEntities(api, summary, entity, 250, i, fieldQuery); } } else { collectEntities(api, summary, entity, top, 1, fieldQuery); } return summary; }
public JArray GetCustomerSavedSearch(string token, string shopName, int id, string[] fields) { var customers = new JArray(); var authState = new ShopifyAuthorizationState(); authState.AccessToken = token; authState.ShopName = shopName; var api = new ShopifyAPIClient(authState, new JsonDataTranslator()); string fieldQuery = ""; if (fields.Length != 0) { var commaSeparatedFields = string.Join(",", fields); fieldQuery = "?fields=" + commaSeparatedFields; } var filterObject = (JObject)api.Get(string.Format("/admin/customer_saved_searches/{0}/customers.json{1}", id, fieldQuery)); var customersObject = filterObject.GetValue("customers"); foreach (JObject customer in customersObject) { customers.Add(customer); } return customers; }
public dynamic GetEntity(string entity, string id, string token, string shopName, string[] fields, int top) { var authState = new ShopifyAuthorizationState { AccessToken = token, ShopName = shopName }; var api = new ShopifyAPIClient(authState, new JsonDataTranslator()); var queryString = ""; dynamic entityObject; if (fields.Length != 0) { var commaSeparatedFields = string.Join(",", fields); queryString = "fields=" + commaSeparatedFields + "&"; } if (entity.Equals("collections")) { entity = "products"; entityObject = GetEntities(entity, token, shopName, fields, top, id); return entityObject; }if (entity.Equals("customer_saved_searches")) { id = id + "/customers"; if (top != 0) { queryString = queryString + "limit=" + top; } } var urlSuffix = $"/admin/{entity}/{id}.json?{queryString}"; entityObject = (JObject)api.Get(urlSuffix); return entityObject; }
/// <summary> /// Creates an instance of this class for use with making API Calls /// </summary> /// <param name="state">the authorization state required to make the API Calls</param> public ShopifyAPIClient(ShopifyAuthorizationState state) { this.State = state; }
/// <summary> /// Creates an instance of this class for use with making API Calls /// </summary> /// <param name="state">the authorization state required to make the API Calls</param> /// <param name="translator">the translator used to transform the data between your C# client code and the Shopify API</param> public ShopifyAPIClient(ShopifyAuthorizationState state, IDataTranslator translator) { this.State = state; this.Translator = translator; }
// // GET: /Shopify/Test public ActionResult Test() { var appID = Request.Params["id"]; using (ShopifyAppsContext context = new ShopifyAppsContext()) { var app = context.ShopifyApps.Find(new Guid(appID)); ViewData["App"] = app; ShopifyAuthorizationState authState = new ShopifyAuthorizationState { ShopName = app.ShopName, AccessToken = app.AccessToken }; var api = new ShopifyAPIClient(authState, new JsonDataTranslator()); // The JSON Data Translator will automatically decode the JSON for you ViewData["ProductData"] = api.Get("/admin/products.json"); } return View(); }
public List<ParcelItem> GetPendingOrders(int userCode, int userAccountCode) { DataModelEntities context = new DataModelEntities(); UserAccount userAccount = context.UserAccounts.First(u => u.User_Account_Code == userAccountCode); List<ChargeCode> chargeCodes = context.ChargeCodes.Where(u => u.Is_Active == true && u.User_Code == userCode).ToList(); ShopifyAuthorizationState authState = new ShopifyAuthorizationState(); authState.AccessToken = userAccount.Config_Value1; authState.ShopName = userAccount.Application_Name; ShopifyAPIClient api = new ShopifyAPIClient(authState); try { // by default JSON string is returned dynamic data = new JavaScriptSerializer().DeserializeObject(api.Get("/admin/orders.json?fulfillment_status=unshipped").ToString()); List<PriceManagerDAL.ParcelItem> parcelItems = context.ParcelItems.Where(f => f.User_Code == userCode && f.UserAccount.Account_Code == (int)Constant.Accounts.Shopify && f.Is_Active == true).ToList(); // delete all database entries foreach (PriceManagerDAL.ParcelItem existingItem in parcelItems) { context.ParcelItems.DeleteObject(existingItem); } context.SaveChanges(); List<ParcelItem> items = new List<ParcelItem>(); foreach (dynamic order in data["orders"]) { foreach (dynamic lineItem in order["line_items"]) { ParcelItem item = new ParcelItem(); item.Type = "SHOPIFY"; item.AccountID = userAccount.User_Account_Code.ToString(); item.RecordNumber = order["order_number"].ToString(); item.ItemID = lineItem["id"].ToString(); item.TransactionID = order["id"].ToString(); item.ItemName = lineItem["title"]; item.CustomLabel = lineItem["sku"].ToString(); item.CustomLabelText = lineItem["sku"].ToString(); string state = order["shipping_address"]["province"]; string stateCode = order["shipping_address"]["province_code"]; if (StateHelper.States.Where(s => s.Key == stateCode).Count() > 0) item.State = StateHelper.States[stateCode]; else item.State = state; item.BuyerName = order["customer"]["first_name"] + " " + order["customer"]["last_name"]; item.EmailAddress = order["email"]; item.BuyerID = order["customer"]["id"].ToString(); item.Street2 = order["shipping_address"]["address1"]; item.Street3 = order["shipping_address"]["address2"]; item.City = order["shipping_address"]["city"]; item.PostalCode = order["shipping_address"]["zip"].TrimStart('0'); item.Country = order["shipping_address"]["country_code"]; item.Phone = order["shipping_address"]["phone"]; item.Quantity = lineItem["quantity"]; if (order["shipping_lines"] != null) item.ShippingCost = double.Parse(order["shipping_lines"][0]["price"]); item.SaleRecordId = order["order_number"].ToString(); // insurance details // item.Currency = order["currency"]; item.Price = double.Parse(lineItem["price"]); item.Messages = GetMessageText(order["note"],order["created_at"]); item.ShippingMethod = order["shipping_lines"][0]["title"]; string shippingCode = order["shipping_lines"][0]["code"]; ChargeCode code = chargeCodes.FirstOrDefault(u => shippingCode.ToLower().Contains(u.Ebay_Code.ToLower()) == true); if (code != null && code.Charge_Code_Name.ToLower() == "ignore") { continue; // ignore the item } bool IspostCodeOK = Common.VerifyPostCode(order["shipping_address"]["zip"], order["shipping_address"]["city"]); if (IspostCodeOK) item.PostCodeImageURL = Constant.tickURL; else item.PostCodeImageURL = Constant.crossURL; items.Add(item); } } return items; } catch (Exception ex) { return null; } }
/// <summary> /// /// </summary> /// <param name="sessionState"></param> /// <param name="state"></param> public static void SetAuthorization(System.Web.HttpContextBase httpContext, ShopifyAuthorizationState state) { httpContext.Session[AuthSessionKey] = state; }
public ProductDataSource() { // TODO: Of course it's a bad idea to hardcode this. In fact having this in your app is a bad idea period. This really should be exposed via // your own custom REST API that then connected to Shopify's. // This is just an example to show that it can be done, not how it *should* be done. ShopifyAuthorizationState authState = new ShopifyAuthorizationState { ShopName = "buckridge-hyatt6895", AccessToken = "42d4917ed3507278c748046addb01f3d" }; var api = new ShopifyAPIClient(authState, new JsonDataTranslator()); // The JSON Data Translator will automatically decode the JSON for you var result = api.Get("/admin/products.json"); result.Completed = delegate(IAsyncOperation<dynamic> asyncAction, AsyncStatus asyncStatus) { var data = asyncAction.GetResults(); var products = data.products; foreach (var product in products) { var group = new ProductDataGroup(product.id.ToString(), product.title.ToString(), product.vendor.ToString(), product.images.Count > 0 ? product.images[0].src.ToString() : "", product.body_html.ToString()); var imgCount = 0; foreach (var variant in product.variants) { group.Items.Add(new ProductDataItem(variant.id.ToString(), variant.option1.ToString(), variant.option2.ToString(), imgCount < product.images.Count ? product.images[imgCount++].src.ToString() : "", "", group.Description, group)); } this.AllGroups.Add(group); } }; }