StorageCustomer

This particular WebAPI contains all methods a customer can use. It is a RESTful API, meaning that every call to this webservice should contain enough information for a single call to complete its operation.

Every response uses HTTP-code to indicate success or failure.
200 - Indicates success.
4XX - Indicates a general common failure - often a message in english stating excatly what happened is contained in the body.
500 - Indicates an server side exception that was not handled happened.

APIDescription
POST Api/StorageCustomer/Login

Authenticates an user and returns a so called auth-token that must be in the request -header of every subsequent call. The name of the value pair sent in each header must be auth_token and the value must be the token returned from this call.

POST Api/StorageCustomer/RemoteLoginApp

Authenticates an user and returns a so called auth-token that must be in the request -header of every subsequent call. The name of the value pair sent in each header must be auth_token and the value must be the token returned from this call.

POST Api/StorageCustomer/FindAllAvailableItems

Retreives an array of pairs: item- ids and the names of items associated with the company and user.

GET Api/StorageCustomer/ItemById/{imagesize}/{requestedFormat}/{id}?fImageLinks={fImageLinks}&getExtraFields={getExtraFields}

Retreives information about a singular mediaitem.

POST Api/StorageCustomer/ItemsByIds

Retreives media -items from OPV Storage identified by an array of ids, and the requested size and image-type. An items image-link is generated by this method.

GET Api/StorageCustomer/Image/{imagesize}/{requestedFormat}/{route}

Requests an image of a certain size and format. Route must be correct and exists. Route must end with an auth-token.

GET Api/StorageCustomer/GetItemsByCategoryId/{imagesize}/{requestedFormat}/{id}?includeExtraFields={includeExtraFields}&useUserFriendlyImageLinks={useUserFriendlyImageLinks}

Returns a list of item -data under a category specified by a category -id. If the category doesn't exists or is empty, an empty list is returned (http code 200).

GET Api/StorageCustomer/GetCategoryTreeItems/{categoryId}?language={language}

Returns a list of category -items by specifying a category -id, but without its children an user has access to. Using the id 0 or -1 will return the root -nodes. If you are specifying an invalid id or an id that doesn't exists, an empty set will be returned.

GET Api/StorageCustomer/GetCategoryTree?language={language}

Returns the entire category tree, including subcategories. If it exists a translation you may use the language -code. If no translation can be found, the default -name will be used. Categoryitems that the current user do not have access to, are omitted.

Examples

Here is a few examples of what you can do. Please note that if you use AJAX you might run into crossdomaincall-troubles. The C# examples uses RestSharp and Newtonsofts JSON-lib.

C# - Example 1 - Logging in

            string auth = "";
            RestClient client = new RestClient();
            client.BaseUrl = new Uri( "https://api.opv.se/ws/storage/v102/" );
            var request = new RestRequest("api/StorageCustomer/Login");
            request.AddHeader("content-type", "application/json");
            request.AddJsonBody(new { Username = "Foo", Password = "Bar" } );
            request.Method = Method.POST;
            var response = client.Execute(request);
            switch (response.StatusCode)
            {
                case System.Net.HttpStatusCode.OK:
                    {
                            auth = JsonConvert.DeserializeObject(response.Content);
                            break;
                    }
                case System.Net.HttpStatusCode.Forbidden:
                    {
                        //do something
                        break;
                    }
                case System.Net.HttpStatusCode.BadRequest:
                    {
                        //do something
                        break;
                    }
            }
        

C# - Example 2 - Finding all available items

            request = new RestRequest("api/StorageCustomer/FindAllAvailableItems");
            request.AddHeader("content-type", "application/json");
            request.AddHeader("auth_token", auth);
            request.Method = Method.POST;
            response = client.Execute(request);
            switch (response.StatusCode)
            {
                case System.Net.HttpStatusCode.OK:
                    {
                        //do something
                        break;
                    }
                case System.Net.HttpStatusCode.Forbidden:
                    {
                        //do something
                        break;
                    }
                case System.Net.HttpStatusCode.BadRequest:
                    {
                        //do something
                        break;
                    }
            }
        

C# - Example 3 - Requesting item information and image -links

            request = new RestRequest("api/StorageCustomer/ItemsByIds");
            request.AddHeader("content-type", "application/json");
            request.AddHeader("auth_token", auth);
            request.AddJsonBody( new{
                                        ItemIds =new List<long>() { 135865, 135916 },
                                        ImageFormat = "Jpg",
                                        Size ="px150",
                                        UseUserFriendlyImageLinks = true,
                                        IncludeExtrafields  = false
                                    }
            );
            request.Method = Method.POST;
            response = client.Execute(request);
            switch (response.StatusCode)
            {
                case System.Net.HttpStatusCode.OK:
                    {
                        //do something
                        break;
                    }
                case System.Net.HttpStatusCode.Forbidden:
                    {
                        //do something
                        break;
                    }
                case System.Net.HttpStatusCode.BadRequest:
                    {
                        //do something
                        break;
                    }
            }
                                                                        
        

C# - Example 4 - Getting the root nodes of the categorytree

            request = new RestRequest("api/StorageCustomer/GetCategoryTreeItems/0");
            request.AddHeader("content-type", "application/json");
            request.AddHeader("auth_token", auth);
            request.Method = Method.GET;
            response = client.Execute(request);
            switch (response.StatusCode)
            {
                case System.Net.HttpStatusCode.OK:
                    {
                        /*
                         * Known structure
                         * 
                         *    public long CategoryItemId { set; get; }
                         *    public long ParentId { set; get; }
                         *    public string Name { set; get; }
                         *    public List<ServiceCategoryItem> Children { set; get; }
                         * 
                         * */
                        var converter = new ExpandoObjectConverter(); //we use a so called expando-object that creates a class from the JSON (more or less) in runtime
                        dynamic serviceCategoryItemList = JsonConvert.DeserializeObject<List<ExpandoObject>>(response.Content, converter);

                        foreach (var categoryItem in serviceCategoryItemList)
                        {
                            Console.WriteLine(categoryItem.Name);
                        }


                        break;
                    }
            }

    

C# - Example 5 - Getting the entire categorytree

            request = new RestRequest("api/StorageCustomer/GetCategoryTree");
            request.AddHeader("content-type", "application/json");
            request.AddHeader("auth_token", auth);
            request.Method = Method.GET;
            response = client.Execute(request);
            switch (response.StatusCode)
            {
                case System.Net.HttpStatusCode.OK:
                    {
                        /*
                         * Known structure
                         * 
                         *    public long CategoryItemId { set; get; }
                         *    public long ParentId { set; get; }
                         *    public string Name { set; get; }
                         *    public List<ServiceCategoryItem> Children { set; get; }
                         * 
                         * */
                        var converter = new ExpandoObjectConverter(); //we use a so called expando-object that creates a class from the JSON (more or less) in runtime
                        dynamic serviceCategoryItemList = JsonConvert.DeserializeObject<List<ExpandoObject>>(response.Content, converter);

                        foreach( var categoryItem in serviceCategoryItemList)
                        {
                            Console.WriteLine(categoryItem.Name);
                            Console.WriteLine(categoryItem.ParentId);
                            Console.WriteLine(categoryItem.CategoryItemId);

                            foreach( var child in categoryItem.Children)
                            {
                                //do something
                            }

                        }
                        break;
                    }
            }


C# - Example 6 - Getting the entire categorytree in Swedish plus category -description

            request = new RestRequest("api/StorageCustomer/GetCategoryTree?language=sv-SE");
            request.AddHeader("content-type", "application/json");
            request.AddHeader("auth_token", auth);
            request.Method = Method.GET;
            response = client.Execute(request);
            switch (response.StatusCode)
            {
                case System.Net.HttpStatusCode.OK:
                    {
                        /*
                         * Known structure
                         * 
                         *    public long CategoryItemId { set; get; }
                         *    public long ParentId { set; get; }
                         *    public string Name { set; get; }
                         *    public List<ServiceCategoryItem> Children { set; get; }
                         * 
                         * */
                        var converter = new ExpandoObjectConverter(); //we use a so called expando-object that creates a class from the JSON (more or less) in runtime
                        dynamic serviceCategoryItemList = JsonConvert.DeserializeObject<List<ExpandoObject>>(response.Content, converter);
                        foreach( var categoryItem in serviceCategoryItemList)
                        {
                            Console.WriteLine(categoryItem.Name);
                            Console.WriteLine(categoryItem.ParentId);
                            Console.WriteLine(categoryItem.CategoryItemId);
                            Console.WriteLine(categoryItem.Description);
                            foreach( var child in categoryItem.Children)
                            {
                                //do something
                            }
                        }
                        break;
                    }
            }

Ajax - Example 1 - Finding all available items

         $.ajax({
            type: "POST",
            dataType: "json",
            url: "https://api.opv.se/ws/storage/v102/Api/StorageCustomer/FindAllAvailableItems",
            headers : { "auth_token" : auth},
            success: function (data) {
                //do something with the array of [id][name]
            },
            error: function (xhr, textStatus, errorThrown) {
                switch (xhr.state) {
                    case 400:
                        //Bad request 
                        break;
                    case 403:
                        //forbidden
                        break;
                    case 404:
                        //not found
                        break;
                    case 500:
                        //internal server error (various)
                        break;
                }
            }
        });
        

Ajax - Example 2 - Getting info on a specific item containing an "userfriendly" link to a Jpeg- image of size 500

         $.ajax({
            type: "POST",
            dataType: "json",
            url: "https://api.opv.se/ws/storage/v102/Api/StorageCustomer/ItemById/px500/Jpg/135865?fImageLinks=true",
            headers : { "auth_token" : auth},
            success: function (data) {
                //do something
            },
            error: function (xhr, textStatus, errorThrown) {
                switch (xhr.state) {
                    case 400:
                        //Bad request 
                        break;
                    case 403:
                        //forbidden
                        break;
                    case 404:
                        //not found
                        break;
                    case 500:
                        //internal server error (various)
                        break;
                }
            }
        });