Created
July 29, 2020 13:00
-
-
Save nalgeon/8071d072d3e66f83d4ff361ca44a9986 to your computer and use it in GitHub Desktop.
Revisions
-
nalgeon created this gist
Jul 29, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ ### Определить самозанятого по ИНН В поддержку «[Дадаты](https://dadata.ru/)» иногда обращаются с вопросом «как проверить, является ли физлицо самозанятым». Налоговая служба не предоставляет открытых данных по самозанятым, поэтому такого сервиса нет в «Дадате». Но можно воспользоваться [API налоговой](https://npd.nalog.ru/html/sites/www.npd.nalog.ru/api_statusnpd_nalog_ru.pdf). Мы подготовили примеры, как это сделать на самых популярных языках — Python, PHP и JavaScript. API налоговой бесплатное, но используете его вы на свой страх и риск. Никто не гарантирует, что оно будет работать корректно и стабильно. Пример ответа API налоговой, если ИНН принадлежит самозанятому: ``` { "status": true, "message": "xxxxxxxxxxxx является плательщиком налога на профессиональный доход" } ``` Пример ответа API, если ИНН не принадлежит самозанятому: ``` { "status": false, "message": "xxxxxxxxxxxx не является плательщиком налога на профессиональный доход" } ``` Примеры вызова на JS, PHP и Python — ниже. This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ const fetch = require("node-fetch"); function checkStatus(inn, date) { if (!date) { date = new Date(); } const dateStr = date.toISOString().substring(0, 10); const url = "https://statusnpd.nalog.ru/api/v1/tracker/taxpayer_status"; const data = { inn: inn, requestDate: dateStr, }; resp = fetch(url, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(data), }); return resp; } checkStatus("027714145906") .then((response) => { return response.json(); }) .then((response) => { console.log(response); }); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ <?php function checkStatus($inn, $date = null) { if (!$date) { $date = new DateTime("now");; } $dateStr = $date->format("Y-m-d"); $url = "https://statusnpd.nalog.ru/api/v1/tracker/taxpayer_status"; $data = array( "inn" => $inn, "requestDate" => $dateStr ); $options = array( 'http' => array( 'method' => 'POST', 'header' => array( 'Content-type: application/json', ), 'content' => json_encode($data) ), ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); return json_decode($result); } $resp = checkStatus("027714145906"); var_dump($resp); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ import datetime as dt import httpx def check_status(inn: str, date: dt.date = None) -> dict: date = date or dt.date.today() date_str = date.isoformat() url = "https://statusnpd.nalog.ru/api/v1/tracker/taxpayer_status" data = { "inn": inn, "requestDate": date_str, } resp = httpx.post(url=url, json=data) return resp.json() if __name__ == "__main__": response = check_status("027714145906") print(response)