/// <summary> /// Gets a list of the metafields for a specified resource. Leave both resourceType and resourceId null for shop metafields. /// </summary> /// <param name="resourceType">The type of shopify resource to obtain metafields for. This could be variants, products, orders, customers, custom_collections.</param> /// <param name="resourceId">The Id for the resource type.</param> /// <param name="options">The <see cref="ShopifyMetaFieldFilter"/> used to filter results</param> /// <returns></returns> public async Task <IEnumerable <ShopifyMetaField> > ListAsync(long?resourceId, string resourceType = null, ShopifyMetaFieldFilter options = null) { string reqPath = "metafields.json"; if (resourceType != null && resourceId != null) { reqPath = $"{resourceType}/{resourceId}/metafields.json"; } IRestRequest req = RequestEngine.CreateRequest(reqPath, Method.GET, "metafields"); //Add optional parameters to request if (options != null) { req.Parameters.AddRange(options.ToParameters(ParameterType.GetOrPost)); } return(await RequestEngine.ExecuteRequestAsync <List <ShopifyMetaField> >(_RestClient, req)); }
/// <summary> /// Gets a count of the metafields for the given entity type and filter options. Leave both resourceType and resourceId null for shop metafields. /// </summary> /// <param name="resourceType">The type of shopify resource to obtain metafields for. This could be variants, products, orders, customers, custom_collections.</param> /// <param name="resourceId">The Id for the resource type.</param> /// <param name="filter">The <see cref="ShopifyMetaFieldFilter"/> used to filter results</param> /// <returns>The count of all metafields for the given entity and filter options.</returns> public async Task <int> CountAsync(long?resourceId, string resourceType = null, ShopifyMetaFieldFilter filter = null) { string reqPath = "metafields/count.json"; if (resourceType != null && resourceId != null) { reqPath = $"{resourceType}/{resourceId}/metafields/count.json"; } IRestRequest req = RequestEngine.CreateRequest(reqPath, Method.GET); //Add optional parameters to request if (filter != null) { req.Parameters.AddRange(filter.ToParameters(ParameterType.GetOrPost)); } JToken responseObject = await RequestEngine.ExecuteRequestAsync(_RestClient, req); //Response looks like { "count" : 123 }. Does not warrant its own class. return(responseObject.Value <int>("count")); }