Difference between revisions of "MOR API tariff retail import"

From Kolmisoft Wiki
Jump to navigationJump to search
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
=Description=
<!---This functionality is available from MOR 11 --->
<!---This functionality is available from MOR 11 --->
[[MOR API]] Import XML Retail tariff
[[MOR API]] Import XML Retail tariff
<br><br>
<br><br>
----
=Usage=
<br><br>


* Call: /api/import_tariff_retail
* From '''MOR X4''' call: '''/api/tariff_retail_import'''
* For Backwards-compatibility old name 'import_tariff_retail' is also usable. Call: '''/api/import_tariff_retail'''
* Methods: POST
* Methods: POST
* Params:
===Parametres===
** u - username to login. '''Required'''.
** p - password to login. '''Required'''.
** xml - retail tariff in xml format. '''Required'''.
**
* Returns response in xml:
**Success:
<response>
  <tariff_id> ID </tariff_id>
  <tariff_name> TARIFF NAME </tariff_name>
  <bad_destinations></bad_destinations>
  <destination_with_bad_rates></destination_with_bad_rates>
  <destination_with_time_collisions_in_xml></destination_with_time_collisions_in_xml>
  <destination_with_time_collisions_in_db></destination_with_time_collisions_in_db>
</response>
 
***
** Errors:
* if bad xml format:
<response>
  <error> File does not exist </error>
</response>
or 
<response>
  <error> Bad XML data </error>
</response> 
                     
* if tariff name does not match with existing tariff found by ID:
<response>
  <error> TARIFF NAME WITH THIS ID DO NOT MATCH !!!FOUND tariff_name </error>
</response>


* if tariff was not found by ID, but tariff with same name exists:
* [[MOR API hash construction | hash]] - SHA1 hash constructed using parameters above and API_Secret_Key ([[MOR API hash construction | More described in Constructing hash]]). '''Required'''.
<response>
* u - username for authorization. '''Required'''.
  <error> TARIFF with same name exists, ID:tariff_id!!! CHANGE NAME OR ID </error>
* xml - retail tariff in xml format. '''Required'''.
</response>
 
* if trying to update not yours tariff:
<response>
  <error>Tariff belongs to other user!</error>
</response>
 
 
* if no destinations found in xml:
<response>
  <error> No destinations! </error>
  <tariff_id> ID </tariff_id>
  <tariff_name> TARIFF NAME </tariff_name>
</response>
 
* if no destination found by destination name or bad destination name:
<response>
  <tariff_id> ID </tariff_id>
  <tariff_name> TARIFF NAME </tariff_name>
  <bad_destinations>
  <destination_group_name> DESTINATION GROUP NAME </destination_group_name>
  <destination_group_type> DESTINATION GROUP TYPE </destination_group_type>
  </bad_destinations>
  <destination_with_bad_rates></destination_with_bad_rates>
  <destination_with_time_collisions_in_xml></destination_with_time_collisions_in_xml>
  <destination_with_time_collisions_in_db></destination_with_time_collisions_in_db>
</response>
 
* if you try to import 'Work Day and Free Day' rate only to 'Work Day' or only to 'Free Day' and vice versa
 
 
<response>
  <tariff_id> ID </tariff_id>
  <tariff_name> TARIFF NAME </tariff_name>
  <bad_destinations></bad_destinations>
  <destination_with_day_type_collision>
  <destination_group_name> DESTINATION GROUP NAME </destination_group_name>
  <destination_group_type> DESTINATION GROUP TYPE </destination_group_type>
  </destination_with_day_type_collision
  <destination_with_bad_rates></destination_with_bad_rates>
  <destination_with_time_collisions_in_xml></destination_with_time_collisions_in_xml>
  <destination_with_time_collisions_in_db></destination_with_time_collisions_in_db>
</response>
 
* if bad rate in destination:
<response>
  <tariff_id> ID </tariff_id>
  <tariff_name> TARIFF NAME </tariff_name>
  <bad_destinations></bad_destinations>
  <destination_with_bad_rates>
  <destination_group_name> DESTINATION GROUP NAME </destination_group_name>
  <destination_group_type> DESTINATION GROUP TYPE </destination_group_type>
  <rate_price> 1 </rate_price>
  <rate_round_by> 588888 </rate_round_by>
  <rate_duration> 7 </rate_duration>
  <rate_type> minute </rate_type>
  <rate_start_time> 00:00:00 </rate_start_time>
  <rate_end_time> 23:99:99 </rate_end_time>
  <day_type/>
  </destination_with_bad_rates>
</response>
 
* if time collision in xml destination rates:
<response>
  <tariff_id> ID </tariff_id>
  <tariff_name> TARIFF NAME </tariff_name>
  <bad_destinations></bad_destinations>
  <destination_with_bad_rates></destination_with_bad_rates>
  <destination_with_time_collisions_in_xml>
  <collision_in_time_range>
    Destination group name Destination group type COLLISION IN rate start AND rate end TIME RANGE
  </collision_in_time_range>
  </destination_with_time_collisions_in_xml>
  <destination_with_time_collisions_in_db></destination_with_time_collisions_in_db>
</response>
 
* if time collision between xml rates and existing rates:
<response>
  <tariff_id> ID </tariff_id>
  <tariff_name> TARIFF NAME </tariff_name>
  <bad_destinations></bad_destinations>
  <destination_with_bad_rates></destination_with_bad_rates>
  <destination_with_time_collisions_in_xml></destination_with_time_collisions_in_xml>
  <destination_with_time_collisions_in_db>
  <collision_in_time_range>
    Destination group name Destination group type COLLISION WITH EXISTING RATES IN rate start AND rate end TIME RANGE
  </collision_in_time_range>
  </destination_with_time_collisions_in_db>
</response>


<br><br>
===Request===
----
<br><br>


XML structure example
XML structure example
Line 210: Line 89:
  </tariff>
  </tariff>


===Returns===


----
'''Success'''
*Example :


By sending such XML you get the following result shown in an image below:
By sending such XML you get the following result shown in an image below:
Line 246: Line 126:
   </tariff>
   </tariff>


After you can check rates in GUI:
<br><br>
[[File:Xml_import.png]]
[[File:Xml_import.png]]
<br><br>
<br><br>
==See also==
----
 
'''Errors'''
 
* if bad xml format:
<response>
  <error> File does not exist </error>
</response>
or 
<response>
  <error> Bad XML data </error>
</response> 
                     
* if tariff name does not match with existing tariff found by ID:
<response>
  <error> TARIFF NAME WITH THIS ID DO NOT MATCH !!!FOUND tariff_name </error>
</response>
 
* if tariff was not found by ID, but tariff with same name exists:
<response>
  <error> TARIFF with same name exists, ID:tariff_id!!! CHANGE NAME OR ID </error>
</response>
 
* if trying to update not yours tariff:
<response>
  <error>Tariff belongs to other user!</error>
</response>
 
 
* if no destinations found in xml:
<response>
  <error> No destinations! </error>
  <tariff_id> ID </tariff_id>
  <tariff_name> TARIFF NAME </tariff_name>
</response>
 
* if no destination found by destination name or bad destination name:
<response>
  <tariff_id> ID </tariff_id>
  <tariff_name> TARIFF NAME </tariff_name>
  <bad_destinations>
  <destination_group_name> DESTINATION GROUP NAME </destination_group_name>
  <destination_group_type> DESTINATION GROUP TYPE </destination_group_type>
  </bad_destinations>
  <destination_with_bad_rates></destination_with_bad_rates>
  <destination_with_time_collisions_in_xml></destination_with_time_collisions_in_xml>
  <destination_with_time_collisions_in_db></destination_with_time_collisions_in_db>
</response>
 
* if you try to import 'Work Day and Free Day' rate only to 'Work Day' or only to 'Free Day' and vice versa
 
 
<response>
  <tariff_id> ID </tariff_id>
  <tariff_name> TARIFF NAME </tariff_name>
  <bad_destinations></bad_destinations>
  <destination_with_day_type_collision>
  <destination_group_name> DESTINATION GROUP NAME </destination_group_name>
  <destination_group_type> DESTINATION GROUP TYPE </destination_group_type>
  </destination_with_day_type_collision
  <destination_with_bad_rates></destination_with_bad_rates>
  <destination_with_time_collisions_in_xml></destination_with_time_collisions_in_xml>
  <destination_with_time_collisions_in_db></destination_with_time_collisions_in_db>
</response>
 
* if bad rate in destination:
<response>
  <tariff_id> ID </tariff_id>
  <tariff_name> TARIFF NAME </tariff_name>
  <bad_destinations></bad_destinations>
  <destination_with_bad_rates>
  <destination_group_name> DESTINATION GROUP NAME </destination_group_name>
  <destination_group_type> DESTINATION GROUP TYPE </destination_group_type>
  <rate_price> 1 </rate_price>
  <rate_round_by> 588888 </rate_round_by>
  <rate_duration> 7 </rate_duration>
  <rate_type> minute </rate_type>
  <rate_start_time> 00:00:00 </rate_start_time>
  <rate_end_time> 23:99:99 </rate_end_time>
  <day_type/>
  </destination_with_bad_rates>
</response>
 
* if time collision in xml destination rates:
<response>
  <tariff_id> ID </tariff_id>
  <tariff_name> TARIFF NAME </tariff_name>
  <bad_destinations></bad_destinations>
  <destination_with_bad_rates></destination_with_bad_rates>
  <destination_with_time_collisions_in_xml>
  <collision_in_time_range>
    Destination group name Destination group type COLLISION IN rate start AND rate end TIME RANGE
  </collision_in_time_range>
  </destination_with_time_collisions_in_xml>
  <destination_with_time_collisions_in_db></destination_with_time_collisions_in_db>
</response>
 
* if time collision between xml rates and existing rates:
<response>
  <tariff_id> ID </tariff_id>
  <tariff_name> TARIFF NAME </tariff_name>
  <bad_destinations></bad_destinations>
  <destination_with_bad_rates></destination_with_bad_rates>
  <destination_with_time_collisions_in_xml></destination_with_time_collisions_in_xml>
  <destination_with_time_collisions_in_db>
  <collision_in_time_range>
    Destination group name Destination group type COLLISION WITH EXISTING RATES IN rate start AND rate end TIME RANGE
  </collision_in_time_range>
  </destination_with_time_collisions_in_db>
</response>
 
<br><br>
 
=See also=


You can always check your XML by using XML validators like http://www.xmlvalidation.com/
* [[MOR API]]
* You can always check your XML by using XML validators like http://www.xmlvalidation.com/
<br><br>
<br><br>

Latest revision as of 08:17, 18 October 2021

Description

MOR API Import XML Retail tariff

Usage

  • From MOR X4 call: /api/tariff_retail_import
  • For Backwards-compatibility old name 'import_tariff_retail' is also usable. Call: /api/import_tariff_retail
  • Methods: POST

Parametres

  • hash - SHA1 hash constructed using parameters above and API_Secret_Key ( More described in Constructing hash). Required.
  • u - username for authorization. Required.
  • xml - retail tariff in xml format. Required.

Request

XML structure example

<tariff>
 <name>Tariff</name>
 <id>2</id>
 <destinations>
  <destination>
   <direction/>
   <destination_group_name>Afghanistan</destination_group_name>
   <destination_group_type>FIX</destination_group_type>
   <rates>
    <rate_price>0.02</rate_price>
    <rate_round_by>1</rate_round_by>
    <rate_type>minute</rate_type>
    <rate_start_time>00:00:00</rate_start_time>
    <rate_end_time>21:59:59</rate_end_time>
    <rate_duration>300</rate_duration>
    <day_type>WD</day_type>
   </rates>
   <rates>
    <rate_price>0.1</rate_price>
    <rate_round_by>1</rate_round_by>
    <rate_type>event</rate_type>
    <rate_start_time>08:00:00</rate_start_time>
    <rate_end_time>17:59:59</rate_end_time>
    <rate_duration>0</rate_duration>
    <day_type>FD</day_type>
   </rates>
   <rates>
    <rate_price>0.1</rate_price>
    <rate_round_by>61</rate_round_by>
    <rate_type>minute</rate_type>
    <rate_start_time>18:00:00</rate_start_time>
    <rate_end_time>23:59:59</rate_end_time>
    <rate_duration>-1</rate_duration>
    <day_type>FD</day_type>
   </rates>
   <rates>
    <rate_price>0</rate_price>
    <rate_round_by>1</rate_round_by>
    <rate_type>minute</rate_type>
    <rate_start_time>21:00:00</rate_start_time>
    <rate_end_time>23:59:59</rate_end_time>
    <rate_duration>-1</rate_duration>
    <day_type>WD</day_type>
   </rates>
  </destination>
  <destination>
   <direction/>
   <destination_group_name>Lithuania</destination_group_name>
   <destination_group_type>MOB</destination_group_type>
   <rates>
    <rate_price>0.2</rate_price>
    <rate_round_by>1</rate_round_by>
    <rate_type>minute</rate_type>
    <rate_start_time>00:00:00</rate_start_time>
    <rate_end_time>23:59:59</rate_end_time>
    <rate_duration>2</rate_duration>
    <day_type/>
   </rates>
   <rates>
    <rate_price>0.3</rate_price>
    <rate_round_by>1</rate_round_by>
    <rate_type>event</rate_type>
    <rate_start_time>00:00:00</rate_start_time>
    <rate_end_time>23:59:59</rate_end_time>
    <rate_duration>0</rate_duration>
    <day_type/>
   </rates>
  </destination>
 </destinations>
</tariff>


Returns

Success

By sending such XML you get the following result shown in an image below:

<tariff>
 <name>test_export_advanced2</name>
 <id>20</id>
 <destinations>
 <destination>
 <direction/>
 <destination_group_name>Afghanistan</destination_group_name>
 <destination_group_type>FIX</destination_group_type>
   <rates>
    <rate_price>0.25</rate_price>
    <rate_round_by>30</rate_round_by>
    <rate_type>minute</rate_type>
    <rate_start_time>00:00:00</rate_start_time>
    <rate_end_time>23:59:59</rate_end_time>
    <rate_duration>30</rate_duration>
    <day_type>WD</day_type>
   </rates>
   <rates>
    <rate_price>0.25</rate_price>
    <rate_round_by>6</rate_round_by>
    <rate_type>minute</rate_type>
    <rate_start_time>00:00:00</rate_start_time>
    <rate_end_time>23:59:59</rate_end_time>
    <rate_duration>-1</rate_duration>
    <day_type>WD</day_type>
   </rates>
 </destination>
 </destinations>
 </tariff>

After you can check rates in GUI:

Xml import.png


Errors

  • if bad xml format:
<response>
 <error> File does not exist </error>
</response> 

or

<response>
 <error> Bad XML data </error>
</response>   
                      
  • if tariff name does not match with existing tariff found by ID:
<response>
 <error> TARIFF NAME WITH THIS ID DO NOT MATCH !!!FOUND tariff_name </error>
</response>
  • if tariff was not found by ID, but tariff with same name exists:
<response>
 <error> TARIFF with same name exists, ID:tariff_id!!! CHANGE NAME OR ID </error>
</response>
  • if trying to update not yours tariff:
<response>
 <error>Tariff belongs to other user!</error>
</response>


  • if no destinations found in xml:
<response>
 <error> No destinations! </error>
 <tariff_id> ID </tariff_id>
 <tariff_name> TARIFF NAME </tariff_name>
</response>
  • if no destination found by destination name or bad destination name:
<response>
 <tariff_id> ID </tariff_id>
 <tariff_name> TARIFF NAME </tariff_name>
 <bad_destinations>
  <destination_group_name> DESTINATION GROUP NAME </destination_group_name>
  <destination_group_type> DESTINATION GROUP TYPE </destination_group_type>
 </bad_destinations>
 <destination_with_bad_rates></destination_with_bad_rates>
 <destination_with_time_collisions_in_xml></destination_with_time_collisions_in_xml>
 <destination_with_time_collisions_in_db></destination_with_time_collisions_in_db>
</response>
  • if you try to import 'Work Day and Free Day' rate only to 'Work Day' or only to 'Free Day' and vice versa


<response>
 <tariff_id> ID </tariff_id>
 <tariff_name> TARIFF NAME </tariff_name>
 <bad_destinations></bad_destinations>
 <destination_with_day_type_collision>
  <destination_group_name> DESTINATION GROUP NAME </destination_group_name>
  <destination_group_type> DESTINATION GROUP TYPE </destination_group_type>
 </destination_with_day_type_collision
 <destination_with_bad_rates></destination_with_bad_rates>
 <destination_with_time_collisions_in_xml></destination_with_time_collisions_in_xml>
 <destination_with_time_collisions_in_db></destination_with_time_collisions_in_db>
</response>
  • if bad rate in destination:
<response>
 <tariff_id> ID </tariff_id>
 <tariff_name> TARIFF NAME </tariff_name>
 <bad_destinations></bad_destinations>
 <destination_with_bad_rates>
  <destination_group_name> DESTINATION GROUP NAME </destination_group_name>
  <destination_group_type> DESTINATION GROUP TYPE </destination_group_type>
  <rate_price> 1 </rate_price>
  <rate_round_by> 588888 </rate_round_by>
  <rate_duration> 7 </rate_duration>
  <rate_type> minute </rate_type>
  <rate_start_time> 00:00:00 </rate_start_time>
  <rate_end_time> 23:99:99 </rate_end_time>
  <day_type/>
 </destination_with_bad_rates>
</response>
  • if time collision in xml destination rates:
<response>
 <tariff_id> ID </tariff_id>
 <tariff_name> TARIFF NAME </tariff_name>
 <bad_destinations></bad_destinations>
 <destination_with_bad_rates></destination_with_bad_rates>
 <destination_with_time_collisions_in_xml>
  <collision_in_time_range> 
   Destination group name Destination group type COLLISION IN rate start AND rate end TIME RANGE 
  </collision_in_time_range>
 </destination_with_time_collisions_in_xml>
 <destination_with_time_collisions_in_db></destination_with_time_collisions_in_db>
</response>
  • if time collision between xml rates and existing rates:
<response>
 <tariff_id> ID </tariff_id>
 <tariff_name> TARIFF NAME </tariff_name>
 <bad_destinations></bad_destinations>
 <destination_with_bad_rates></destination_with_bad_rates>
 <destination_with_time_collisions_in_xml></destination_with_time_collisions_in_xml>
 <destination_with_time_collisions_in_db>
  <collision_in_time_range>
   Destination group name Destination group type COLLISION WITH EXISTING RATES IN rate start AND rate end TIME RANGE
  </collision_in_time_range>
 </destination_with_time_collisions_in_db>
</response>



See also