Skip to content

asimlqt/akeneo-api-python-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Akeneo API Python Client

A simple Python client for the Akeneo PIM API

Installation

pip install akeneo-api-client

Usage

Initialise the client

from akeneo_api_client.client_builder import ClientBuilder
from akeneo_api_client.client.akeneo_api_error import AkeneoApiError

cb = ClientBuilder(uri)
api = cb.build_authenticated_by_password(username, password, client_id, secret)

Or if you already have a cached version of the token you can use:

api = cb.build_authenticated_by_token(client_id, secret, token, refresh_token)

Fetch a product

try:
    response = api.product_uuid_api.get(uuid)
    print(response)
except AkeneoApiError as e:
    print(e.response.status_code)
    print(e.response_body)

Iterate over a list of products

from akeneo_api_client.search.search_builder import SearchBuilder

sb = SearchBuilder()
sb.add_filter('updated', '>', '2023-11-29 00:00:00')
sb.add_filter('completeness', '=', 100, {"scope": "ecommerce"})
sb.add_filter('enabled', '=', True)
search = sb.get_filters()

try:
    for page in api.product_uuid_api.all(query_params={"search": search}):
        for item in page:
            print(item["uuid"])
except AkeneoApiError as e:
    print(e.message)

Create a product

try:
    response = api.product_uuid_api.create(data={"family":"my_family"})
    print(response.headers.get("location"))
except AkeneoApiError as e:
    print(e.response_body)

Upsert a product

This call will create a product if it doesn't exist or update it if it does

data = {
    "values": {
        "Product_name": [
            {"scope": None, "locale": "en_GB", "data": "My product"}
        ]
    }
}

try:
    api.product_uuid_api.upsert(uuid, data)
except AkeneoApiError as e:
    print(e.message)

Upsert a list of products

products = [
    {
        "uuid": str(uuid.uuid4()),
        "values": {
            "Product_name": [
                {"scope": None, "locale": "en_GB", "data": "Product 1"}
            ]
        }
    },
    {
        "values": {
            "Product_name": [
                {"scope": None, "locale": "en_GB", "data": "Product 2"}
            ]
        }
    }
]

try:
    response = api.product_uuid_api.upsert_list(products)
    for item in response:
        if item['status_code'] >= 400:
            print(item)
except AkeneoApiError as e:
    print(e.response.reason)

Delete a product

try:
    api.product_uuid_api.delete(uuid)
except AkeneoApiError as e:
    print(e.response_body)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages