Overview

Материал из post-API.ru
Перейти к: навигация, поиск

OVERVIEW

These files contain a set of classes and functions for the development of online stores that sell in the Russian regions. With these classes, you can accomplish the following on Russian Post based:

   Find address (Region, Area, Autonom area, City) for input index
   Calculate the time of delivery of goods
   Calculate a cost of service for give payment for goods (CyberMoney tariffs)
   Calculate a delivery cost
   Find indexes by partial city name (case insensitive)

The present library don't require any database engines.

LIST OF API

The API is present by next interface files:

   http://post-api.ru/api/postdata.php
   http://post-api.ru/api/city2index.php
   http://post-api.ru/api/delivcost.php

The first file return address data by index and delivery time The second file return indexes by full or partial city name. The third file return a delivery cost of box with goods

The base encoding of input/output 'utf-8'. Input data will be POST or GET. Response will be json-array

USE postdata.php

QUERY

For use API need make a GET or POST next query:

http://post-api.ru/api/postdata.php?d=1&i=656056&m=1700&apikey=dev

where:

   d - debug. If set, script postdata.php echo a print_r of result work above json response
   i - index of russian post object
   m - the money amount for send via CyberMoney of Russian Post
   apikey - is key for identification of user. For developer it's can be "dev". In this case API limit by 656056 post index

RESPONSE

The response - is a json-array (in utf-8), included next mandatory fields:

   id - 3-chars in uppercase, need to identify type of array. Must be set in "ALL"
   api_ver - version of API
   executed_time - the time of script execute on server side in seconds
   status - "ok", if access granted, "forbidden" if access not granted

The next elements are optional, and depend from POST or GET input data

   ADR - the array with (Region, Area, Autonom area, City) elements. Present if "&i=" is set
   DUR - the array with duration of steps of delivery process. Present if "$i=" is set if DUR.postcenter == ADR.city, then use for total calc DUR.inarea value, else DUR.areatocity
   POP - the list of post sorted hubs. It's array is set for wrong index
   CYM - the array with CyberMoney service cost calculation. Present, if "&m=" is set

The each of optional information elements has a next mandatory fields

   id - 3-chars in uppercase, need to identify type of array (see above).
   status - if "error", then "content" element is empty. if "ok" - you can use this data in application
   content - an array with information data

TEST

For view output information you can use a test scripts with pre-installed test values:

   ADR: http://post-api.ru/api/test/post_addr_test.php
   DUR, POP: http://post-api.ru/api/test/post_duration_test.php
   CYM: http://post-api.ru/api/test/post_cybermoney_test.php

USE city2index.php

QUERY

For use API need make a GET or POST next query:

http://post-api.ru/api/city2index.php?d=1&city=%D1%81%D0%B0%D0%BD%D0%BA%D1%82&apikey=dev

where:

   d - debug. If set, script city2index.php echo a print_r of result work above json response
   city - partial city name (case insensitive)
   apikey - is key for identification of user. For developer it's can be "dev". In this case API limit by "санкт-петербург" city

RESPONSE

The response - is a json-array (in utf-8), included next mandatory fields:

   id - 3-chars in uppercase, need to identify type of array. Must be set in "IBC"
   api_ver - version of API
   executed_time - the time of script execute on server side in seconds
   status - "ok" - the citys was found, "empty" if result array is empty, "short" - input < 3 chars, "error" - internal error
   content - array of arrays in form: "Moscow" => "456789,345678,123456"

TEST

For view output information you can use a test scripts with pre-installed test values:

   IBC: http://post-api.ru/api/test/post_city2index_test.php

USE delivcost.php

QUERY

For use API need make a GET or POST next query:

http://post-api.ru/api/delivcost.php?d=1&apikey=dev&i=656056&c=2340&ac=15.70&we=800&w=300&h=120&de=300&in=1&war=0&a=0

where:

   d - debug. If set, script city2index.php echo a print_r of result work above json response
   apikey - is key for identification of user. For developer it's can be "dev". In this case API limit by "санкт-петербург" city
   i - index of russian post object
   c - the cost of items ordered
   ac - the addititonal cost (for example, a package cost)
   we - weight of goods (MUST BE with package weight, for correct delivery cost calculation) (gramms)
   w - width of box (mm)
   h - height of box (mm)
   de - depth of box (mm)
   in - if 1 - to need calculate a insurance cost
   war - if 1 - when calculate add cost for carefull use a box
   a - if 1 - when calculate with fly-delivery costs

RESPONSE

The response - is a json-array (in utf-8), included next mandatory fields:

   id - 3-chars in uppercase, need to identify type of array. Must be set in "IBC"
   api_ver - version of API
   executed_time - the time of script execute on server side in seconds
   date - the date of rates last update
   status - "ok" - if all input data correct and calculation is correct. Else "error".
   content - array of different types of costs
   content.src - a duplicate of input data (for check, that input data parse correctly)

TEST

For view output information you can use a test scripts with pre-installed test values:

   DLV: http://post-api.ru/api/test/post_cost_test.php

ACCESS TO API

For access to API need to generate API-key. The API-key can be generate in http://post-api.ru. For developer purpose may be used a apikey = "dev". In this case, developer can use any scripts, but with post index 656056 only.

In response of each script need look at array fields "access" and "access_status".

The "access_status" field set a status of access to API-functions. There are can be set:

   ok - the access is granted
   forbidden - the access is denied

The "access" field set a reason of access denied. There are can be set:

   unknown - internal error
   active - the API-key is active and granted to access to API-functions
   notexist - the API-key was not found
   blocked - the API-key is blocked, need contact with me for details