Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Pieter3033 opened this issue Aug 11, 2023 · 1 comment
Open

Comments

@Pieter3033
Copy link

Pieter3033 commented Aug 11, 2023

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
Copy link

mcoPCE commented May 14, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants