Skip to content

Instantly share code, notes, and snippets.

@gwokudasam
Forked from theorigin/SQLServer-APIPost.sql
Created August 18, 2017 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gwokudasam/b9cf8059472f35de04b6e2f443a91544 to your computer and use it in GitHub Desktop.
Save gwokudasam/b9cf8059472f35de04b6e2f443a91544 to your computer and use it in GitHub Desktop.
SQL Server code to POST to an API
DECLARE @Object AS INT;
DECLARE @ResponseText AS VARCHAR(8000);
DECLARE @Body AS VARCHAR(8000) =
'{
"what": 1,
"ever": "you",
"need": "to send as the body"
}'
EXEC sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
EXEC sp_OAMethod @Object, 'open', NULL, 'post','http://requestb.in/1h83e3n1', 'false'
EXEC sp_OAMethod @Object, 'setRequestHeader', null, 'Content-Type', 'application/json'
EXEC sp_OAMethod @Object, 'send', null, @body
EXEC sp_OAMethod @Object, 'responseText', @ResponseText OUTPUT
SELECT @ResponseText
EXEC sp_OADestroy @Object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment