Code Monkey home page Code Monkey logo

ikea-api-client's People

Contributors

actions-user avatar dependabot[bot] avatar erik142 avatar github-actions[bot] avatar letmaik avatar momoson avatar sqr avatar vrslev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

ikea-api-client's Issues

KeyError: 'details' when using US zip codes

Hello, I am investigating the following error:

Traceback (most recent call last):
  File "ikea.py", line 17, in <module>
    api.OrderCapture(zip_code="02215")
  File "/home/square/ikea-api/ikea_api/core.py", line 64, in OrderCapture
    return OrderCapture(self._token, zip_code)()
  File "/home/square/ikea-api/ikea_api/endpoints/order_capture/__init__.py", line 29, in __call__
    return self.get_delivery_services()
  File "/home/square/ikea-api/ikea_api/endpoints/order_capture/__init__.py", line 93, in get_delivery_services
    delivery_area = self._get_delivery_area(checkout)
  File "/home/square/ikea-api/ikea_api/endpoints/order_capture/__init__.py", line 80, in _get_delivery_area
    response = self._call_api(
  File "/home/square/ikea-api/ikea_api/api.py", line 70, in _call_api
    self._error_handler(response.status_code, response_dict)
  File "/home/square/ikea-api/ikea_api/endpoints/order_capture/__init__.py", line 33, in _error_handler
    raise OrderCaptureError(response)
  File "/home/square/ikea-api/ikea_api/errors.py", line 44, in __init__
    if response["message"] == response["details"]
KeyError: 'details'

It seems to happen with all the United States zip codes I have tried.

My script is as follows:

from ikea_api import IkeaApi

api = IkeaApi(
    token=...,  # If you already have a token and stored it somewhere
    country_code="us",
    language_code="en",
)

api.login_as_guest()

cart = api.Cart
cart.add_items({"90446761": 1})
# print(cart.show())

api.OrderCapture(zip_code="02215")

Showing the cart works.

I am going to query the api manually and see how the response looks, in case I can spot the problem.

Purchases API has changed

Currently you get an Internal Server Error when using the Purchases API.
I already found that the API endpoint changed
ikea_api/endpoints/purchases.py > _get_session_info() must now use
https://cssom-prod.ingka.com/purchase-history/graphql

However I still get this JSON response:

{
    "data": {
        "history": []
    }
}

When I use a browser I however am able to see my history.
From the network tab it appears that there is another request made before the one that returns the history
First one:
Request:

[
  {
    "operationName": "Authenticated",
    "query": "query Authenticated {\n  authenticated\n}",
    "variables": {}
  }
]

Response:

[
  {
    "data": {
      "authenticated": true
    }
  }
]

Second one:
Request:

[
  {
    "operationName": "History",
    "query": "query History($skip: Int!, $take: Int!) {\n  history(skip: $skip, take: $take) {\n    id\n    dateAndTime {\n      ...DateAndTime\n      __typename\n    }\n    status\n    eventStatus\n    storeName\n    totalCost {\n      code\n      value\n      formatted\n      __typename\n    }\n    type\n    __typename\n  }\n}\n\nfragment DateAndTime on DateAndTime {\n  time\n  date\n  formattedLocal\n  formattedShortDate\n  formattedLongDate\n  formattedShortDateTime\n  formattedLongDateTime\n  __typename\n}",
    "variables": {
      "skip": 0,
      "take": 5
    }
  }
]

Response:

[
  {
    "data": {
      "history": [
        {
          "id": "100",
          "status": "IN_PROGRESS"
          "more fields": "..."
          
        },
        {
          "id": "101",
          "status": "COMPLETED"
          "more fields": "..."
          
        }
      ]
    }
  }
]

I'm not too familiar with these requests yet and couldn't figure out how to fix it :/

Retail ID is not supported: en

Hello, thanks for taking the time to make this client.

The examples provided in the readme work, however, when I try to change the language code to english and location to the united states, I get the following error

ikea_api.errors.UnauthorizedError: Retail ID is not supported: en

Traceback (most recent call last): File "ikea.py", line 14, in <module> cart.add_items({"40453645": 1}) File "/home/square/ikea-api/ikea_api/endpoints/cart/__init__.py", line 21, in inner return self._call_api(data=self._build_payload(query, **variables)) # type: ignore File "/home/square/ikea-api/ikea_api/api.py", line 69, in _call_api self._basic_error_handler(response.status_code, response_dict) File "/home/square/ikea-api/ikea_api/api.py", line 43, in _basic_error_handler raise UnauthorizedError(response) ikea_api.errors.UnauthorizedError: Retail ID is not supported: en

The only thing I've changed is

country_code="us", language_code="en",

Any ideas on why this might be causing an issue?

Thanks!

400: Invalid GetItemCommunicationsRequest.ClassUnitType: value is not a valid enum

Hey,

I intend to use this library as a backend and write a fancy frontend on it. I made an api layer using flask to call the library but I encountered some issues.

Calling the getitem API results in the following repsonse:
ikea_api.exceptions.NotSuccessError: (400, '{"error":{"code":400,"message":"invalid GetItemCommunicationsRequest.ClassUnitType: value is not a valid enum"}}')

Code snippet:
constants = ikea_api.Constants(country="it", language="it", base_url="https://www.ikea.com") itemCode = ["00366301","29902933","60366303"] items = await ikea_api.get_items(constants,itemCode)

My question is do I ignore the 400?
I am hoping someone managed to get around this.

feature suggestion: Search for products by name

Hi again,

I believe that it would be beneficial to be able to search for products by name and get information back, including the item number for the product. I have a first implementation ready for this feature if it is of any interest to this project?

I have only tested it on the Swedish version of the corresponding IKEA API. However, the API seems to follow the same "region naming scheme" as the existing API endpoints in this project, so I believe that it should work in the same way for other regions. Let me know if this sounds interesting. If so, I'll add a PR for this 😄

API endpoint IngkaItems does not work as expected

When trying to fetch info on some IKEA items, I ran into the following error message being raised:

File "foo/bar.py", line 19, in <module>
  response = ikea_api.IngkaItems()(['40263848'])
File "/usr/local/lib/python3.9/site-packages/ikea_api/_endpoints/item_ingka.py", line 39, in __call__
  return self._get(params={"itemNos": item_codes})
File "/usr/local/lib/python3.9/site-packages/ikea_api/_api.py", line 60, in _get
  return self._handle_response(response)
File "/usr/local/lib/python3.9/site-packages/ikea_api/_api.py", line 44, in _handle_response
  self._error_handler(response)
File "/usr/local/lib/python3.9/site-packages/ikea_api/_endpoints/item_ingka.py", line 34, in _error_handler
  raise ItemFetchError(response, item_codes)
ikea_api.exceptions.ItemFetchError: (400, '{"error":{"code":400,"message":"invalid GetItemCommunicationsRequest.ClassUnitType: value is not a valid enum"}}')

I have tested this with multiple item numbers.

Error when trying to get auth token

Hello,

Thanks a lot for providing us with this public repo.

I'm running python 3.11 and my intention is to get product id's and the end goal is serve this repo over a restful api mainly to get product info such as price. I'm getting the below error.

I'm running the below command

ikea_api.Auth(constants).get_guest_token()

and getting the below error

EndpointInfo(func=functools.partial(<function Auth.get_guest_token at 0x1046c6480>, <ikea_api.endpoints.auth.Auth object at 0x1063c33d0>), handlers=[<function handle_json_decode_error at 0x104467c40>, <function handle_401 at 0x1046c5300>, <function handle_not_success at 0x1046c6020>])

Unable to check stock of an item, response includes code 606.

Hi, I've been trying to use your API to check stock of an item, to do this I used the following code:

import ikea_api

constants = ikea_api.Constants(country="pl", language="pl")
stock = ikea_api.Stock(constants)
endpoint = stock.get_stock("00366301")

print(ikea_api.run(endpoint))

This prints out the following message:

{'code': 606, 'message': 'classUnitType in path should be one of [ru sto]'}

And I'm stuck right here, I have no idea what can I do to fix this issue.
Is there anything I can do to fix this? Thanks for reading : )

RCRalph

Using getitems async

@vrslev I debugged my issue from my previous request and it came down to calling ikea_api.get_items in an async manner.

Could I make a request to add to the documentation an example of this to avoid RuntimeError: Event loop is closed

About favorites

Is there any way to add "shopping list" (favorites) functionality? Does IKEA provide access to them in its api, and can you add this to your client?

KeyError: 'details' when using Swedish OrderCapture API

Hello,

Thank you for creating this IKEA api client, I find it very useful for a project that I am currently working on. I am having an issue with the "order capture" api in Sweden, which seems to result in the same error as #33. The latest version (0.7.0) does not solve this issue for me. See error below:

Traceback (most recent call last):
  File "d:\Filer\Utveckling\Projekt\Python\IKEA-notifier\src\app.py", line 8, in <module>
  File "d:\Filer\Utveckling\Projekt\Python\IKEA-notifier\src\api\ikea_availability_api.py", line 17, in getAvailability
    availabilities = self.__IKEA_API.OrderCapture(
  File "C:\Users\Erik\AppData\Local\Programs\Python\Python39\lib\site-packages\ikea_api\core.py", line 64, in OrderCapture
    return OrderCapture(self._token, zip_code, state_code)()
  File "C:\Users\Erik\AppData\Local\Programs\Python\Python39\lib\site-packages\ikea_api\endpoints\order_capture\__init__.py", line 32, in __call__
    return self.get_delivery_services()
  File "C:\Users\Erik\AppData\Local\Programs\Python\Python39\lib\site-packages\ikea_api\endpoints\order_capture\__init__.py", line 97, in get_delivery_services
    checkout: str | None = self._get_checkout()
  File "C:\Users\Erik\AppData\Local\Programs\Python\Python39\lib\site-packages\ikea_api\endpoints\order_capture\__init__.py", line 71, in _get_checkout
    response: dict[str, str] = self._call_api(
  File "C:\Users\Erik\AppData\Local\Programs\Python\Python39\lib\site-packages\ikea_api\api.py", line 70, in _call_api
    self._error_handler(response.status_code, response_dict)
  File "C:\Users\Erik\AppData\Local\Programs\Python\Python39\lib\site-packages\ikea_api\endpoints\order_capture\__init__.py", line 36, in _error_handler
    raise OrderCaptureError(response)
    if response["message"] == response["details"]
KeyError: 'details'

The error can be reproduced by running the following code:

api = IkeaApi(country_code='se', language_code='sv')
api.login_as_guest()

api.Cart.clear()
api.Cart.add_items({"20512245": 1})
cart_show = api.Cart.show()    # The show method works as expected, showing the added item in the cart
api.OrderCapture(zip_code="12345")    # Mock zip-code here, but it does not work with a valid zip code either

I have debugged the issue myself and have traced it down to the hard coded "ru" language code in the file "src/ikea_api/endpoints/order_capture/__init__.py" (line 66):

data = {
"shoppingType": "ONLINE",
"channel": "WEBAPP",
"checkoutType": "STANDARD",
"languageCode": "ru",
"items": items,
"deliveryArea": None,
}

By changing this to:

data = {
            "shoppingType": "ONLINE",
            "channel": "WEBAPP",
            "checkoutType": "STANDARD",
            "languageCode": Constants.LANGUAGE_CODE,
            "items": items,
            "deliveryArea": None,
        }

the issue is solved for me. I do not think that this change would create any further issues for other regions and languages, so I will go ahead and create a PR to fix this.

If there is any potential issue with this change, please let me know.

Thanks!

Handle internal error

ikea_api/api.py», line 62, in basic_error_handler
    raise Exception(code + ‘, ‘ + str(err))
Exception: INTERNAL_ERROR, {‘message’: ‘an internal error has occurred’, ‘extensions’: {‘code’: ‘INTERNAL_ERROR’, ‘requestId’: ‘localhost/ByzaAoxjs4-5483209’}}

Only able to get_items from Russia

If I change the COUNTRY_CODE and LANGUAGE_CODE from "ru" to "hu" or "at" it's not working anymore. With default values it works fine and I get a response.

If source is:

from ikea_api.wrappers import get_items
from ikea_api._constants import Constants

Constants.COUNTRY_CODE = "ru"
Constants.LANGUAGE_CODE = "ru"

print(get_items(["09251777"]))

Response is:

[ParsedItem(is_combination=True, item_code='49251780', name='КЛИППАН, 2-местный диван, Кабуса темно-серый', image_url='https://www.ikea.com/ru/ru/images/products/klippan-2-mestnyy-divan-kabusa-temno-seryy__0562986_pe663639_s5.jpg', weight=0.0, child_items=[ChildItem(name=None, item_code='50501293', weight=0.0, qty=1), ChildItem(name=None, item_code='00398726', weight=0.0, qty=1)], price=14999, url=HttpUrl('https://www.ikea.com/ru/ru/p/klippan-klippan-2-mestnyy-divan-kabusa-temno-seryy-s49251780/', scheme='https', host='www.ikea.com', tld='com', host_type='domain', port='443', path='/ru/ru/p/klippan-klippan-2-mestnyy-divan-kabusa-temno-seryy-s49251780/'), category_name='Двухместные диваны', category_url=HttpUrl('https://www.ikea.com/ru/ru/cat/dvuhmestnye-divany-10668/', scheme='https', host='www.ikea.com', tld='com', host_type='domain', port='443', path='/ru/ru/cat/dvuhmestnye-divany-10668/'))]

If source is:

from ikea_api.wrappers import get_items
from ikea_api._constants import Constants

Constants.COUNTRY_CODE = "hu"
Constants.LANGUAGE_CODE = "hu"

print(get_items(["09251777"]))

Response is:

Traceback (most recent call last):
  File "/Users/gergelymarosi/_hobbi/ikea/main.py", line 7, in <module>
    print(get_items(["09251777"]))
  File "/Users/gergelymarosi/_hobbi/ikea/venv/lib/python3.9/site-packages/ikea_api/wrappers/__init__.py", line 192, in get_items
    fetched_items_ingka_pip = _get_ingka_pip_items(pending_item_codes)
  File "/Users/gergelymarosi/_hobbi/ikea/venv/lib/python3.9/site-packages/ikea_api/wrappers/__init__.py", line 164, in _get_ingka_pip_items
    ingka_items = _get_ingka_items(item_codes)
  File "/Users/gergelymarosi/_hobbi/ikea/venv/lib/python3.9/site-packages/ikea_api/wrappers/__init__.py", line 142, in _get_ingka_items
    responses.append(fetcher(item_codes_chunk))
  File "/Users/gergelymarosi/_hobbi/ikea/venv/lib/python3.9/site-packages/ikea_api/_endpoints/item_ingka.py", line 39, in __call__
    return self._get(params={"itemNos": item_codes})
  File "/Users/gergelymarosi/_hobbi/ikea/venv/lib/python3.9/site-packages/ikea_api/_api.py", line 60, in _get
    return self._handle_response(response)
  File "/Users/gergelymarosi/_hobbi/ikea/venv/lib/python3.9/site-packages/ikea_api/_api.py", line 44, in _handle_response
    self._error_handler(response)
  File "/Users/gergelymarosi/_hobbi/ikea/venv/lib/python3.9/site-packages/ikea_api/_endpoints/item_ingka.py", line 34, in _error_handler
    raise ItemFetchError(response, item_codes)
ikea_api.exceptions.ItemFetchError: (400, '{"error":{"code":400,"message":"invalid GetItemCommunicationsRequest.ClassUnitType: value is not a valid enum"}}')

Use different query for adding items

{"query":"\n    mutation {\n      addItems(items: [\n        {itemNo: \"40372084\", quantity: 1}\n      ]) {\n        quantity\n        context {\n          userId\n          isAnonymous\n          retailId\n        }\n      }\n    }\n  "}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.