This post outlines a Python script for interacting with the Magaya SOAP API. It demonstrates how to establish a connection, authenticate, and perform various operations using the API.
Setup
First, let's import the necessary libraries:
import xml.etree.ElementTree as ET
from zeep import Client, Settings
import pprint
pp = pprint.PrettyPrinter()
Configuration
Set up the connection parameters:
url = 'http://#CustomerID#.magayacloud.com:3691/CSSoapService?wsdl'
alias = 'http://#CustomerID#.magayacloud.com:3691/Invoke?Handler=CSSoapService'
user = '#Username#'
password = '#Password#'
access_key = ''
Configure the SOAP client:
settings = Settings(strict=False, xml_huge_tree=True)
client = Client(url, settings=settings)
Main Function
The getEntities
function is the core of this script. It performs various operations using the Magaya SOAP API:
def getEntities(service, access_key):
# Uncomment and modify these lines as needed for different API calls
# print(service.GetEntities(access_key, 0x00000000, "#StringValue#"))
# print(service.GetEntityContacts(access_key, 0x00000000, "#Hexvalue#"))
# print(service.GetTransactionsByBillingClient(access_key, "#Hexvalue#", "#", "2020-01-01", "2021-02-07", 0x00000001))
# print(service.GetChargeDefinitions(access_key))
# print(service.GetTransRangeByDate(access_key, "SH", "2021-02-01T00:00:00", "2021-02-16T23:00:00", 0x00000001))
# print(service.QueryLog(access_key, "2020-11-01T10:00:00", "2021-01-31T10:00:00", 0x01, "#", 0x01))
print(service.GetTransaction(access_key, "#", 0x00000001, "#"))
# Add more API calls as needed
Main Execution
The main execution block establishes a connection, starts a session, and calls the getEntities
function:
try:
service = client.create_service(
"{urn:CSSoapService}CSSoapServiceSoap",
alias
)
key = service.StartSession(user, password)
access_key = key['access_key']
getEntities(service, access_key)
# Uncomment the following line to get active currencies
# print(service.GetActiveCurrencies(access_key))
except Exception as e:
print(str(e))
Notes
- This script is set up to interact with the Magaya SOAP API, which is used for various logistics and supply chain management operations.
- The script includes several commented-ou