MyKubo API
Base URI
This header is required to all methods except the Login. This token in obtained by calling the Login Method
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Web; using System.IO; using System.Runtime.Serialization.Json; using System.Web.Script.Serialization;
namespace Mykubo.API.Test { class Program { static void Main(string[] args) { //Login into API Login response = Deserialize<Login>(Auth("email1@gmail.com", “test”)); string token = response.token;
//Get Brands allowed by the login BrandsObj brands = Deserialize<BrandsObj>(ListBrands(token));
//Get all products for the first returned brand ProductsObj products = Deserialize<ProductsObj>(GetProducts(token,brands.brands.First().brand_id));
}
static string Auth(string email, string pass) { return HttpPost(“http://api.mykubo.dev/v0.1/login”, new string[] { “email”, “password” }, new string[] {email,pass}, null); }
static string ListBrands(string token) { return HttpGet(“http://api.mykubo.dev/v0.1/brands”, token); }
static string GetProducts(string token, string brandId) { return HttpGet(“http://api.mykubo.dev/v0.1/brands/”+brandId +"/products/", token); }
static string HttpPost(string url, string[] paramName, string[] paramVal, string token) { HttpWebRequest req = WebRequest.Create(new Uri(url)) as HttpWebRequest;
req.Method = “POST”; req.ContentType = “application/x-www-form-urlencoded”;
//The authentication token has to be sent in the HTTP HEADER of the request if (!String.IsNullOrEmpty(token)) { req.Headers.Add(“token”, “”); }
// Build a string with all the params, properly encoded. // We assume that the arrays paramName and paramVal are // of equal length: StringBuilder paramz = new StringBuilder(); for (int i = 0; i < paramName.Length; i++) { paramz.Append(paramName[i]); paramz.Append("="); paramz.Append(HttpUtility.UrlEncode(paramVal[i])); paramz.Append("&"); }
// Encode the parameters as form data: byte[] formData = UTF8Encoding.UTF8.GetBytes(paramz.ToString()); req.ContentLength = formData.Length;
// Send the request: using (Stream post = req.GetRequestStream()) { post.Write(formData, 0, formData.Length); }
// Pick up the response: string result = null; using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse) { StreamReader reader = new StreamReader(resp.GetResponseStream()); result = reader.ReadToEnd(); }
return result; }
static string HttpGet(string url, string token) { HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest;
//The authentication token has to be sent in the HTTP HEADER of the request if (!String.IsNullOrEmpty(token)) { req.Headers.Add(“token”, token); } string result = null; using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse) { StreamReader reader = new StreamReader(resp.GetResponseStream()); result = reader.ReadToEnd(); } return result; }
public static string Serialize<T>(T obj) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType()); MemoryStream ms = new MemoryStream(); serializer.WriteObject(ms, obj); string retVal = Encoding.UTF8.GetString(ms.ToArray()); return retVal; }
public static T Deserialize<T>(string json) { T obj = Activator.CreateInstance<T>(); MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(json)); DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType()); obj = (T)serializer.ReadObject(ms); ms.Close(); return obj; } }
public class Login { public bool OK { get; set; } public string token { get; set; } }
public class BrandsObj { public bool OK { get; set; }
public List<Brands> brands { get; set; } }
public class Brands { public string brand_id { get; set; }
public string name { get; set; } }
public class ProductsObj { public bool OK { get; set; }
public List<Product> products { get; set; } }
public class Category { public string category_id { get; set; }
public string name { get; set; } }
public class Product { public string product_id { get; set; }
public string reference { get; set; }
public string name { get; set; }
public Category category { get; set; }
public decimal price { get; set; }
public List<string> tags { get; set; } }
}
Request headers
Request body
Returns all the possible product categories and with the associated category_id
Request headers
Returns the meaning of all possible order status codes
Request headers
Get all acessible brands
Request headers
{brand_id}/products/{brand_id}/products/{product_id}/color{product_id}/color/{color_ref}/size{product_id}/color/{color_ref}/image{product_id}{product_id}/color/{color_ref}{product_id}/color/{color_ref}/image/{image_id}{product_id}/contents/{content_id}/{product_id}/name{product_id}/price{product_id}/category{product_id}/description{product_id}/tags{product_id}/reference{product_id}/content/{content_id}/stock{product_id}/color/{color_ref}/color_hex{product_id}/color/{color_ref}/color_ref{product_id}/color/{color_ref}/set_default{product_id}/color/{color}/image/{image_id}/set_default{brand_id}/products/Lists all products from a brand
Path variables
Request headers
Responses
Body
F0F0F0
red
Request headers
Request body
images : array of files submitted as multipart/form-data
{brand_id}/products/Add new product to the brand
Path variables
Request headers
Request body
{product_id}/colorPath variables
Request headers
Request body
{product_id}/color/{color_ref}/sizePath variables
Request headers
Request body
{product_id}/color/{color_ref}/imagePath variables
Request headers
Request body
{product_id}Path variables
Request headers
{product_id}/color/{color_ref}Path variables
Request headers
{product_id}/color/{color_ref}/image/{image_id}Path variables
Request headers
{product_id}/contents/{content_id}/Path variables
Request headers
{product_id}/namePath variables
Request headers
Request body
Examples
""{product_id}/pricePath variables
Request headers
Request body
{product_id}/categoryPath variables
Request headers
Request body
{product_id}/descriptionPath variables
Request headers
Request body
{product_id}/tagsPath variables
Request headers
Request body
{product_id}/referencePath variables
Request headers
Request body
{product_id}/content/{content_id}/stockPath variables
Request headers
Request body
{product_id}/color/{color_ref}/color_hexPath variables
Request headers
Request body
{product_id}/color/{color_ref}/color_refPath variables
Request headers
Request body
{product_id}/color/{color_ref}/set_defaultPath variables
Request headers
Request body
{product_id}/color/{color}/image/{image_id}/set_defaultPath variables
Request headers
Request body
{brand_id}/orders{order_id}/confirm{order_id}/reject{order_id}/sent{order_id}/finish{brand_id}/ordersPath variables
Request headers
Responses
Body
{order_id}/confirmPath variables
Request headers
{order_id}/rejectPath variables
Request headers
Request body
{order_id}/sentPath variables
Request headers
Request body
{order_id}/finish