Uploading images To My Fashion Emporium using our API

My Fashion Emporium Support
2018-01-22 09:46

You can use the following API commands to upload images directly in to My Fashion Emporium. In order to use the API, you must request a application Key by sending your request to support@myfashionemporium.com

  • Our system uses OAuth2 implicit authorization for user grants.  To request a user access token, send the request to https://www.myfashionemporium.com/api/authorize.php?response_type=token&client_id=<client_id>&state=<session_id>
  • Access Tokens are valid for 30 days at which time the user will have to authenticate again. If the API returns a HTPP status of 401 Unauthorized, you must send a new authorization request. JSON success will be false and  error will be invalid_token as well.
  • All commands are post commands and are sent to https://www.myfashionemporium.com/api/remoteadd.php

All commands require the following two fields:

  1. access_token: This is the Access Token that was returned in the users authorization request. 
  2. action: This is the action that is being requested. Valid actions are getStyles, getSizes, and addItem.

When the action is addItem to upload an item image, the following additional fields are also required:

  1. styleID: This is the selected style id. This id is the value field when you retrieve the styles using the getStyles action.
  2. sizeID: This is the selected size id. This id is the value field when you retrieve the sizes using the getSizes action.
  3. qty: This is an optional field and defaults to 1. If you choose to use this field, use this to specify the available quantity of the item being uploaded.
  4. imageName: The file name of the image being uploaded.
  5. imageData: This is the image and must be in the base64 encoded URI scheme. See here for details. The system expects the string to be formatted as  data:<image mime type>;base64,<base64 encoded image data>.

Action responses from the server are return using a JSON object with the following fields. If an error occurs the server will also have a HTTP status code 400 (Bad Request)

  1. success : This will be true or false depending if the request was successful or not.
  2. data: This will contain the requested data if result is true. Will not be present if success is false.
  3. error: This is the generic error label. Will not be present if success is true.
  4. error_description: This is the verbose error description. Will not be present if success is true

My Fashion Emporium supports multiple clothing lines so the styles and sizes will not always be the same and our users have the ability to create their own styles and sizes as they see fit. Due to this you will need to retrieve the styles and sizes from our system before you make them available for selection by your users. 

To get a list of styles using Java Script and jquery:

Ajax command:
$.ajax({
      url: 'https://www.myfashionemporium.com/api/remoteadd.php',
     data:  {
          access_token: "4a64ef8bed8cdc1110ff5cwz398a6c67",
          action: "getStyles"
     }
     dataType: "json",
     type: 'POST',
     success: function(rsp){
          if (rsp.success  == false){
              console.log('Request Error: '+rsp.error_description);
          }else{
               console.log(rsp.data);
          }
     }
});

Response in JSON:
{
      "success ":true,
      "data":[
             {"name":"Adeline","value":"1"},
             {"name":"Album Test","value":"201"},
             {"name":"Amelia","value":"2"}
              ....
      ]
}

Name contains the style name and value contains the styleID that is passed when using the addItem action.

To get a list of sizes using Java Script and jquery:

Ajax command:
$.ajax({
      url: 'https://www.myfashionemporium.com/api/remoteadd.php',
     data:  {
          access_token: "4a64ef8bed8cdc1110ff5cwz398a6c67",
          action: "getSizes"
     }
     dataType: "json",
     type: 'POST',
     success: function(rsp){
          if (rsp.success == false){
              console.log('Request Error: '+rsp.error_description);
          }else{
               console.log(rsp.data);
          }
     }
});

Response in JSON:
{
      "success ":true,
      "data":[
             {"name":"XXS","value":"2"},
             {"name":"XS","value":"3"},
             {"name":"S":"4"},
              ....
      ]
}

Name contains the size name and value contains the sizeID that is passed when using the addItem action.

To upload an image using Java Script and jquery:

Ajax command:
toDataURL('http://www.somserver.com/item_2564.JPG', function(imageDataUrl) {
      $.ajax({
           url: 'https://www.myfashionemporium.com/api/remoteadd.php',
           data:  {
                access_token: "4a64ef8bed8cdc1110ff5cwz398a6c67",
                action: "getSizes",
                styleID: 1,
                sizeID: 6,
                imageName: "item_2564.JPG",
                imageData: imageDataUrl
           }
           dataType: "json",
           type: 'POST',
           success: function(rsp){
                if (rsp.success == false){
                    console.log('Request Error: '+rsp.error_description);
                }else{
                    console.log(rsp.data);
                }
           }
      });
});

Response in JSON:
{
      "success ":true,
      "data": 1254
}

Data returns the newly created item ID.

Below is the toDataURL function that is used in the above example to load an image to a base64 encoded format.  You may need to create a function to load the image if the image is on the local device and not a http server.

function toDataURL(url, callback) {
      var xhr = new XMLHttpRequest();
      xhr.onload = function() {
            var reader = new FileReader();
            reader.onloadend = function() {
                  callback(reader.result);
            }
            reader.readAsDataURL(xhr.response);
      };
      xhr.open('GET', url);
      xhr.responseType = 'blob';
      xhr.send();
}

If you have any questions or issues, please contact our support team at support@myfashionemporium.com

Tags: API
Average rating: 5 (1 Vote)

You cannot comment on this entry