For using Cart API you should enable it previously, via admin part of you’re site.Go to System->Users->API and you’ll see a predefined user named “Default”.Edit it – and the are no API-key so generate it, by pressing the button and set “Status” to enable.Next, add you’r IP to list of permitted for API access on another tab.
API is avaliable via URL like
https://marketplace.shipcomet.com/yourstore/index.php?route=api/cart/add
where route is using choose appropriate controller.
Firstly, you can and definitly should get token for you session – you’ll get cookie file and Cart server will identify activity by this way.
import requests s = requests.Session() username = 'Default' key='L3MYyzlYMRL8gBcpCm6CdrVarFUXtPORZkJKP7vgaY8M8EIZWOr3EJxq' # Actually, key is 256 character-long s.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/login', data={'username':username, 'key':key} ).text
If everything was done right, you’ll get json-response with api_token for you’r session. Check site admin API page, edit API user and open “Sessions” tab – you can see established session.
Now, what you can do with Cart API?
Establishing session for API user by key PARAMS:DATA:username:username from oc_apikey:key from oc_apiEXAMPLE:
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/shipping/address', params={'api_token':'768ef1810185cd6562478f61d2'}, data={ 'username':username, 'key':key } )
DESCRIPTION:change session currencyPARAMS:api_tokenDATA:currency:code from table oc_currencyEXAMPLE:
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/currency', params={'api_token':'768ef1810185cd6562478f61d2'}, data={'currency':'USD'} )
DESCRIPTION:adding product to cartPARAMS:api_tokenDATA:product_id:product_id from table oc_cartquantity:quantity from table oc_cartoption:option array from table oc_cartEXAMPLE:
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/cart/add', params={'api_token':'768ef1810185cd6562478f61d2'}, data={ 'product_id':'100' 'quantuty':'1' } )
DESCRIPTION:edit product quantity in cartPARAMS:api_tokenDATA:key:cart_id from table oc_cartquantity:quantity from table oc_cartEXAMPLE:
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/cart/edit', params={'api_token':'768ef1810185cd6562478f61d2'}, data={ 'key':'10' 'quantuty':'2' } )
DESCRIPTION:removing product from cartPARAMS:api_tokenDATA:key:cart_id from table oc_cartEXAMPLE:
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/cart/remove', params={'api_token':'768ef1810185cd6562478f61d2'}, data={ 'key':'10' } )
DESCRIPTION:cart contentPARAMS:api_tokenDATA:EXAMPLE:
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/cart/products', params={'api_token':'768ef1810185cd6562478f61d2'}, data={} )
DESCRIPTION:apply existing couponPARAMS:api_tokenDATA:coupon:code from oc_coupon;EXAMPLE:
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/coupon', params={'api_token':'768ef1810185cd6562478f61d2'}, data={ 'coupon':'2222' } )
DESCRIPTION:set customer for current sessionPARAMS:api_tokenDATA:firstname:lastname:email:telephone:EXAMPLE:
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/customer', params={'api_token':'768ef1810185cd6562478f61d2'}, data={ 'firstname':'Dear', 'lastname':'Customer', 'email':'customer@example.com', 'telephone':'+1 879 2548022'} } )
DESCRIPTION:apply existing voucherPARAMS:api_tokenDATA:voucher:code from oc_voucher;EXAMPLE:
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/voucher', params={'api_token':'768ef1810185cd6562478f61d2'}, data={ 'voucher':'VOU-7271' } )
DESCRIPTION:add new voucher for current sessionPARAMS:api_tokenDATA:from_name:from_name from oc_voucherfrom_email:from_email from oc_voucherto_name:to_name from oc_voucherto_email:to_email from oc_voucheramount :amount from oc_voucher in selected currencycode :code from oc_voucherEXAMPLE:
session.post( 'https://marketplace.shipcomet.com//yourstore/index.php?route=api/voucher/add', params={'api_token':'768ef1810185cd6562478f61d2'}, data={ 'from_name':'MyCart Admin' 'from_email':'admin@example.com' 'to_name':'Dear Customer' 'to_email':'customer@example.com' 'amount':'100' 'code':'VOU-7177' } )
DESCRIPTIONIPTION:set shipping address for current sessionPARAMS:api_tokenDATA:firstnamelastnameaddress_1citycountry_idzone_idEXAMPLE:
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/shipping/address', params={'api_token':'768ef1810185cd6562478f61d2'}, data={ 'firstname':'Customer', 'lastname':'Dear', 'address_1':'Somewhere', 'city':'KLD', 'country_id':'RUS', 'zone_id':'KGD' } )
DESCRIPTION:returning avaliable shipping methodsPARAMS:api_tokenDATA:EXAMPLE:
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/shipping/methods', params={'api_token':'768ef1810185cd6562478f61d2'}, )
DESCRIPTION:set shipping method for current sessionPARAMS:api_tokenDATA:shipping_methodEXAMPLE:
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/shipping/method', params={'api_token':'768ef1810185cd6562478f61d2'}, data={ 'shipping_method':'pickup.pickup' } )
DESCRIPTION:PARAMS:api_tokenDATA:EXAMPLE:
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/reward', params={'api_token':'768ef1810185cd6562478f61d2'}, data={ } )
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/reward/maximum', params={'api_token':'768ef1810185cd6562478f61d2'}, data={ } )
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/reward/avaliable', params={'api_token':'768ef1810185cd6562478f61d2'}, data={ } )
DESCRIPTION:new order by cart content and payment/delivery information has beeen set by current sessionPARAMS:api_tokenDATA:EXAMPLE:
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/order/add', params={'api_token':'768ef1810185cd6562478f61d2'}, )
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/order/edit', params={'api_token':'768ef1810185cd6562478f61d2'}, data={ } )
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/order/delete', params={'api_token':'768ef1810185cd6562478f61d2'}, data={ } )
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/order/info', params={'api_token':'768ef1810185cd6562478f61d2'}, data={ } )
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/order/history', params={'api_token':'768ef1810185cd6562478f61d2'}, data={ } )
DESCRIPTION:set payment address for this sessionPARAMS:api_tokenDATA:firstnamelastnameaddress_1citycountry_idzone_idEXAMPLE:
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/payment/address', params={'api_token':'768ef1810185cd6562478f61d2'}, data={ 'firstname':'Customer', 'lastname':'Dear', 'address_1':'Somewhere', 'city':'KLD', 'country_id':'RUS', 'zone_id':'KGD' } )
DESCRIPTION:returning avaliable payment methodsPARAMS:api_tokenDATA:EXAMPLE:
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/payment/methods', params={'api_token':'768ef1810185cd6562478f61d2'}, )
DESCRIPTION:setting payment method of avaliable in api/payment/methodsPARAMS:api_tokenDATA:payment_methodEXAMPLE:
session.post( 'https://marketplace.shipcomet.com/yourstore/index.php?route=api/payment/method', params={'api_token':'768ef1810185cd6562478f61d2'}, data={ 'payment_method':'bank_transfer' } )