magento-python是一个使用Python写的Magento2 API SDK
pip install magento-python
from magento.client import Client
client = Client('SERVER_URL', 'ACCESS_TOKEN') # Host must have trailing slash
All
response = client.search_product({'searchCriteria': '[]'})
按created_at排序, 并只返回一条数据
response = client.search_product({'searchCriteria[sortOrders][0][field]': 'created_at', 'searchCriteria[pageSize]': '1'})
Filter by created_date greater than 2018-02-26 15:31:09, up to 100 items
response = client.search_product({'searchCriteria[filter_groups][0][filters][0][field]': 'created_at', 'searchCriteria[filter_groups][0][filters][0][value]': '2018-02-26 15:31:09', 'searchCriteria[filter_groups][0][filters][0][condition_type]': 'gt', 'searchCriteria[pageSize]': '100'})
data = {
"product": {
"name": 'Perfume Antonio Banderas',
"sku": 'PAB',
'type_id': 'simple',
'attribute_set_id': '4',
'price': '100000'
}
}
response = client.create_product(data)
By SKU
response = client.get_product('SKU')
By SKU
response = client.delete_product('SKU')
All
response = client.search_customer({'searchCriteria': ''})
data = {
"customer": {
"email": "janedoe@jd.com",
"firstname": "Jane",
"lastname": "Doe",
"addresses": [{
"defaultShipping": True,
"defaultBilling": True,
"firstname": "Jane",
"lastname": "Doe",
"region": {
"regionCode": "NY",
"region": "New York",
"regionId": 43
},
"postcode": "10755",
"street": ["123 Oak Ave"],
"city": "Purchase",
"telephone": "512-555-1111",
"countryId": "US"
}]
},
"password": "Password1"
}
response = client.create_customer(data)
By ID
response = client.get_customer('CUSTOMER_ID')
By ID
response = client.delete_customer('CUSTOMER_ID')
All
response = client.search_order({'searchCriteria': ''})
By ID
response = client.get_order('ORDER_ID')
All
response = client.get_product_types({'searchCriteria': ''})
All
response = client.get_product_attribute_sets({'searchCriteria': ''})
All
response = client.get_customer_groups({'searchCriteria': ''})
We are always grateful for any kind of contribution including but not limited to bug reports, code enhancements, bug fixes, and even functionality suggestions.
You can report any bug you find or suggest new functionality with a new issue.
- Fork it ( https://github.com/GearPlug/magento-python )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Adds my new feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request