Skip to main content

Client for several IKEA's APIs

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

Client for several IKEA APIs.

Test Coverage Version Python Downloads License

Features

With this library you can access the following IKEA's APIs:

  • Cart,
  • Delivery Services (actually, Order Capture),
  • Purchases (history and order info),
  • Items info (3 different services),
  • Search.

Also:

  • Fully typed and tested,
  • Has wrappers around most of APIs based on Pydantic.

Installation

pip install ikea_api

If you intend to use wrappers:

pip install "ikea_api[wrappers]"

Usage

IKEA object unites all available the APIs that are in this package. This is done to share token, country and language.

from ikea_api import IKEA

ikea = IKEA(token=None, country_code="ru", language_code="ru")

Endpoints reference

🔑 Authorization

First time you open IKEA.com, guest token is being generated and stored in cookies. Same thing must be done in here before using any endpoint.

This token expires in 30 days.

ikea.login_as_guest()

It is stored in token property:

ikea.token  # Outputs JWT token

Previously you could login as user (with login and password), but now there's very advanced telemetry that I wouldn't be able to solve in hundred years 🤪

🛒 Cart

With this endpoint you can do everything you can using IKEA's frontend:

  • Show the cart
ikea.cart.show()
  • Clear it
ikea.cart.clear()
  • Add, update and delete items
ikea.cart.add_items({"30457903": 1})  # { item_code: quantity }

ikea.cart.update_items({"30457903": 5})

ikea.cart.remove_items(["30457903"])
  • Set and clear coupon
ikea.cart.set_coupon(...)

ikea.cart.clear_coupon()
  • and even copy another user's cart.
ikea.cart.copy_items(source_user_id=...)

If you use authorized token (copy-paste from cookies), than you edit your user's actual cart.

💡 There's wrapper that clears current cart and adds items with error handling: if requested item doesn't exist, the function just skips it and tries again.

from ikea_api.wrappers import add_items_to_cart

add_items_to_cart(  # Function returns items that can't be added. In this case: ['11111111']
    ikea,
    items={
        "30457903": 1,
        "11111111": 2,  # invalid item that will be skipped
    },
)

🚛 Order Capture

Check pickup or delivery availability. If you need to know whether items are available in stores, check out ikea-availability-checker.

order = ikea.order_capture(
    zip_code="02215",
    state_code="MA",  # pass State Code only if your country has them
)
home_delivery_services = order.get_home_delivery_services()
collect_delivery_services = order.get_collect_delivery_services()

💡 You can use wrapper to add items to cart (clearing cart before and handling unknown item errors if they appear) and parse response in nice Pydantic models:

from ikea_api.wrappers import get_delivery_services

res = get_delivery_services(
   ikea,
   items={
       "30457903": 1,
       "11111111": 2,  # invalid item that will be skipped
   },
   zip_code="101000",
)
res.delivery_options  # List of parsed delivery services
res.cannot_add  # ['11111111']

📦 Purchases

History

This method requires authentication, so if you don't have authorized token, it won't work.

ikea.purchases.history()

# Get all purchases:
ikea.purchases.history(take=10000)

# Pagination:
ikea.purchases.history(take=10, skip=1)

💡 Get parsed response with the wrapper:

from ikea_api.wrappers import get_purchase_history

get_purchase_history(ikea)  # Returns list of parsed purchases

Order info

ikea.purchases.order_info(order_number=..., email=...)

# If you have authorized token, you can drop email:
ikea.purchases.order_info(order_number="111111111")

# The method also has other params but they're mostly internal:
ikea.purchases.order_info(
    order_number=...,
    email=...,
    queries=...,  # Queries that will be included in request, combine any of: ["StatusBannerOrder", "CostsOrder", "ProductListOrder"]. By default, all of them are included.
    # Params below are relevant to ProductListOrder
    skip_products=...,
    skip_product_prices=...,
    take_products=...,
)

💡 Get parsed response with the wrapper:

from ikea_api.wrappers import get_purchase_info

get_purchase_info(  # Returns parsed purchase object. Items are not listed.
   ikea,
   id=...,
   email=...,
)

🪑 Item info

Get item specification by item code (product number or whatever). There are 3 endpoints to do this because you can't get all the data about all the items using only one endpoint.

from ikea_api import IowsItems, IngkaItems, PipItem

item_code = "30457903"
item_codes = [item_code]

# <=90 items at a time
IowsItems()([item_codes])

# <=50 items at a time
IngkaItems()([item_codes])

# 1 item at a time
PipItem()(item_code)

💡 You probably won't want to use raw APIs when there's convenient "smart" wrapper that combines them all and parses basic info:

from ikea_api.wrappers import get_items

get_items(["30457903"])

🔎 Search

Search for products in the product catalog by product name. Optionally also specify a maximum amount of returned search results (defaults to 24) and types of required search results.

ikea.search("Billy")

# Retrieve 10 search results (default is 24)
ikea.search("Billy", limit=10)

# Configure search results types
ikea.search(
    "Billy",
    types=...,  # Combine any of: ["PRODUCT", "CONTENT", "PLANNER", "REFINED_SEARCHES", "ANSWER"]
)

Utilities

Parse item codes

Parse item codes from string or list.

from ikea_api import parse_item_codes

assert parse_item_codes("111.111.11") == ["11111111"]
assert parse_item_codes("11111111, 222.222.22") == ["11111111", "22222222"]
assert parse_item_codes("111") == []

Format item code

Parse item code and format it.

from ikea_api import format_item_code

assert format_item_code("11111111") == "111.111.11"
assert format_item_code("111-111-11") == "111.111.11"
assert format_item_code("111.111.11") == "111.111.11"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ikea_api-1.1.2.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ikea_api-1.1.2-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

Details for the file ikea_api-1.1.2.tar.gz.

File metadata

  • Download URL: ikea_api-1.1.2.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for ikea_api-1.1.2.tar.gz
Algorithm Hash digest
SHA256 e762d724c2f33500784f9b19353131b70be21a1dd37bd830141ed7769d0183bb
MD5 fbc403bbdd5b2dd5f2f430b503d2a60b
BLAKE2b-256 4f73caf6b336e8df2429f0d35702d453a71348cde2707c43492e811409596c33

See more details on using hashes here.

File details

Details for the file ikea_api-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: ikea_api-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 30.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.1

File hashes

Hashes for ikea_api-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 888a8de10e57c5c5fd99ca22630bdc81860ec8df14cea67d5e1bb3f902d2008c
MD5 a341157a6a7e048deefa2b179ebf18af
BLAKE2b-256 3c60a33dd04d5d44b614ba9a2b75311e1096539f369119d8e0ce22eaef5bb187

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page