microsoft / sql-server-samples

Azure Data SQL Samples - Official Microsoft GitHub Repository containing code samples for SQL Server, Azure SQL, Azure Synapse, and Azure SQL Edge
Other
9.77k stars 8.79k forks source link

Calling Http endpoints in T-SQL using CURL extension - Content Type. #1197

Open Pieter3033 opened 11 months ago

Pieter3033 commented 11 months ago

In regards to : https://github.com/microsoft/sql-server-samples](https://github.com/Microsoft/sql-server-samples/tree/master/samples/features/sql-clr/Curl)

What is the Content Type of the CURL.XPOST procedure, I need it to be application/json.

I am unable to locate where it mentions what the Content Type is in the source code.

See below for reference:

Curl Syntax:

curl \
  -X POST \
  -H "Content-Type: application/json" \
  -H "simcontrol-api-key: YOUR_API_KEY" \
  --data '{ "query": "{ account { name balance } }" }' \
  https://app.simcontrol.co.za/graphql/

My CURL.XPOST procedure:


declare @hkey nvarchar(200) = N'Content-Type: application/json/simcontrol-api-key: My-Key';
declare @body nvarchar(4000) = N'{ "query": "{ account { name balance } }" }'
declare @endpoint nvarchar(1000) = N'https://app.simcontrol.co.za/graphql/';

exec curl.XPOST @H = @hkey, @d = @body, @url = @endpoint
```;
mcoPCE commented 2 months ago

Need to do the same thing here. Looks like you're at least missing a delimiter in your header string, I'm just not sure what that delimiter should be. I tried introducing newline characters like: declare @hkey nvarchar(200) = N'Authorization: Bearer 12341234' + CHAR(10) + 'Accept: application/json'; and declare @hkey nvarchar(200) = N'Authorization: Bearer 12341234' + CHAR(13) + 'Accept: application/json';

Those did not work and I got an error: System.ArgumentException: Specified value has invalid CRLF characters.