I am tasked with writing a SQL Server stored procedure to request a bearer token from a vendor site using their API.
The vendor site issued me two files of type .cer
and .key
. When I import these files into Postman, I can request a bearer token and receive the appropriate response after including two additional values, the client_id
and client_secret
.
I am looking for documentation on how to do the same from SQL Server. There are almost NO posts anywhere about using a security certificate from a SQL Server stored procedure directly. The writer already has a bearer token to use in their code in all the posts I found, and assumes you do, too. This makes me wonder if this can be done from a SQL Server stored procedure?
I combined the two files into a .pfx
file and imported into the Windows Server certificate store where the SQL Server instance resides. It is currently in the Personal store (it can be moved to another store, if need be).
Am I going about this wrong? I could always use Postman to get the bearer token, then consume into SQL Server using the xp_cmdshell. It just seems like this should be easier than that.
I can successfully get a bearer token using Postman. I cannot find instructions anywhere for how to do the same thing within SQL Server.
SQL Server 2016 running on Windows Server 2016. The vendor is the payroll company ADP.
1条答案
按热度按时间n1bvdmb61#
This is very much not recommended. You should have an app or script with application code in between SQL Server and the other environment, rather than trying do this in SQL directly.
Nevertheless, it should be possible. What you need is to send the appropriate HTTP requests to get the token, and that can be accomplished using the information here:
How can I make HTTP request from SQL server?
The link is talking about connecting to Tomcat, rather than a REST API, but the basic principle of using HTTP is the same.
And again: not recommended.