Integration of the Russian Post API

This document describes the implementation of information exchange between Falcon Space and Russian post.

General input data:

  • Departure city (Flag - from the door);
  • City of receipt (Flag-up to the door);
  • Length, cm;
  • Width, cm;
  • Height, cm;
  • Weight, g.

The general algorithm:

  1. Forming the request text with parameters
  2. Sending a request
  3. Getting a response to a request
  4. Response parsing, getting data.

 

Email of the Russian Federation with the authorization otpravka.pochta.ru (overview)

To get started, you need to register -https://passport.pochta.ru.

API of the Online service « sending » - Basic information -https://otpravka.pochta.ru/specification#/main

Interaction viaREST queries.

The service's requests and responses useJSON text format.

 

To integrate with the API of the Sending Online service «Отправка», you must have:

  •     the access token of the application;
  •     by user's authorization key.

 

Key user authorization-generated using the base64 algorithm -https://otpravka.pochta.ru/specification#/authorization-key

 

The token can be found in the settings of your personal account -https://otpravka.pochta.ru/settings#/api-settings

To work with this service and get a token, you need an agreement with Russian Post!

This method is not considered Further.

Russian post without authorization

If you don't have a contract and api access, use these two services from Russian Post. 

Calculating delivery times - https://delivery.pochta.ru/#/calcmail/910

Calculation of the delivery cost -https://tariff.pochta.ru/#/calcmail/101

 

Russian post rates-Cost - PROCEDURE [api_ruPostTariff_request]

Automatic calculation of the cost of mail and services using the billing service

Site: https://tariff.pochta.ru/#/calcmail/101

Documentation: https://tariff.pochta.ru/TariffAPI.pdf?367

To get the calculation, the client sends to the server REST-request method GET

 

Request parameters

 

Input data for the query – parameters of the PROCEDURE [dbo].[api_ruPostTariff_request]

Variable

Type

Default value

Description

Note

1

@resultType

nvarchar(32)

'Json'

Format of the requested data

Json - result type

2

@codeObject

nvarchar(32)

'47030'

Type (code) of the postal billing object, see App 1

47030 - Package of class 1 (EXAMPLE c6v.ru)

27030 - Package (individual or enterprise) - Package standard

3

@indexTo

nvarchar(32)

'101000'

The index of the destination

101000 "MOSCOW"

4

@doorFrom

bit

 0

Flag-from the door

 NOT USED YET

5

@indexTo

nvarchar(32)

'690000 '

The index of the destination

108803 "VOSKRESENSKOE"

- Vladivostok

6

@doorTo

bit

0

Flag-to the door

 NOT USED YET

 

weight/dimensions

7

@weight

nvarchar(32)

'100'

Weight

(while counting in grams)

8

@length    

nvarchar(32)

'10'

Length, cm

NOT USED YET

9

@width     

nvarchar(32)

'10'

Width, cm

NOT USED YET

10

@height    

nvarchar(32)

'10'

Height, cm

NOT USED YET

11

@pack      

nvarchar(32)

'10'

Тип упаковки

See possible values in App 3

10 - Box «S»

12

@operDate  

nvarchar(8)

 

Billing date YYYYMMDD

If no date is specified, the current date value is assumed

 

The estimated parameters

13

size

nvarchar(max)

 

The size of the shipment (cm).

Specifies 3 integer values separated by a sign “x”, for example, size=100x50x25.

NOT USED YET

  

Indexes

  • 101000-MOSCOW
  • 344000-Rostov
  • 163000-Arkhangelsk
  • 690000-Vladivostok

Note 1. Depending on the billing object Code, the set of input parameters may change.

 

Sample request text - request.

 https://tariff.pochta.ru/tariff/v1/calculate?Json&object=47030&from=101000&to=690000&weight=100&pack=10&date=20200603

 

Note.in Fact, only theURLIS passed in this request. Body – request body is not present, SELECT2 is not used.

Sample response text - response.

{
    "version": "1.13.3.390",
    "place": "C5-6",
    "id": 47030,
    "name": "Class 1 package",
    "typ": 47,
    "cat": 3,
    "dir": 0,
    "from": 101000,
    "to": 690000,
    "weight": 100,
    "date": 20200603,
    "time": 0,
    "date-first": 20200101,
    "postoffice": [
        {
            "index": 101000,
            "tp": 1,
            "name": "MOSCOW",
            "region": 1000000001045,
            "regid": 77,
            "place": 1000000001045,
            "parent": 127950,
            "type": 3,
            "pvz": 1,
            "item-check-men": 1,
            "item-check-view": 1,
            "move": 1,
            "pack-max": 99
        },
        {
            "index": 690000,
            "tp": 2,
            "name": "THE VLADIVOSTOK POST OFFICE",
            "region": 1005,
            "regid": 25,
            "place": 1000000031441,
            "parent": 690700,
            "type": 15
        }
    ],
    "trans": 3,
    "transid": 2,
    "transname": "avia",
    "tariff": [
        {
            "id": "2556",
            "name": "Payment for sending a class 1 parcel",
            "steps": [
                {
                    "name": "Delivery from group 1 to zone 2",
                    "route": [
                        2556,
                        "1",
                        "2",
                        "100"
                    ],
                    "v": 14417,
                    "id": "2556-1-2-100"
                }
            ],
            "fromi": 101000,
            "from": "MOSCOW",
            "toi": 690000,
            "to": "THE VLADIVOSTOK POST OFFICE",
            "ground": {
                "val": 14417,
                "valnds": 17300,
                "ndsrate": 20.0
            }
        }
    ],
    "ground": {
        "val": 14417,
        "valnds": 17300
    },
    "pay": 14417,
    "paynds": 17300,
    "ndsrate": 20,
    "nds": 2883,
    "typcatname": "Class 1 package",
    "now": "20200603T202514"
}

 

CREATE PROCEDURE [dbo].[api_ruPostTariff_request]
	@parameters ExtendedDictionaryParameter READONLY,  -- incoming parameters for internal processing (use Key, Value2)
	@username nvarchar(32)  -- current user.
    --  API QUERY-KEYS Source data:
    ,@resultType nvarchar(32) = 'Json' 		-- Json		result type
	,@codeObject nvarchar(32) = '47030'  	-- Billing object code
    										-- 47030 - Class 1 parcel -- EXAMPLE c6v.ru
											-- 27030 - Package (individual or company) - standard Package

	,@indexFrom	nvarchar(32) = '101000'   	-- Departure point index -- 101000 "MOSCOW".
	,@doorFrom  bit = 0 					-- Flag - Door - EXAMPLE c6v.ru -- NOT USED YET

	,@indexTo   nvarchar(32) = '690000'   	-- The index of the destination -- 108803 "VOSKRESENSKOE". -- 690000 - Vladivostok
	,@doorTo   	bit = 0 					-- Flag - Door - EXAMPLE c6v.ru -- NOT USED YET
	-- вес/габариты
	,@weight     nvarchar(32) = '100'   	-- Weight (grams/kg) -- Specified in grams or kilograms, depending on the billing object, see App 1
											-- while counting in grams
    -- Size   -- EXAMPLE c6v.ru -- NOT USED YET
	,@length     nvarchar(32) = '10'   		-- Length, cm
	,@width      nvarchar(32) = '10'   		-- Width, cm
	,@height     nvarchar(32) = '10'   		-- Height, cm

	,@pack       nvarchar(32) = '10'   		-- Packaging
    ,@operDate   nvarchar(8)  = ''          --'20200527'  -- Billing date YYYYMMDD -- If no date is specified, the current date value is accepted

AS
BEGIN

-- Billing date YYYYMMDD -- If no date is specified, the current date value is accepted
-- 112 = yyyymmdd --'20200527'
IF  LEN(  ISNULL ( @operDate   , '' ) )=0
SET @operDate  =  CONVERT ( nvarchar(8) , GETDATE() , 112 )
-- exec as_print @str = @operDate


DECLARE @apiUrl 		nvarchar(max) = '' 		-- The final line to send -- @apiStr -- IN FACT this is Url
DECLARE @apiCommomStr 	nvarchar(max) = '' 	    -- Common part for all queries
SET     @apiCommomStr   = 'https://tariff.pochta.ru/tariff/v1/calculate?' -- ? sign at the end Necessarily

-- size Line size of the shipment (cm). Specifies 3 integer values separated by a sign “x”, example, size=100x50x25. Possible value: 1–1000
-- is formed on the input parameters
-- EXAMPLE c6v.ru -- NOT USED YET
DECLARE @size nvarchar(max) = ''
SET     @size =  @length + 'x' + @width + 'x' + @height
-- exec as_print @str=@size

SET  @apiUrl  = @apiUrl + @apiCommomStr
                        + @resultType
                        + IIF ( LEN(  ISNULL ( @codeObject , '' ) )>0, '&object=' + @codeObject, '' )
                        + IIF ( LEN(  ISNULL ( @indexFrom  , '' ) )>0, '&from=' + @indexFrom, '' )
                        + IIF ( LEN(  ISNULL ( @indexTo    , '' ) )>0, '&to=' + @indexTo, '' )
                        + IIF ( LEN(  ISNULL ( @weight     , '' ) )>0, '&weight=' + @weight, '' )
                        + IIF ( LEN(  ISNULL ( @pack       , '' ) )>0, '&pack=' + @pack, '' )
                        + IIF ( LEN(  ISNULL ( @operDate   , '' ) )>0, '&date=' + @operDate, '' )


    -- DEBUG
	insert into as_trace (text, username, code , created )   values( @apiUrl , @username, 'api_ruPostTariff_request' , GETDATE() )

    -- THE CORRECT LINE
    -- select '' Msg, 1 Result, 'https://tariff.pochta.ru/tariff/v1/calculate?json&object=27030&from=101000&to=108803&weight=1000&pack=10&date=20200527' Url
    -- IN FACT THE ENTIRE REQUEST IS SENT to the URL
    select '' Msg, 1 Result, @apiUrl AS Url

	-- SELECT 2 PARAMETERS - parameters that will be passed to an external source
	-- select 'id' name, '5' value, '' [type] -- form (в форме передается), header (в http headers), get запросы передавайте прямо в URL
	END

Russian post rates-Cost - PROCEDURE [api_ruPostTariff_response]

The query result can be either a message with information or an error message.

 A list of possible error messages.

  1.  'Error! The @response string is not JSON!' (Checking the response with the ISJSON () operator)
  2.  'Error! The @response query returned an error! '… @errorText.

Sample response text response – with the error.

{
    "caption": "Pricing errors",
    "version": "1.13.3.390",
    "error": [
        "The billing object is not specified in the object parameter. (1301)"
    ],
    "errors": [
        {
            "msg": "The billing object is not specified in the object parameter.",
            "code": 1301
        }
    ]
}

If no errors are found in the response, the following data is selected from the response:

  • Total amount without VAT
  • Total amount with VAT
  • VAT Rate %
  • VAT Amount
  • The name of the operation
  • completion date and Time

Sample text – result: "Operation: class 1 Parcel total amount without VAT: 144.71 RUB. Total VAT (Rate 20% ):28.38 rubles. Total amount with VAT: 173.00 RUB."

PROCEDURE [dbo].[api_ruPostTariff_response]

CREATE PROCEDURE [dbo].[api_ruPostTariff_response]
	@response nvarchar(max),
	@parameters ExtendedDictionaryParameter READONLY,  -- входящие параметры для внутренней обработки (используйте Key, Value2 - те же что и на request)

	@username nvarchar(32)
AS
BEGIN
    -- DEBUG
    -- exec as_print @str='api_ruPostTariff_response'
	insert into as_trace (text, username, code , created) values(@response, @username, 'api_ruPostTariff_response' , GETDATE() )


    DECLARE @json1 NVARCHAR(MAX)  = N''
	SET @json1 = @response

    -- To check whether the JSON format is correct, there is an ISJSON function that returns 1 if it is JSON, 0 if it is not, and NULL if NULL was passed
    DECLARE @presentJSON bit = 0
    SELECT @presentJSON = ISNULL( ISJSON( @json1 ) , 0 )
    -- SELECT @presentJSON
    IF @presentJSON <> 1
    BEGIN
        SELECT 'Error! Line @response не является JSON!' Msg, 0 Result, @response Response
        RETURN
    END


    -- Handling an error in the response
    DECLARE @presentError bit = 0, @errorText NVARCHAR(MAX), @errorCode NVARCHAR(MAX), @errorMsg NVARCHAR(MAX)
    -- error
    -- https://tariff.pochta.ru/tariff/v1/calculate?Json&27030&101000&108803&1000&10&20200527
    -- {"caption": "Pricing errors","version": "1.12.19.385","error": ["The billing object is not specified in the object parameter. (1301)"],"errors": [{"msg":"The billing object is not specified in the object parameter.","code":1301}]}

	DECLARE @pay		NVARCHAR(MAX) -- Total amount without VAT
          , @paynds		NVARCHAR(MAX) -- Total amount with VAT
          , @ndsrate	NVARCHAR(MAX) -- VAT rate %
          , @nds		NVARCHAR(MAX) -- amount of VAT
          , @typcatname NVARCHAR(MAX) -- The name of the operation
          , @now		NVARCHAR(MAX) -- Date and Time of completion

	-- To extract a scalar value from JSON, you can use the function JSON_VALUE:
      SELECT @presentError = IIF( JSON_VALUE( @json1, '$.error[0]') IS NULL  , 0 , 1 )
           , @errorText    = JSON_VALUE( @json1, '$.error[0]')
           , @errorCode    = JSON_VALUE( @json1, '$.errors[0].code')
           , @errorMsg     = JSON_VALUE( @json1, '$.errors[0].msg')
           -- Данные
           , @pay 			= JSON_VALUE( @json1, '$.pay')
           , @paynds 		= JSON_VALUE( @json1, '$.paynds')
           , @ndsrate 		= JSON_VALUE( @json1, '$.ndsrate')
           , @nds 			= JSON_VALUE( @json1, '$.nds')
           , @typcatname 	= JSON_VALUE( @json1, '$.typcatname')
           , @now 			= JSON_VALUE( @json1, '$.now')


      IF @presentError = 1
      BEGIN
          SELECT 'Error! Request @response return an error! '+ ISNULL( @errorText, '' ) Msg, 0 Result, @response Response
          RETURN
      END

	 DECLARE @payInt		NVARCHAR(MAX) -- Total amount without VAT -- Integer
          , @payDecimal		NVARCHAR(MAX) -- Total amount with VAT -- Fractional
          , @payndsInt		NVARCHAR(MAX) -- Total amount with VAT -- Integer
          , @payndsDecimal	NVARCHAR(MAX) -- Total amount with VAT -- Fractional
          , @ndsInt			NVARCHAR(MAX) -- Amount of VAT -- Integer
          , @ndsDecimal		NVARCHAR(MAX) -- Amount of VAT -- Fractional

    SELECT @payInt        = ISNULL( SUBSTRING ( @pay , 1 , LEN(@pay) - 2 )		, '' )
         , @payDecimal    = ISNULL( SUBSTRING ( REVERSE( @pay ), 1 ,2 )			, '' )
         , @payndsInt     = ISNULL( SUBSTRING ( @paynds , 1 , LEN(@paynds) - 2 ), '' )
         , @payndsDecimal = ISNULL( SUBSTRING ( REVERSE( @paynds ), 1 ,2 )		, '' )
         , @ndsInt        = ISNULL( SUBSTRING ( @nds , 1 , LEN(@nds) - 2 )		, '' )
         , @ndsDecimal    = ISNULL( SUBSTRING ( REVERSE( @nds ), 1 ,2 )			, '' )


	-- SELECT 1
	select 'Operation: '+ ISNULL( @typcatname, '' )
         + ' Total amount without VAT: '+ ISNULL( @payInt, '' )  + '.'    + ISNULL( @payDecimal, '' ) +' rub.'
         + ' Total VAT (Rate '  + ISNULL( @ndsrate, '' ) +'% ):'  + ISNULL( @ndsInt, '' )  + '.'  + ISNULL( @ndsDecimal, '' ) +' rub.'
         + ' Total amount with VAT: '  + ISNULL( @payndsInt , '' ) + '.' + ISNULL( @payndsDecimal, '' ) +' rub.' AS Msg --
          , 1 Result , @response Response


	-- SELECT 2 External action

END

Russian post - Delivery Time - PROCEDURE [api_ruPostDelivery_request]

Automatic calculation of standard delivery times for postal items.

The site: https://delivery.pochta.ru/#/calcmail/913

Documentation:  https://delivery.pochta.ru/delivery_api.pdf?176

 

To get the calculation, the client sends to the server REST-request method GET

Request parameters

 

Input data for the query – procedure parameters PROCEDURE [api_ruPostDelivery_request]

Variable

Type

Default

Discription

Note

1

@resultType

nvarchar(32)

'Json'

Format of the requested data

Json - result type

2

@codeObject

nvarchar(32)

'47030'

Type (code) of the postal billing object, see App 1

47030 - Class 1 package – 

27030 - Package (individual or company) - standard Package

3

@indexFrom

nvarchar(32)

'101000'

Departure point index

101000 "MOSCOW"

4

@indexTo

nvarchar(32)

'690000 '

The index of the destination

108803 "VOSKRESENSKOE"

- Vladivostok

5

@operDate  

nvarchar(8)

 

Billing date YYYYMMDD

If no date is specified, the current date value is assumed

 

An example of the request text - request.

https://delivery.pochta.ru/delivery/v1/calculate?Json&object=47030&from=101000&to=690000&date=20200603

Note. In fact, only the URL is passed in this request. The body of the request body – no, SELECT2 is not being used.

 

Example response text - response.

{
    "version": "1.13.3.390",
    "place": "D_21",
    "id": 47030,
    "name": "Class 1 package",
    "typ": 47,
    "cat": 3,
    "dir": 0,
    "from": 101000,
    "to": 690000,
    "date": 20200603,
    "time": 0,
    "date": 20200603,
    "time": 0,
    "date-first": 20200218,
    "postoffice": [

        {
            "index": 101000,
            "tp": 1,
            "name": "MOSCOW",
            "region": 1000000001045,
            "regid": 77,
            "place": 1000000001045,
            "parent": 127950,
            "type": 3,
            "pvz": 1,
            "item-check-men": 1,
            "item-check-view": 1,
            "move": 1,
            "pack-max": 99
        },
        {
            "index": 690000,
            "tp": 2,
            "name": "THE VLADIVOSTOK POST OFFICE",
            "region": 1005,
            "regid": 25,
            "place": 1000000031441,
            "parent": 690700,
            "type": 15
        }
    ],
    "tariff": [
        {
            "id": "5072",
            "name": "Standard delivery period for class 1 departure",
            "steps": [
                {
                    "name": "Direct line between localities",
                    "route": [
                        "5072",
                        "45000000",
                        "5701000001"
                    ],
                    "z": 4,
                    "id": "5072-45000000-5701000001"
                }
            ],
            "fromi": 101000,
            "from": "MOSCOW",
            "toi": 690000,
            "to": "THE VLADIVOSTOK POST OFFICE",
            "delivery": {
                "min": 2,
                "max": 4
            }
        }
    ],
    "delivery": {
        "min": 2,
        "max": 4
    },
    "typcatname": "Class 1 package",
    "now": "20200603T204906"
}

CREATE PROCEDURE [dbo].[api_ruPostDelivery_request]
	@parameters ExtendedDictionaryParameter READONLY,  -- incoming parameters for internal processing (use Key, Value2)
	@username nvarchar(32)  -- curent user.
    --
    ,@resultType nvarchar(32) = 'Json' 		-- Json		type of result
	,@codeObject nvarchar(32) = '47030'  	-- Billing object code
    										-- 47030 - Class 1 parcel -- EXAMPLE c6v.ru
											-- 27030 - Package (individual or company) - standard Package

	,@indexFrom	nvarchar(32) = '101000'   	-- Departure point index -- 101000 " MOSCOW".

	,@indexTo   nvarchar(32) = '690000'   	-- The index of the destination -- 108803 "VOSKRESENSKOE". -- Vladivostok 690000

    ,@operDate   nvarchar(8)  = ''          --'20200527'  -- Billing date YYYYMMDD
    										-- The date must be specified in local time.If no date is specified–the value of the current date in Moscow time is assumed

AS
BEGIN

-- Billing date YYYYMMDD -- If no date is specified, the current date value is assumed
-- 112 = yyyymmdd --'20200527'
IF  LEN(  ISNULL ( @operDate   , '' ) )=0
SET @operDate  =  CONVERT ( nvarchar(8) , GETDATE() , 112 )
-- exec as_print @str = @operDate

DECLARE @apiUrl 		nvarchar(max) = '' 		-- Final line to send -- @apiStr -- IN FACT THIS IS Url
DECLARE @apiCommomStr 	nvarchar(max) = '' 	    -- Common part for all queries
SET     @apiCommomStr   = 'https://tariff.pochta.ru/tariff/v1/calculate?' -- ? the sign at the end is Mandatory

-- size Line The size of the dispatch (cm). Specifies 3 integer values separated by “ x ”, for example size = 100x50x25. Possible values: 1–1000
-- is formed according to the incoming parameters
-- EXAMPLE c6v.ru -- NOT USED YET
DECLARE @size nvarchar(max) = ''
SET     @size =  @length + 'x' + @width + 'x' + @height
-- exec as_print @str=@size

SET  @apiUrl  = @apiUrl + @apiCommomStr
                        + @resultType
                        + IIF ( LEN(  ISNULL ( @codeObject , '' ) )>0, '&object=' + @codeObject, '' )
                        + IIF ( LEN(  ISNULL ( @indexFrom  , '' ) )>0, '&from=' + @indexFrom, '' )
                        + IIF ( LEN(  ISNULL ( @indexTo    , '' ) )>0, '&to=' + @indexTo, '' )
                        + IIF ( LEN(  ISNULL ( @operDate   , '' ) )>0, '&date=' + @operDate, '' )


    -- DEBUG
	-- exec as_print @str='api_ruPostTariff_request'
	insert into as_trace (text, username, code , created )   values( @apiUrl , @username, 'api_ruPostDelivery_request' , GETDATE() )
    -- IN FACT ALL REQUEST SENDS TO URL
    select '' Msg, 1 Result, @apiUrl AS Url

	-- SELECT 2 PARAMETERS - parameters that will be passed to an external source
	-- select 'id' name, '5' value, '' [type] -- form (in the form passed), header (в http headers), send requests get directly to the URL
END

Russian post - Delivery Terms - PROCEDURE [api_ruPostDelivery_response]

 The request result can be either an information message or an error message.

 List of possible error messages.

  1. 'Error! The @response line is not JSON!' (Checking the response with the ISJSON operator() )
  2. 'Error! Request @response вернул ошибку! '… @errorText.

 

Sample response text – response – with error

{
    "caption": "Pricing errors",
    "version": "1.13.3.390",
    "data": {
        "id": 47030,
        "typ": 47,
        "cat": 3,
        "dir": 0,
        "name": "Class 1 package",
        "seq": 47030,
        "date": 20200603,
        "date-first": 20200218
    },
    "error": [
        "Invalid value for the \"Destination index\" parameter (to). the value \ " 6900001111\" is not a parameter of the post object. (1301)"
    ],
    "errors": [
        {
            "msg": "Invalid value for the \"Destination index\" parameter (to). the value \ " 6900001111\" is not a parameter of the post object.",
            "code": 1301
        }
    ]
}

If no errors are found in the response, the following data is selected from the response:

  •  Minimum standard number of days for delivery of the shipment
  •  Maximum standard number of days of delivery of the shipment
  • Operation name
  • Execution Date and Time

  

Example of text – result: "Operation: class 1 Parcel delivery Time: 2 to 4 days."

CREATE PROCEDURE [dbo].[api_ruPostDelivery_response]
	@response nvarchar(max),
	@parameters ExtendedDictionaryParameter READONLY,  -- incoming parameters for internal processing (use Key, Value2 - the same as on request)

	@username nvarchar(32)
AS
BEGIN
    -- DEBUG
    -- exec as_print @str='api_ruPostDelivery_response'
	insert into as_trace (text, username, code , created  ) values(@response, @username, 'api_ruPostDelivery_response' , GETDATE() )


    DECLARE @json1 NVARCHAR(MAX)  = N''
	SET @json1 = @response

    -- To check whether the JSON format is correct, there is an ISJSON function that returns 1 if it is JSON, 0 if it is not, and NULL if NULL was passed
    DECLARE @presentJSON bit = 0
    SELECT @presentJSON = ISNULL( ISJSON( @json1 ) , 0 )
    -- SELECT @presentJSON
    IF @presentJSON <> 1
    BEGIN
        SELECT 'Error! The line @response isn't JSON!' Msg, 0 Result, @response Response
        RETURN
    END

	-- Handling an error in the response
    DECLARE @presentError bit = 0, @errorText NVARCHAR(MAX), @errorCode NVARCHAR(MAX), @errorMsg NVARCHAR(MAX)

	DECLARE  @typcatname NVARCHAR(MAX) -- The name of the operation
           , @now		NVARCHAR(MAX) -- Date and Time of completion
           --
    DECLARE @deliveryDaysMin NVARCHAR(MAX)
	DECLARE @deliveryDaysMax NVARCHAR(MAX)

	-- To extract a scalar value from JSON, you can use the function JSON_VALUE:
    SELECT @presentError = IIF( JSON_VALUE( @json1, '$.error[0]') IS NULL  , 0 , 1 )
           , @errorText    = JSON_VALUE( @json1, '$.error[0]')
           , @errorCode    = JSON_VALUE( @json1, '$.errors[0].code')
           , @errorMsg     = JSON_VALUE( @json1, '$.errors[0].msg')
           -- Data
           , @typcatname 	= JSON_VALUE( @json1, '$.typcatname')
           , @now 			= JSON_VALUE( @json1, '$.now')
           , @deliveryDaysMin = JSON_VALUE( @json1, '$.delivery.min')
	 	   , @deliveryDaysMax = JSON_VALUE( @json1, '$.delivery.max')

      IF @presentError = 1
      BEGIN
          SELECT 'Error! The @response query returned an error! '+ ISNULL( @errorText, '' ) Msg, 0 Result, @response Response
          RETURN
      END

    DECLARE @deliveryText NVARCHAR(MAX)
    -- Delivery time: 2 to 4 days.
    IF ISNULL( @deliveryDaysMin, '' ) <> ISNULL( @deliveryDaysMax, '' ) SET @deliveryText = 'Delivery time: from ' + ISNULL( @deliveryDaysMin, '' )+' before '+ISNULL( @deliveryDaysMax, '' )+' days.'
    IF ISNULL( @deliveryDaysMin, '' )  = ISNULL( @deliveryDaysMax, '' ) SET @deliveryText = 'Delivery time: ' + ISNULL( @deliveryDaysMin, '' )+' days.'

	-- SELECT 1
	select 'Operation: '+ ISNULL( @typcatname, '' ) +' '+ @deliveryText AS  Msg
          , 1 Result, @response Response

	-- SELECT 2 External action

END

Falcon Space is a functional web development platform on a narrow stack MS SQL/Bootstrap. Falcon Space Gettting started
{sp-shortDemostandLinks}

Falcon Space Platform

This is a reduction in the cost of ownership

at the expense of fewer people to support

This is a quick change

while using the program

This is a modern interface

full adaptation for mobile devices

Note