Data cleansing, enrichment and suggestions via Dadata API
The official Dadata .NET library, supporting .NET Standard 2.0+
Using the .NET Core command-line interface (CLI) tools:
dotnet add package Newtonsoft.Json
dotnet add package Dadata
Using the NuGet Command Line Interface (CLI):
nuget install Newtonsoft.Json
nuget install Dadata
Using the Package Manager Console:
Install-Package Newtonsoft.Json
Install-Package Dadata
From within Visual Studio:
- Open the Solution Explorer.
- Right-click on a project within your solution.
- Click on Manage NuGet Packages...
- Click on the Browse tab and search for "Dadata".
- Click on the Dadata package, select the appropriate version in the right-tab and click Install.
Import namespaces:
using Dadata;
using Dadata.Model;
Create API client instance:
var token = "Replace with Dadata API key";
var secret = "Replace with Dadata secret key";
var api = new CleanClientAsync(token, secret);
// or any of the following, depending on the API method
api = new SuggestClientAsync(token);
api = new OutwardClientAsync(token);
api = new ProfileClientAsync(token, secret);
Then call API methods as specified below.
Examples use async clients: CleanClientAsync
, SuggestClientAsync
, OutwardClientAsync
and ProfileClientAsync
. There are sync alternatives with Sync
suffixes — they exist for backward compatibility and will be removed in future releases.
var api = new CleanClientAsync(token, secret);
var address = await api.Clean<Address>("мск сухонская 11 89");
Same API method as "validate and cleanse":
var api = new CleanClientAsync(token, secret);
var address = await api.Clean<Address>("москва сухонская 11");
var api = new SuggestClientAsync(token);
var response = await api.Geolocate(lat: 55.878, lon: 37.653);
var address = response.suggestions[0].data;
var api = new SuggestClientAsync(token);
var response = await api.Iplocate("46.226.227.20");
var address = response.location.data;
var api = new SuggestClientAsync(token);
var response = await api.SuggestAddress("самара метал");
var address = response.suggestions[0].data;
Show suggestions in English:
var request = new SuggestAddressRequest("samara metal") { language = "en" };
var response = await api.SuggestAddress(request);
var address = response.suggestions[0].data;
Constrain by city (Yuzhno-Sakhalinsk):
var request = new SuggestAddressRequest("ватутина")
{
locations = new[] {
new Address() { kladr_id = "6500000100000" },
}
};
var response = await api.SuggestAddress(request);
var address = response.suggestions[0].data;
Constrain by specific geo point and radius (in Vologda city):
var request = new SuggestAddressRequest("сухонская")
{
locations_geo = new[]
{
new LocationGeo() { lat=59.244634, lon=39.913355, radius_meters=200}
}
};
var response = await api.SuggestAddress(request);
var address = response.suggestions[0].data;
Boost city to top (Toliatti):
var request = new SuggestAddressRequest("авто")
{
locations_boost = new[]
{
new Address() { kladr_id = "6300000700000" },
}
};
var response = await api.SuggestAddress(request);
var address = response.suggestions[0].data;
var api = new SuggestClientAsync(token);
var response = await api.FindAddress("9120b43f-2fae-4838-a144-85e43c2bfb29");
var address = response.suggestions[0].data;
Find by KLADR ID:
var response = await api.FindAddress("77000000000268400");
var address = response.suggestions[0].data;
Suggest postal office by address or code:
var api = new OutwardClientAsync(token);
var response = await api.Suggest<PostalUnit>("дежнева 2а");
var unit = response.suggestions[0].data;
Find postal office by code:
var response = await api.Find<PostalUnit>("127642");
var unit = response.suggestions[0].data;
Find nearest postal office:
var response = await api.Geolocate<PostalUnit>(lat: 55.878, lon: 37.653, radius_meters: 1000);
var unit = response.suggestions[0].data;
var api = new OutwardClientAsync(token);
var response = await api.Find<DeliveryCity>("3100400100000");
var city = response.suggestions[0].data;
var api = new SuggestClientAsync(token);
var response = await api.FindFias("9120b43f-2fae-4838-a144-85e43c2bfb29");
var address = response.suggestions[0].data;
var api = new OutwardClientAsync(token);
var response = await api.Suggest<Country>("та");
var country = response.suggestions[0].data;
var api = new SuggestClientAsync(token);
var response = await api.FindParty("7707083893");
var party = response.suggestions[0].data;
Find by INN and KPP:
var request = new FindPartyRequest(query: "7707083893", kpp: "540602001");
var response = await api.FindParty(request);
var party = response.suggestions[0].data;
var api = new SuggestClientAsync(token);
var response = await api.SuggestParty("сбер");
var party = response.suggestions[0];
Constrain by specific regions (Saint Petersburg and Leningradskaya oblast):
var request = new SuggestPartyRequest("сбер")
{
locations = new[] {
new Address() { kladr_id = "7800000000000" },
new Address() { kladr_id = "4700000000000" },
}
};
var response = await api.SuggestParty(request);
var party = response.suggestions[0];
Constrain by active companies:
var request = new SuggestPartyRequest("сбер")
{
status = new[] { PartyStatus.ACTIVE }
};
var response = await api.SuggestParty(request);
var party = response.suggestions[0];
Constrain by individual entrepreneurs:
var request = new SuggestPartyRequest("сбер")
{
type = PartyType.INDIVIDUAL
};
var response = await api.SuggestParty(request);
var party = response.suggestions[0];
var api = new SuggestClientAsync(token);
var response = await api.FindAffiliated("7736207543");
var party = response.suggestions[0].data;
Search only by manager INN:
var request = new FindAffiliatedRequest("773006366201")
{
scope = new[] { FindAffiliatedScope.MANAGERS }
};
var response = await api.FindAffiliated(request);
var party = response.suggestions[0].data;
var api = new SuggestClientAsync(token);
var response = await api.FindBank("044525225");
var bank = response.suggestions[0].data;
Find by SWIFT code:
var response = await api.FindBank("SABRRUMM");
var bank = response.suggestions[0].data;
Find by INN:
var response = await api.FindBank("7728168971");
var bank = response.suggestions[0].data;
Find by INN and KPP:
var request = new FindBankRequest(query: "7728168971", kpp: "667102002");
var response = await api.FindBank(request);
var bank = response.suggestions[0].data;
Find by registration number:
var response = await api.FindBank("1481");
var bank = response.suggestions[0].data;
var api = new SuggestClientAsync(token);
var response = await api.SuggestBank("ти");
var bank = response.suggestions[0].data;
var api = new CleanClientAsync(token, secret);
var fullname = await api.Clean<Fullname>("Срегей владимерович иванов");
var api = new SuggestClientAsync(token);
var response = await api.SuggestName("викт");
var fullname = response.suggestions[0].data;
Suggest female first name:
var request = new SuggestNameRequest("викт")
{
parts = new[] { FullnamePart.NAME },
gender = Gender.FEMALE
};
var response = await api.SuggestName(request);
var fullname = response.suggestions[0].data;
var api = new CleanClientAsync(token, secret);
var phone = await api.Clean<Phone>("9168-233-454");
var api = new CleanClientAsync(token, secret);
var passport = await api.Clean<Passport>("4509 235857");
var api = new OutwardClientAsync(token);
var response = await api.Suggest<FmsUnit>("772 053");
var unit = response.suggestions[0].data;
var api = new CleanClientAsync(token, secret);
var email = await api.Clean<Email>("serega@yandex/ru");
var api = new SuggestClientAsync(token);
var response = await api.SuggestEmail("maria@");
var email = response.suggestions[0].data;
var api = new OutwardClientAsync(token);
var response = await api.Find<FnsUnit>("5257");
var unit = response.suggestions[0].data;
var api = new OutwardClientAsync(token);
var response = await api.Suggest<MetroStation>("алек");
var station = response.suggestions[0].data;
Constrain by city (Saint Petersburg):
var request = new SuggestOutwardRequest("алек")
{
filters = new Dictionary<string, string>() { { "city", "Санкт-Петербург" } }
};
var response = await api.Suggest<MetroStation>(request);
var station = response.suggestions[0].data;
var api = new OutwardClientAsync(token);
var response = await api.Suggest<CarBrand>("фо");
var brand = response.suggestions[0].data;
var api = new OutwardClientAsync(token);
var response = await api.Find<OktmoRecord>("54623425");
var record = response.suggestions[0].data;
var api = new OutwardClientAsync(token);
var response = await api.Suggest<OkvedRecord>("космических");
var record = response.suggestions[0].data;
var api = new ProfileClientAsync(token, secret);
Balance:
var response = await api.GetBalance();
var balance = response.balance;
Usage stats:
var response = await api.GetDailyStats();
var cleanCount = response.services.clean;
var suggestionsCount = response.services.suggestions;
var mergingCount = response.services.merging;
Dataset versions:
var response = await api.GetVersions();
var egrulVersion = response.suggestions.resources["ЕГРЮЛ"];
var geoVersion = response.factor.resources["Геокоординаты"];
This project only accepts bug fixes.
This project uses CalVer with YY.MM.MICRO schema. See changelog for details specific to each release.