There's a site called NPI registry lookup which will show the information about the doctor you're searching for. i am getting this error XMLHttpRequest cannot load https://npiregistry.cms.hhs.gov/api/?number=1306935523. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:58202' is therefore not allowed access.
<script type="text/javascript">
$(document).ready(function () {
$('#btnGetNpi').click(function () {
$.ajax({
async: true,
crossDomain: true,
url: 'https://npiregistry.cms.hhs.gov/api/?number=' + $('#txtnpi').val(),
method: 'get',
dataType: 'json',
success: function (data) {
debugger;
resultElement.html('FirstName:' + data.basic[0].first_name);
},
error: function (jqXHR, exception) {
alert(exception);
}
});
});
});
</script>
</div>
I'm not sure if this is what you're looking for, but the US Gov has a free API for doing NPI lookups, so you could pull your code from here: https://npiregistry.cms.hhs.gov/ It has a link to the API, which shows how to request info from the NPI db. There are several other websites that do this too, so you could crib code from them....
Application Programming Interface (API) | Read-Only The API is a new, faster alternative to the downloadable NPPES data files. It allows systems to access NPPES public data in real-time, rather than through batched uploads. The API retrieves data from NPPES daily.
NPPES Read API Interactive Test Application System administrators can use the interactive demo to experiment with generating queries. The API will generate its output at https://npiregistry.cms.hhs.gov/api/.
There are several sites that do NPI lookups. Look at their code. Other sites do it. Copy the successful ones.
Those of you who are coders should be able to make this sing!
I just ran into the same issue and had to hack a solution. This is by no means a final or permanent solution, but it does work. I am going to attempt to contact whoever maintains this database and let them know that it is CORS blocked and as such a useless public API, hopefully, we can get that changed.
Here is what I ended up doing: n.b. You may not have php, but I'm willing to bet some other languages have something similar that could work.
.js file:
$.ajax({
type: 'post',
url: 'somefile.php',
data: 'npiNumber=xxxxxxxxxx',
success: function(response) {
var npiData = JSON.parse(response);
console.log(npiData);
}
});
.php file
if(isset($_POST['npiNumber'])) {
echo file_get_contents('https://npiregistry.cms.hhs.gov/api/resultsDemo2/?number='.$_POST['npiNumber']);
}
That's all. The php file_get_contents literally goes to the page and loads it and returns the content of whatever is on that page. It isn't a server request so much as just a "give me the results of the page itself" request. Then I pass that back to javascript and parse it into a JSON object. Ugly hack. Ugly.