Python connector for Salesforce Commerce Cloud via Open Commerce API
Project description
Salesforce Commerce Cloud connector
This package enables users to leverage a client offering resources to perform API calls against Salesforce Commerce Cloud (SFCC) via the standard Open Commerce API (OCAPI).
Features
- Business Manager user grant authentication
- Retry policy on each call:
- Applies to every request responding with 5xx status code
- Max of 5 minutes with exponential backoff strategy with a max wait time of 30s
- Stop after 5 mins of attempts
- Limited amount of APIs offered but highly scalable and flexible model to integrate more at need
Getting Started
Installation
To install the tool via pip
from PyPI
:
pip install sfcc-connector
Usage
Simple Example
#!/usr/bin/env python3
from __future__ import absolute_import
from datetime import datetime, timedelta
from sfcc_connector import SFCCClient
from apiclient.exceptions import APIRequestError
if __name__ == "__main__":
# !! Please replace values opportunely in your configuration !!
default_config = {
"domain": "<YOUR-DOMAIN:YOUR-PORT>",
"ocapi_version": "<YOUR-OCAPI-VERSION>",
"site_id": "<YOUR-SITE-ID>",
"use_ssl": False,
"is_production": False,
"username": "<YOUR_USERNAME>",
"password": "<YOUR_PASSWORD>",
"client_id": "<YOUR-CLIENT-ID>",
"client_password": "<YOUR-CLIENT-PWD>"
}
# Initialize client
client = SFCCClient(default_config)
# Perform calls against SFCC
try:
# Authentication is required to perform other calls
resp = client.authenticate()
print("Authentication response: {}".format(resp))
# Fetching order details for order with ID = 1
resp = client.get_order(1)
print("Get Order (1) response: {}".format(resp))
# Fetching all orders from yesterday up to now
end = datetime.now()
begin = end - timedelta(days=1)
resp = client.get_orders(begin, end)
print("Get Orders response: {}".format(resp))
# Fetching all jobs from yesterday up to now
resp = client.get_jobs(begin, end)
print("Get Jobs response: {}".format(resp))
except APIRequestError as e:
print("Error {}".format(e))
The SFCCClient
exposes a number of predefined methods that can be called to access equivalent resources on Salesforce Commerce Cloud.
authenticate
No arguments to be provided. Returns a valid token according to specs when successful.
get_orders
The query used by default will retrieve all orders having creation_date
or last_modified
within the time interval defined by given begin_date
and end_date
.
Provide another query (custom_query
) if you want to filter orders based on other criteria.
By default all order fields will be returned. If you need to retrieve only a selection of them, please provide a custom_select
as for example: custom_select="(hits.(data.(creation_date,confirmation_status,total)))"
Arguments | Format | Description |
---|---|---|
begin_date |
datetime |
Used to filter orders based on time interval |
end_date |
datetime |
Used to filter orders based on time interval |
(optional) custom_query |
dict |
To be built according to specs |
(optional) custom_select |
str |
To limit the amount of returned fields |
get_order
Arguments | Format | Description |
---|---|---|
order |
int |
Order ID to identify the order to be fetched |
get_jobs
The query used by default will retrieve all jobs having start_time
or end_time
within the time interval defined by given begin_date
and end_date
. Provide another query (custom_query
) if you want to filter orders based on other criteria.
By default all order fields will be returned. If you need to retrieve only a selection of them, please provide an opportune custom_select
Arguments | Format | Description |
---|---|---|
begin_date |
datetime |
Used to filter jobs based on time interval |
end_date |
datetime |
Used to filter jobs based on time interval |
(optional) custom_query |
dict |
To be built according to specs |
(optional) custom_select |
str |
To limit the amount of returned fields |
Contributing
Do you want to use this library for your own projects? Great!
- Want to contribute? Even better! Feel free to create a PR
- Found a bug? Open an issue
License
MIT Licensed. See LICENSE for full details.
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
Built Distribution
File details
Details for the file sfcc connector-1.0.3.tar.gz
.
File metadata
- Download URL: sfcc connector-1.0.3.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f3b12029ce6fb6ca82f70e7b24ac17f83575adacd1d4633380d02a8c9fbd82d |
|
MD5 | 6eacf6bd5e5a32d0727d2c8c4affaeb7 |
|
BLAKE2b-256 | 76a2ddd38b1c1cc2b68ea96b51164c20c91d833233c3a720cae98aba9cbdae79 |
File details
Details for the file sfcc_connector-1.0.3-py2.py3-none-any.whl
.
File metadata
- Download URL: sfcc_connector-1.0.3-py2.py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98ac1447729086d30dff4bdeb9c8b9de836812b7c443a032ebc1bd127408dfb5 |
|
MD5 | 7ba72d85c5d81ec6e011570bf569141d |
|
BLAKE2b-256 | edbe07fe677c9fe75504f6f0e842a4bc5a3c406e12f7b148918fe539b0b44acd |