SQL-APIConsumer icon indicating copy to clipboard operation
SQL-APIConsumer copied to clipboard

Values not POSTing. Please help.

Open neo302 opened this issue 3 years ago • 0 comments

Hello,

For some reason I can't get the JSON values to post to a basic Net Core API.
I've tried the different methods APICaller_Web_Extended, APICaller_POST_Extended, etc., but still can't get the value to post to the API as I get an immediate reject. Can someone please help?

DECLARE @httpMethod nvarchar(max) = 'POST' DECLARE @URL nvarchar(max) = 'https://localhost:42368/api/myapi' DECLARE @Headers nvarchar(max) = '[{ "Name": "Content-Type", "Value" :"application/json; charset=utf-8" }]'; Declare @cJSONbody NVARCHAR(MAX) = '{ "astring": "Foo" }' exec [dbo].[APICaller_POST_Extended]
@URL ,@Headers ,@JsonBody = @cJSONbody

API: [HttpPost] public async Task<ActionResult> myapi(string astring) { try { var j = astring; //....
return Ok("OK"); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, "Database Failure"); } }

Error Result: {"type":"https://tools.ietf.org/html/rfc7231#section-6.5.1","title":"One or more validation errors occurred.","status":400,"traceId":"00-ebe41ad40e4609a7ba247b3c55687ca7-b98e61eaac0c50b3-00","errors":{"astring":["The astring field is required."]}}

ContentType: application/problem+json; charset=utf-8

neo302 avatar Dec 25 '22 05:12 neo302