Skip to content
This repository has been archived by the owner on May 12, 2023. It is now read-only.

pardahlman/akeneo-csharp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b9738cb · May 15, 2017

History

57 Commits
Apr 16, 2017
May 15, 2017
May 14, 2017
May 15, 2017
Apr 13, 2017
Apr 13, 2017
Apr 17, 2017
Apr 19, 2017
Apr 25, 2017
Apr 16, 2017
Apr 17, 2017

Repository files navigation

Akeneo .NET Client

Build Status NuGet GitHub release

.NET Client to consume Akeneo PIM's RESTful API.

Getting started

Install NuGet package

This package is available as a release on nuget.org.

PM> Install-Package Akeneo.NET 

Create OAuth Client and Secret

Follow the official instructions to create client id and client secret

php app/console pim:oauth-server:create-client \
        --grant_type="password" \
        --grant_type="refresh_token"

Create .NET client

Create an instance of the client by providing the URL to Akeneo PIM together with client id/secret and user name and password. The client will request access token and refresh token when needed.

var client = new AkeneoClient(new ClientOptions
{
    ApiEndpoint = new Uri("http://localhost:8080"),
    ClientId = "1_3qwnpneuey80o080g0gco84ow4gsoo88skc880ssckgcg0okkg",
    ClientSecret = "3aw5l2xnvugwg0kc800g4k8s4coo80kkkc8ccs0so08gg08oc8",
    UserName = "admin",
    Password = "admdin"
});

Create, delete and update

That's it! Use the client's generic methods to create, get, update and remove Attributes, Attribute Options, Families, Categories and Products.

Note: There are some endpoints that are not implemented in the current version (1.7.3) of Akeneo PIM. For example, only products can be removed.

Programmatically define a product and specify its categories, values etc

var product = new Product
{
    Identifier = "nike_air",
    Categories = new List<string>
    {
        Category.Shoes,
        Category.Sport,
        Category.Fashion
    },
    Family = Family.Shoes,
    Values = new Dictionary<string, List<ProductValue>>
    {
        {
            "shoe_size", new List<ProductValue>
            {
                new ProductValue {Locale = Locales.EnglishUs, Data = "10"},
                new ProductValue {Locale = Locales.SwedenSwedish, Data = "42"},
            }
        },
        {
            "name", new List<ProductValue>
            {
                new ProductValue {Data = "Nike Air"}
            }
        }
    }
};

Add it to the PIM

var response = await Client.CreateAsync(product);
if (response.Code != HttpStatusCode.Created)
{
    _logger.Information(
        "Endpoint returned {statusCode}. Message: {message}, Errors: {@errors}",
        response.Code, response.Message, response.Errors
    );
})

Update it

product.Enabled = true;
var response = await Client.UpdateAsync(product);

Remove it

var response = await Client.DeleteAsync<Product>(product.Identifier);