1

I want to get my Binance account info by calling API via SQL Server. But I can't figure it out how sent API key with suitable format. Is it possible? How should I sent API key with get request?

Error: {"code":-2014,"msg":"API-key format invalid."}

Here is my SQL below;

DECLARE @Object AS INT;
DECLARE @ResponseT AS  VARCHAR(max);
DECLARE @Response AS TABLE(Json_Table NVARCHAR(MAX))


DECLARE @Signature NVARCHAR(255) = 'XXXXXXXXXXXXXXXXXXXXXX'
DECLARE @Timestamp_Value NVARCHAR(255) = '163818122343'


DECLARE @Url NVARCHAR(1000) = 'https://api.binance.com/api/v3/account?'+'timestamp='+@Timestamp_Value+'&signature='+@Signature
DECLARE @Api_Key  varchar(max) = '[{
                                  "Name": "X-MBX-APIKEY",
                                  "Value" :"YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"
                                }]';

 
EXEC sp_OACreate 'MSXML2.ServerXMLHTTP', @Object OUT;
EXEC sp_OAMethod @Object, 'open', NULL, 'get',
                 @Url,
                 'false'

EXEC sp_OAMethod @Object, 'setRequestHeader', NULL, 'Content-Type', 'application/json';
EXEC sp_OAMethod @Object, 'send', null, @Api_Key


EXEC sp_OAMethod @Object, 'responseText', @ResponseT OUTPUT

INSERT INTO @Response (Json_Table)
EXEC sp_OAGetProperty @Object, 'responseText'

SELECT  * FROM @Response

EXEC sp_OADestroy @Object 
Dale K
  • 25,246
  • 15
  • 42
  • 71
rkapukaya
  • 77
  • 1
  • 8
  • 5
    t-sql is the wrong tool for this kind of thing. I would roll this into a CLR procedure. – Sean Lange Nov 17 '21 at 20:50
  • Agree with the SQL CLR recommendation. The sp_OA* methods have all sorts of concurrency and portability issues that you don't want. Plus you're not doing any kind of error checking and handling here so you'll never know when things go wrong nor why. – AlwaysLearning Nov 17 '21 at 21:40

0 Answers0