The use of OTAPI methods in the documentation is described for OT Box and mobile application for it as an example.
OTAPI methods can be used and varied in the operation of any sites on various CMS.
All methods are available on documentation page: http://docs.otapi.net/en.
Send GET/POST request to http://otapi.net/service/ to get response from api in xml format.
Send GET/POST request to http://otapi.net/service-json/ to get response from api in json format.
Add method name and parameters in GET/POST form to the address depending on query and its size. Some parameters may nootherwiset fit in GET query, so it is always easier to make POST.
The ErrorCode node necessarily comes in the response from api, if it is not equal to 'Ok' and not equal to 'BatchError' - it is necessary to process the error. Errors must be separated by value in the ErrorCode and / or SubErrorCode nodes.
Some ErrorCode that can be processed globally at the application level:
In some cases, the error message must be shown to the user. It is stored in the Errordescription node and comes with the translation for the language specified when querying in the 'language' parameter.
You need to get application settings when you start it: http://docs.otapi.net/en/Documentations/Method?name=GetCommonInstanceOptionsInfo with parameter applicationType=MobileApplication/Android or applicationType=MobileApplication/iOS depends on system.
Application should get a list of available languages from the settings and provide user with an interface to choose application language (if there is more than one language in the list). Further queries to api are called with this language. When starting, the application should take the first language from the list in the settings, check user session (anonymous or authorized) with this language and get application language from the user’s preferences (for more details see working with the user block).
It is also necessary to request a list of translations for application interface at the start: http://docs.otapi.net/ru/Documentations/Method?name=GetApplicationUITranslations with language and parameter passing applicationType=MobileApplication/Android or applicationType=MobileApplication/iOS depends on system.
The list of successfully received settings must be cached. It is worth clearing settings cache in the background without slowing down application’s operation with this request. It’s worth clearing cache in background either every N hours or every time the application starts. Settings are the same for the entire application and do not differ for different users.
The first time mobile application starts, it must ask user for permission to receive push notifications. It is necessary to send application push token to the services http://docs.otapi.net/ru/Documentations/Method?name=SetUserPushNotificationToken if the user agreed to receive push notifications. Application should monitor relevance of the push token and update it if necessary in the future.
Some otapi methods require customer's session parameter. It's necessary to get a session before working with logic for users. Initially, you need to get an anonymous session using http://docs.dev.otapi.net/en/Documentations/Method?name=GetAnonymousSession method so that the shopping cart, preferences (for example) and so on could be saved on it. All data will be automatically transferred if the previous anonymous session was transferred during authorization. Obtained session must be saved in the application memory and used later for all requests.
Any method using user session may return SessionExpired error, which means that session has expired. In this case you need to transfer user to authorization with the corresponding message, and return user to the place where the error occurred when new session is successfully received.
The easiest way to force session verification by http://docs.otapi.net/en/Documentations/Method?name=GetUserStatusInfo method. It is the least time consuming.
User registration is carried out by http://docs.otapi.net/en/Documentations/Method?name=RegisterUser method
Check input data before calling this method:
Additional obligatory flag field "I accept the user agreement" should be in the registration form. Registration without this flag is not allowed.
Check Result-> IsEmailVerificationUsed field in the response after successful registration using RegisterUser method. Show message to user "An email was sent to your mail with a link to activation to activate account" if IsEmailVerificationUsed = "true". You need to authorize user immediately (set a new SessionId for him received in response to services) if IsEmailVerificationUsed = "false".
Together with the message that email was sent, you need to display input field for activation code. You should call http://docs.otapi.net/en/Documentations/Method?name=ConfirmEmail when user checks email and enters the code in the application. There is a field Result->SessionId->Value in response ConfirmEmail which contains authorized user session. Based on this session, you must immediately authorize user in the application.
Users' authorization is carried out by http://docs.otapi.net/en/Documentations/Method?name=Authenticate method.
Authorization form should contain the following fields: login (userLogin), password (userPassword) and remember me flag (rememberMe). Check input data before calling Authenticate method:
sessionId parameter in Authenticate method is the session identifier of an unauthorized customer.
Login as well as user's email can be transferred as userLogin. Probably it is worthwhile to somehow suggest this in the interface.
Social Networks Authorization (OT API)
Get the list of available social networks in settings from GetCommonInstanceOptionsInfo depending on current language, since for example admin can leave VKontakte for Russian and remove for English. Check in TranslatableOptions->choice by language->ExternalAuthentications.
Password recovery is done by http://docs.otapi.net/en/Documentations/Method?name=RequestPasswordRecovery method.
Field userIdentifier may contain user login or email. After calling RequestPasswordRecovery, show user the message "Further instructions were sent to your email" and display a form with confirmation code and two text fields for entering the password. User checks code in the email, returns to the application, enters the code and new password. If both fields with password match, then you need to call http://docs.otapi.net/en/Documentations/Method?name=ConfirmNewPassword. ConfirmNewPassword response has Result-> SessionId-> Value field that contains an authorized user session. Based on this session, you need to authorize user in the application immediately.
Social networks authorization
Use http://docs.otapi.net/en/Documentations/Method?name=BatchSearchRatingLists method to get collections. We pass the following parameters at the first request:
<BatchRatingListSearchParameters><UseDefaultParameters>true</UseDefaultParameters></BatchRatingListSearchParameters> |
and parameter applicationType=MobileApplication/Android or applicationType=MobileApplication/iOS depends on system. Received data for each collection has a serial number for sorting <Order> 0 </Order>, you need to display collections on the application screen according to this sorting. It is recommended to show collections only from cache. Collections in cache must be updated in background: every 60 minutes, request BatchSearchRatingLists method and save result in the cache. When receiving a response, you need to check HasTranslateErrors node (http://docs.dev.otapi.net/en/Documentations/Type?name=BatchRatingListsSearchResultAnswer), if the node is "true", then you do not need to cache the response. You must check HasError node (http://docs.dev.otapi.net/en/Documentations/Type?name=RatingListSearchResult) for each RatingList element in the response, if the node is true, then this collection item does not need to be cached.
Thus, we get a situation when buyer sees collections from cache. At the same time, collections in the cache have no errors. Situation is possible when we show user outdated information, while we are sure that this information is error-free.
Open "Demonstration MetaUI" plugin:
Choose "Banner settings" in dropdown list and press "Open" button:
Fill in the data and add website (website is required):
After that follow next steps:
You can get a full list of banners configured for application by http://docs.otapi.net/en/Documentations/Method/GetBanners method, passing parameter applicationType=WebSite (applicationType=MobileApplication/Android or applicationType=MobileApplication/iOS depends on system), instanceKey and language. Send request and get the link:
Each banner will have its name, image address, type of action, and action parameter. The current types of actions and the meaning of their parameters are listed below.
The current types of actions and their parameters purpose are listed below:
Action type | Parameter |
---|---|
Url | Absolute address of the link to open when you click banner |
Category | ID of the category that should be opened when clicking the banner |
TODO:
TODO:
Customer may have a number of preferences-settings on which otapi answers or behavior of the system / application depend on in the future.
You can get currently selected preferences using http://docs.otapi.net/en/Documentations/Method?name=GetUserPreferences method.
User preference can be changed using http://docs.otapi.net/en/Documentations/Method?name=UpdateUserPreferences method.
Application interface should allow users to change their preferences.
Send a request first: http://docs.otapi.net/en/Documentations/Method?name=GetRootCategoryInfoList - we get a list of website root categories. This list can be cached for 24 hours. Then make a separate request for attempt to expand each category - http://docs.otapi.net/en/Documentations/Method?name=GetCategorySubcategoryInfoList. Each list can be also cached for 24 hours using parent category identifier in the key.
category contains other categories (that is it can be expanded) if the flag <IsParent> true </IsParent> has come for it.
Don't show category in catalog if it is hidden <IsHidden>true</IsHidden>.
Flag <IsVirtual>true</IsVirtual> means that category doesn't contain goods (only other subcategories).
Absolute image address for category can be returned (image is set by administrator in admin panel) in the optional <IconImageUrl> node http://open-demo.otcommerce.com/uploaded/category/zh_odezhda.jpg </IconImageUrl>.
http://docs.otapi.net/en/Documentations/Method?name=BatchSearchRatingLists method, xmlSearchParameters=
<
BatchRatingListSearchParameters
><
RatingLists
><
RatingList
><
CategoryId
>0</
CategoryId
><
ItemRatingType
>Best</
ItemRatingType
><
IsRandomSearch
>false</
IsRandomSearch
><
ContentType
>Vendor</
ContentType
><
FramePosition
>0</
FramePosition
><
FrameSize
>20</
FrameSize
></
RatingList
></
RatingLists
></
BatchRatingListSearchParameters
>
FrameSize - number of vendors on the page, TotalCount will be returned in the response - the total number of recommended vendors. You can draw pagination based on TotalCount and FrameSize.
http://docs.otapi.net/en/Documentations/Method?name=BatchSearchRatingLists method, xmlSearchParameters=
<
BatchRatingListSearchParameters
><
RatingLists
><
RatingList
><
CategoryId
>0</
CategoryId
><
ItemRatingType
>Best</
ItemRatingType
><
IsRandomSearch
>false</
IsRandomSearch
><
ContentType
>Brand</
ContentType
><
FramePosition
>0</
FramePosition
><
FrameSize
>20</
FrameSize
></
RatingList
></
RatingLists
></
BatchRatingListSearchParameters
>
FrameSize - number of brands on the page, TotalCount will be returned in the response - the total number of recommended brands. You can draw pagination based on TotalCount and FrameSize.
The following properties should be used on recommended vendors page, in product card in vendor's block, for viewing all goods of vendor and for displaying information about the vendor:
Property | Description | Where to show | Comments |
---|---|---|---|
DisplayName | vendor name | everywhere | Thanks to this, website admin will be able to change names later, but nothing will change in Mobile Application logic. |
DisplayPictureUrl | vendor image | everywhere | Only if available, otherwise there is an image stub in recommended vendors, do not display in other places. Thanks to this, website admin will be able to change images but nothing will change in Mobile Application logic.
|
Credit/Level | vendor rating from 1 to 20 | in product card | Only if available and more than 0, otherwise it does not need to be displayed. |
Credit/TotalFeedbacks | number of feedbacks | in product card on vendor's page | Only if available and more than 0, otherwise it does not need to be displayed. |
Credit/PositiveFeedbacks | number of positive feedbacks | in product card on vendor's page | Only if available and more than 0, otherwise it does not need to be displayed. Display as% of total reviews if available. |
Scores/DeliveryScore | delivery scrore from 1.0 to 5.0 | in product card on vendor's page | Only if available and more than 0, otherwise it does not need to be displayed. |
Scores/ItemScore | item score from 1.0 to 5.0 | in product card on vendor's page | Only if available and more than 0, otherwise it does not need to be displayed. |
Scores/ServiceScore | service score from 1.0 to 5.0 | in product card on vendor's page | Only if available and more than 0, otherwise it does not need to be displayed. |
Basic documentation on search.
Use only one convenient search method to search for goods: http://docs.otapi.net/en/Documentations/Method?name=BatchSearchItemsFrame
To open a category / seller / brand or search query for the first time, call BatchSearchItemsFrame method with the blockList parameter: SubCategories,HintCategories,Vendor,Brand,Category,RootPath,SearchProperties,AvailableSearchMethods. Send search parameters in xmlParameters (for example, category ID <CategoryId>otc-3</CategoryId> or search or search query <ItemTitle>dress</ItemTitle>). We recommend sending <UseOptimalFrameSize>true</UseOptimalFrameSize> with search parameters. This will allow to get optimal number of products per page for this request.
Display information received in the response.
AvailableSearchMethods node contains all search methods available for current query. Allow customer to change search method if there are more than one search methods.
Find detailed information about the current search method that the query is now made in Items node, using values from Provider and SearchMethod nodes (for example: <Provider> Taobao </Provider> <SearchMethod> Extended </SearchMethod>) in AvailableSearchMethods. Using this information we provide user with filters available on the current search page. The correspondence of fields from information about search method and search parameters can be found in basic documentation.
Show SubCategories (Subcategories), HintCategories (You may be interested) to user. Categories that match current search query (Specify category) come up in Items - Categories node. Show goods from Items - Items node. Check the flag IsSellAllowed = true and SellDisallowReason = "IsFiltered" for the product - then we show the stub for the product - product is not allowed for purchase. Show error: NotFound - product was deleted, NotAvailable - product is unavailable instead of product image if product ErrorCode is not equal to "OK". For all other error codes just show the word "Error".
It is a good practice to change display depending on which nodes are returned in response to BatchSearchItemsFrame request. If:
This approach will allow you to localize search logic and services will be responsible for page display logic.
Use http://docs.otapi.net/en/Documentations/Method?name=BatchGetSimplifiedItemFullInfo when you open the card for the first time, it's necessary to send the following parameters: RootPath,Vendor,MostPopularVendorItems16,Description
Show product card:
Show product price:
use http://docs.otapi.net/en/Documentations/Method?name=BatchGetSimplifiedItemConfigurationInfo method, it's necessary to send the following parameters: AdditionalPrices (the first request can be made with an empty xmlRequest)
<Request /> equal to <Request> <Current /> </Request> equal to <Request> <Current Quantity="1" /> </Request> |
<Request> <Current Quantity="5" /> </Request> Request to current options: <Request> <Current ConfigurationId="idconfiguration" /> </Request> or <Request> <Current ConfigurationId="idconfiguration" Quantity="5" /> </Request> or <Request> <Current> <Property Id="idcolor" ValueId="idRed" </Current> </Request> or <Request> <Current> <Property Id="idcolor" ValueId="idRed" <Property Id="idSize" ValueId="idMiddle" </Current> </Request> or <Request> <Current Quantity="5"> <Property Id="colorid" ValueId="idRed" <Property Id="idSize" ValueId="idMiddle" <Property Id="idModel" ValueId="idSomeModel" </Current> </Request> |
<Request> <Selected ConfigurationId="idConfiguration" Quantity="1" /> <Selected ConfigurationId="idConfiguration" Quantity="2" /> ... </Request> or <Request> <Selected Quantity="1"> <Property Id="idColor" ValueId="idRed" <Property Id="idSize" ValueId="idMiddle" </Selected> <Selected Quantity="2"> <Property Id="idColor" ValueId="idGreen" <Property Id="idSize" ValueId="idMiddle" </Selected> ... </Request> A query with everything together can be any combination of other types of queries, for example: <Request> <Current Quantity="5"> <Property Id="idColor" ValueId="idRed" </Current> <Selected Quantity="2"> <Property Id="idColor" ValueId="idGreen" <Property Id="idSize" ValueId="idMiddle" </Selected> </Request> |
What's Current/Selected - and what's correct? Current or Selected?
If you need only 1 simultaneously selected config, then you can not think about Selected at all.
If you need several (as in 1688), then in Selected send everything where the quantity is entered.
Get list of items: http://docs.otapi.net/en/Documentations/Method?name=BatchGetUserData , blockList=Note.
Add item to favorites: http://docs.otapi.net/en/Documentations/Method?name=AddItemToNote , fieldParameters=<Fields/>
Remove item from favorites: http://docs.otapi.net/en/Documentations/Method?name=RemoveItemFromNote , confirmation to delete is required before removing.
Move item into cart: http://docs.otapi.net/en/Documentations/Method?name=MoveItemFromNoteToBasket
Change item quantity in favorites: http://docs.otapi.net/en/Documentations/Method?name=EditNoteItemQuantity
Change comment: http://docs.otapi.net/en/Documentations/Method?name=EditNoteItemFields , <Fields><FieldInfo Name="Comment" Value="Text for comment"/></Fields>
Change item configuration:
1. you can get available configurations by the following methods http://docs.otapi.net/en/Documentations/Method?name=BatchGetSimplifiedItemFullInfo and http://docs.otapi.net/en/Documentations/Method?name=BatchGetSimplifiedItemConfigurationInfo - similar to item card.
2. new configuration is saved by adding a new one and deleting the old one, i.e. consecutive calls http://docs.otapi.net/en/Documentations/Method?name=AddItemToNote (it is important to pass all fieldParameters from the old record into the method, otherwise you may lose some of information, for example, user’s comment on a product) and http://docs.otapi.net/en/Documentations/Method?name=RemoveItemFromNote
Vendors list: http://docs.otapi.net/en/Documentations/Method?name=BatchGetUserData , blockList=FavoriteVendors
Add vendor to favorites: http://docs.otapi.net/en/Documentations/Method?name=AddVendorToFavorites , fieldParameters=<Fields/>
Remove vendor from favorites: http://docs.otapi.net/en/Documentations/Method?name=RemoveVendorFromFavorites , confirmation to delete is required before removing.
Get list of items: http://docs.otapi.net/en/Documentations/Method?name=BatchGetUserData , blockList=Basket.
The list of goods should be divided by providers, as you can order goods of only one provider in one order. User should be notified about minimum order amount (if it is set in configuration), you can get it using http://docs.otapi.net/en/Documentations/Method?name=GetCommonInstanceOptionsInfo method (Result->Order->MinOrderCost)
Remove item from cart: http://docs.otapi.net/en/Documentations/Method?name=RemoveItemFromBasket , confirmation to delete is required before removing.
Empty cart http://docs.otapi.net/en/Documentations/Method?name=ClearBasket , confirmation to delete is required before removing.
Move selected item from cart to favorites: http://docs.otapi.net/en/Documentations/Method?name=MoveItemFromCartToNote several calls are made to transfer several marked products MoveItemFromCartToNote
Change quantity of items in the cart: http://docs.otapi.net/en/Documentations/Method?name=EditBasketItemQuantity
Add/edit comment to item: http://docs.otapi.net/en/Documentations/Method?name=EditBasketItemFields <Fields><FieldInfo Name="Comment" Value="Comment text"/></Fields>
Edit item weight: http://docs.otapi.net/en/Documentations/Method?name=EditBasketItemFields <Fields><FieldInfo Name="Weight" Value="New weight of an item"/></Fields>
Edit item configuration:
1. you can get available configurations by http://docs.otapi.net/en/Documentations/Method?name=BatchGetSimplifiedItemFullInfo and http://docs.otapi.net/en/Documentations/Method?name=BatchGetSimplifiedItemConfigurationInfo methods - similar to item card.
2. new configuration is saved by adding a new one and deleting the old one, i.e. consecutive calls http://docs.otapi.net/en/Documentations/Method?name=AddItemToBasket (it is important to pass all fieldParameters from the old record into the method, otherwise you may lose some of information, for example, user’s comment on a product) and http://docs.otapi.net/en/Documentations/Method?name=RemoveItemFromBasket
Get basic information about user (name, email, etc.): http://docs.otapi.net/en/Documentations/Method?name=GetUserInfo , you can edit this information with http://docs.otapi.net/en/Documentations/Method?name=UpdateUser method.
Delivery address. Delivery address is created and edited separately from basic information about the user. N delivery addresses are possible in total where N is taken from the setting http://docs.otapi.net/en/Documentations/Method?name=GetCommonInstanceOptionsInfo UserProfile->MaxProfilesCount. Methods for working with delivery address:
Interface is required for user that allows to select default profile https://www.screencast.com/t/1fZ9HuauBjf . Selected profile must be saved in user preferences: http://docs.otapi.net/en/Documentations/Method?name=UpdateUserPreferences , ProfileId field.
Get a list of content pages for profile screen: http://docs.otapi.net/en/Documentations/Method?name=GetContentMenuItemTree , parameters:
applicationType=MobileApplication/Android or applicationType=MobileApplication/iOS depends on system
menuList=Profile
includeContent=true
Get list of countries for delivery: http://docs.otapi.net/en/Documentations/Method?name=GetDeliveryCountryInfoList .
Get list of cities: http://docs.otapi.net/en/Documentations/Method?name=SearchCities (while user enters characters to search for the city, i.e. QueryText parameter is empty, you need to send IsMainCity = true to get a list of default cities). When user selects city from the list, save it in the City profile and CityCode profile and automatically fill in the Region field.
Important: CountryCode - obligatory field for placing an order, CityCode - optional field, system must transfer the code to the services if user selected a city from the list. Save only City node if user entered city that is not in SearchCities list.
http://docs.otapi.net/en/Documentations/Method?name=SearchOrdersForUser
Active: <OrderSearchParametersForUser><IsCancelled>false</IsCancelled><IsCompleted>false</IsCompleted></OrderSearchParametersForUser>
Cancelled: <OrderSearchParametersForUser><IsCancelled>true</IsCancelled></OrderSearchParametersForUser>
Completed: <OrderSearchParametersForUser><IsCompleted>true</IsCompleted></OrderSearchParametersForUser>
The list of fields to display:
Get order information: http://docs.otapi.net/en/Documentations/Method?name=GetSalesOrderDetails
Display order information for user (OrderInfo node, details here http://docs.otapi.net/en/Documentations/Type?name=OtapiOrderInfo), properties:
Display goods list in the order (SalesLinesList node, details about each line is here http://docs.otapi.net/en/Documentations/Type?name=SalesLine)
Shippings list - http://docs.otapi.net/en/Documentations/Method?name=GetSalesOrderShippings
You can place goods of only one provider into one order.
When placing an order, you will need a form for choosing delivery address or, if an address was previously created, a form for creating delivery address / s (delivery profile documentation anchor).
When placing an order, you will need to select a delivery method from provided list: http://docs.otapi.net/en/Documentations/Method?name=SearchDeliveryModes request, xmlSearchParameters parameters:
Parameters example: <DeliveryModeSearchParameters><CountryCode>RU</CountryCode><CityCode>7700000000000</CityCode><Weight>75.000</Weight><ProviderType>Taobao</ProviderType></DeliveryModeSearchParameters>.
IsPickupPointMode flag must be considered when displaying delivery methods.
Save ExternalDeliveryId to user preferences after successful order (http://docs.otapi.net/en/Documentations/Method?name=UpdateUserPreferences) as well as update delivery address parameters, if the interface has not done it immediately (http://docs.otapi.net/en/Documentations/Method?name=UpdateUserProfile).
"check" relevance of prices and possibility to buy before placing an order from the cart:
It is important to start cart checking again each time customer changes selected products, as well as re-display error / success messages from the services.
You can place an order "from the cart" calling http://docs.otapi.net/en/Documentations/Method?name=CreateOrder method, passing:
Allow customer to make a follow-up order (if customer has such an opportunity) when making an order. Get orders that allow to make a follow-up order, call http://docs.otapi.net/en/Documentations/Method?name=SearchOrdersForUser with parameters xmlSearchParameters= <OrderSearchParametersForUser><ProviderType>IDProvider(for example, Taobao)</ProviderType><IsAvailableForRecreation>true</IsAvailableForRecreation></OrderSearchParametersForUser>. Allow customer to choose if he makes a new order or a follow-up order if there are such orders. Call http://docs.otapi.net/en/Documentations/Method?name=RecreateOrder method for follow-up order.
It is possible to make an order from item card by "Quick order" button. Call http://docs.otapi.net/en/Documentations/Method?name=AddOrder method sending:
If the order is not paid, be sure to offer customer to pay it. Call http://docs.otapi.net/en/Documentations/Method?name=GetAccountInfo method if there are funds in customer's personal account, AvailableAmount node (definitely use CurrencySign for display), offer customer a button that will pay for the order from personal account. Write available payment amount on the button, this should be RemainAmount from order information http://docs.otapi.net/en/Documentations/Method?name=GetSalesOrderDetails (provided that personal account has more than RemainAmount) or AvailableAmount (provided that personal account is less than RemainAmount).
Call http://docs.otapi.net/en/Documentations/Method?name=PaymentPersonalAccount method when clicking the button and refresh order page.
Order can be paid through payment systems. Request a list of available payment systems: http://docs.otapi.net/en/Documentations/Method?name=GetPaymentModes . Image of PS - AbsoluteImageUrl, name of PS - Name. Display "Pay" button after clicking payment system and display email input field if CustomField node == "Email", display phone number input field if CustomField node == "Phone".
Call http://docs.otapi.net/en/Documentations/Method?name=GetPaymentParameters after clicking "Pay" button. Pass the following parameters: Amount (RemainAmount from order information), CurrencyCode, PaymentSystemId, OrderId, SuccessUrl and FailUrl return addresses that application can intercept.
Form http-form based on received response, open it in browser and submit it:
Customer’s personal account will be replenished by Amount if you don't pass OrderId into GetPaymentParameters method.
Browser will return to one of the transmitted addresses after successful or unsuccessful payment, accordingly application should intercept them, close browser and show appropriate screen.