Skip to main content

A python module for interacting with the Magento 2 REST API. GUI

Project description

Magento 2 API Package

Overview

This package provides an interface for interacting with the Magento 2 API, allowing you to perform various operations such as logging in, making API requests, and handling data. It is designed to simplify interactions with the Magento 2 API by managing authentication and making HTTP requests.

Features

  • User authentication with Magento 2 API
  • Making various types of API requests (GET, POST, PUT, DELETE)
  • Token-based session management
  • Handling API responses and errors

Installation

To use this package, you need to have Python installed on your system. Install the package using pip:

bash

Copy code

pip install magento-api-2

Alternatively, clone the repository and install it manually:

bash

Copy code

git clone https://github.com/Gunn1/Magento-API.git cd Magento-API pip install .

Usage

Authentication

The LoginController class handles user authentication and manages the login session. Here's how you can use it:

python

Copy code

`from magento_api import LoginController, Magento

Initialize the LoginController with your Magento credentials

login_controller = LoginController(username='your_username', password='your_password')

Log in to Magento

login_controller.login()

Check if the user is logged in

if login_controller.is_logged_in(): print("User is logged in.") else: print("User is not logged in.")`

Making API Requests

Once authenticated, you can make API requests using the Magento class. Here's an example:

python

Copy code

`from magento_api import Magento

Initialize the Magento class with the LoginController

magento = Magento(login_controller=login_controller)

Make a GET request to the API

response = magento.make_api_request( endpoint='https://your-magento-store.com/rest/V1/orders', request_type='get' )

print(response)`

Classes

LoginController

A class for managing the login process to the Magento 2 API.

Attributes:

  • token: Stores the authentication token.
  • store: The store code used in the API endpoint.
  • api_endpoint: The base URL for the Magento 2 API.
  • logged_in: Indicates if the user is logged in.
  • login_time: The timestamp when the user logged in.
  • token_expiration: The expiration time for the token (4 hours by default).

Methods:

  • __init__(self, username=None, password=None): Initializes the controller. Prompts for credentials if not provided.
  • login(self): Logs in the user and stores the token. Raises InvalidCredentialsError if login fails.
  • is_logged_in(self): Checks if the user is logged in by verifying the token's validity. Returns True or False.

Magento

A class for making API requests using an authenticated session.

Attributes:

  • login_controller: An instance of LoginController used for authentication.

Methods:

  • make_api_request(self, endpoint: str, params: Params = None, request_type: str = "get", data: dict = None, json: dict = None) -> dict: Makes an API request to the specified endpoint.

    Parameters:

    • endpoint (str): The API endpoint to send the request to.
    • params (Optional[Params]): Query parameters for the request.
    • request_type (str): Type of HTTP request ("get", "post", "put", "delete").
    • data (Optional[dict]): Data to send with the request (for POST and PUT requests).
    • json (Optional[dict]): JSON data to send with the request (for POST and PUT requests).

    Raises:

    • InvalidCredentialsError: If the user is not logged in.
    • PermissionDeniedError: If the request is unauthorized.
    • APIRequestError: If the request fails.

    Returns:

    • dict: The response data from the API request.

Contributing

Contributions are welcome! Please submit a pull request or open an issue to report bugs or request new features.

License

This package is licensed under the MIT License. See the LICENSE file for more details.

Contact

For questions or support, please contact tylerjgunn@gmail.com.

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

magento_2-0.0.1.tar.gz (28.9 kB view details)

Uploaded Source

Built Distribution

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

magento_2-0.0.1-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

Details for the file magento_2-0.0.1.tar.gz.

File metadata

  • Download URL: magento_2-0.0.1.tar.gz
  • Upload date:
  • Size: 28.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for magento_2-0.0.1.tar.gz
Algorithm Hash digest
SHA256 bdd18d2a33a81a6b04b4a71e3b2ebcb3f294219c023f0b16e1dfc9dfd5664eed
MD5 25f0f05dc0fbd54ffddef85f3e277bfa
BLAKE2b-256 ed0e885b7ea75a671c4009b2e15e9cb2f0132e3206743f6009de799ce8dfbcda

See more details on using hashes here.

File details

Details for the file magento_2-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: magento_2-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 27.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for magento_2-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5a6aec6aec42816dbdc7b64a11f7da260c8894220816422d94cced0600647461
MD5 a00f56a8c6b7eab69ba9a820be9a5655
BLAKE2b-256 c5ca842e9d3edcea4aaf0a8ab55b724876858a8cdaa5d40e713e9fe37879bb31

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