API integration DaData.ru address suggestions

Full documentation-API address hints - https://dadata.ru/api/suggest/address/

service DaData.ru (https://dadata.ru/suggestions/) provides the search API.

Searches for addresses in any part of the address from the region to the house («Tverskaya Nizhny 12» → «Nizhny Novgorod region, Nizhny Novgorod, Tverskaya street, d 12»).

Also searches by zip code («105568 »→ « g Moscow, Magnitogorsk street »).

Registration.

you need to register and confirm your email address.

Registration-https://dadata.ru/suggestions/usage/address/#registration_popup

Confirm your email address.

the API will start working after confirmation.

After registering in your personal account  https://dadata.ru/profile/#info   the API key and the Secret key for standardization will become available.

Subscription:The tariff is "Free", valid indefinitely. The possibility - Free up to 10,000 requests per day.

API request.

The format of the request.

  • URL - https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/address.
  • – Post method.
  • – Json format.
  • Encoding-UTF-8.
  • Content-Type –  application/json.
  • Accept –  application/json.
  • Authorization-Token 1d01d91d91d91d91d9f1d91d9____ - API key from your merchant profile.

Request body (json format): 

{"query": "Moscow Serpukhovskaya", "count": 20 }

query-Query text (required)

count - Number of results (maximum of 20) (optional).

CREATE PROCEDURE [dbo].[api_daDataAddress_request]
	@parameters ExtendedDictionaryParameter READONLY,  -- incoming parameters for internal processing (use Key, Value2)
	@username nvarchar(32)  -- curent user.

AS
BEGIN
DECLARE @queryCount nvarchar(2) = 20 		-- Number of results (maximum — 20)
SELECT  @queryCount = ISNULL( Value2 , '20' )  FROM @parameters WHERE [Key] = 'queryCount'
IF LEN( ISNULL( @queryCount , '20' ) ) = 0
	SET @queryCount = N'20'

DECLARE @queryStr nvarchar(max)
-- getting form field values from @parameters
SELECT  @queryStr  =  ISNULL( Value2 , '' )  FROM @parameters WHERE [Key] = 'queryStr'

IF LEN( ISNULL( @queryStr , '' ) ) = 0
	SET @queryStr = N'Moscow Serpukhov'
-- for testing
-- SET @queryStr = N'Moscow Serpukhov' -- @queryStr = N'Moscow Khabar' -- Query text

DECLARE @apiUrl1 		nvarchar(max) = '' 		-- Final line to send  -- IN FACT THIS IS Url
DECLARE @jsonRequest1	nvarchar(max) = '' 	    -- тtext json-object

SET     @apiUrl1  = 'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/address'

-- for testing -- SET     @jsonRequest1 = N'{ "query": "Moscow Serpukhov", "count": 20 }'
--
SET     @jsonRequest1 = N'{ "query": "'+ ISNULL( @queryStr, '' ) +'", "count": '+ TRY_CAST( ISNULL( @queryCount, '' )  AS nvarchar ) + ' }'

-------------------------------------------------------------------------------------------
    -- ОТЛАДКА
	 insert into as_trace ( header, text, username, code , created )   values( 'apiUrl1'       , @apiUrl1      , @username, 'api_daDataAddress_request' , GETDATE() )
	 insert into as_trace ( header, text, username, code , created )   values( '@jsonRequest1' , @jsonRequest1 , @username, 'api_daDataAddress_request' , GETDATE() )
-------------------------------------------------------------------------------------------

	-- SELECT 1
    	select '' Msg, 1 Result
          , @apiUrl1 Url
          , 'application/json' ContentType -- explicit instruction for HEADER

	-- SELECT 2 PARAMETERS - parameters that will be passed to an external source
	 select 'Authorization' name
           , 'Token 1d01d91d91d91d91d9f1d91d9' value
           , 'header' [type] -- form (in the form passed), header (in http headers), send get requests directly to the URL
     union
	 select 'body' name
           , @jsonRequest1 value -- this is body
           , 'json' [type] -- form (in the form passed), header (in http headers), send get requests directly to the URL


END

In response to the request, an object with an array of suggestions in the suggestions field is returned.

Sample response (with abbreviations).

{
    "suggestions": [
        {
            "value": "Moscow, Khabarovsk street",
            "unrestricted_value": "Moscow, Khabarovsk street",
            "data": {
                "postal_code": null,
                "country": "Russia",
                "country_iso_code": "RU",
                "federal_district": null,
                "region_fias_id": "0c5b2444-70a0-4932-980c-b4dc0d3f02b5",
            }
        },
        ...
    ]
}

As a result of parsing the response, the procedure returns the following result:

Query: Tverskaya Nizhny 12
query Results: Region: [Nizhny Novgorod region][Tver region].
unique emails Found.indexes-2.
Addresses-3.

Address

Index

Tver region, Staritsky district, village of Nizhny Spass, d 12

171372

Tver region, Staritsky district, village of Nizhny Spass, d 12

171372

Nizhny Novgorod, Tverskaya street, d 12

603105

Note. The parsing procedure outputs only three fields Address, Index, and Region.

There are more than 70 fields in the response of the service for a single address. you can get the most detailed information for each address, including the values of all classifiers.

The response procedure is [dbo].[api_daDataAddress_response] - available by link.

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

SQL-tool for creating personal accounts on the site

The essence of the approach and the history of the creation of Falcon Space
Web platform for creating personal accounts

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

MS SQL web applications. Affiliate program for developers and web studios

You can develop on your own or collaborate with us on Falcon Space web development using only SQL and HTML.
See examples with SQL code
Platform documentation
Working on MS SQL Server
Note