Have you ever needed to read API data from an endpoint and then turn around and load that into your database?
I would consider Python requests library in combination with SQLalchemy for a task like that, but did you know you can do it all in Management Studio?
Lets take a look at the following API endpoint : http://api.open-notify.org/iss-now.json.
This endpoint returns the current position of the International Space Station in lat / long format.
Before we are able to do this we must prepare our SQL enviorment, you might lack permissions to do this on a production instance, but a local SQL express version of SQL server will do just fine if that is the case.
Next we will declare variables for the endpoint, response and data.
You can change the operation type to POST data for instance, in this demo we will simply be using GET.
As you can see in the print window we will have our response from the ISS, pretty neat!
If you want to furthur abstract this code we can turn it into a stored procedure and parameterize the entire process.
This way one stored procedure can handle all the API verbs and you can even log the responses utalizing output parameters!
Ian Fogelman
My name is Ian Fogelman. I like to develop data driven solutions with SQL Server, Python, .NET and predictive analytics.