I have a MS SQL script that runs a stored procedure called [Freak_APITest2] - see script code below
DECLARE @LeaderboardName varchar (20)DECLARE @LeaderboardNameFull varchar (20) DECLARE @PlayerCount varchar (20)DECLARE @PlayerName varchar (20)DECLARE @Score nvarchar (20)DECLARE @ZombiesKilled varchar (15)DECLARE @Accuracy varchar (50)DECLARE @DamageTaken varchar (20)DECLARE @SecondsInLevel varchar (30)DECLARE @Deaths varchar (50)SELECT top 1 @LeaderboardName = LeaderboardName from ScoreBoard where date = '2020-02-04 14:04:38.970'SELECT top 1 @LeaderboardNameFull = LeaderboardNameFull from ScoreBoard where date = '2020-02-04 14:04:38.970'SELECT top 1 @PlayerCount = PlayerCount from ScoreBoard where date = '2020-02-04 14:04:38.970' SELECT top 1 @PlayerName = PlayerName from ScoreBoard where date = '2020-02-04 14:04:38.970' SELECT top 1 @Score = Score from ScoreBoard where date = '2020-02-04 14:04:38.970' SELECT top 1 @ZombiesKilled = ZombiesKilled from ScoreBoard where date = '2020-02-04 14:04:38.970' SELECT top 1 @Accuracy = Accuracy from ScoreBoard where date = '2020-02-04 14:04:38.970' SELECT top 1 @DamageTaken = DamageTaken from ScoreBoard where date = '2020-02-04 14:04:38.970' SELECT top 1 @SecondsInLevel = SecondsInLevel from ScoreBoard where date = '2020-02-04 14:04:38.970'SELECT top 1 @Deaths = Deaths from ScoreBoard where date = '2020-02-04 14:04:38.970' EXEC [Freak_APITest2] @LeaderboardName, @LeaderboardNameFull,@PlayerCount, @PlayerName, @Score,@ZombiesKilled,@Accuracy,@DamageTaken,@SecondsInLevel,@Deaths
When I run the above script I get an error message, see below
Status: 422 (Unprocessable Entity)
Response text: {"error":{"type":"INVALID_REQUEST_MISSING_FIELDS","message":"Could not find field \"fields\" in the request body"}}
The stored procedure script code for Freak_APITest2 is below
I don't know why it won't run when the json is formatted correctly. Any support will be greatly appreciated.
Microsoft SQL ServerJSONRESTSQL
Last Comment
Stevie Zakhour
8/22/2022 - Mon
Stevie Zakhour
ASKER
I modified SET @postData = to include casting, see below
SET @postData = '{ "records": [ { "fields": { "LeaderboardName":"'+cast(@LeaderboardName as varchar(20))+'", "LeaderboardNameFull":"'+cast(@LeaderboardNameFull as varchar(20))+'", "PlayerCount": "'+cast(@PlayerCount as varchar(20))+'",, "PlayerName": "'+cast(@PlayerName as varchar(20))+'", "Score": "'+cast(@Score as varchar(20))+'", "ZombiesKilled":"'+cast(@ZombiesKilled as varchar(15))+'", "Accuracy": "'+cast(@Accuracy as varchar(50))+'", "DamageTaken": "'+cast(@DamageTaken as varchar(30))+'", "Deaths": "'+cast(@Deaths as varchar(50))+'" } } ]}'
When I run the stored procedure again I get the error
Status: 422 (Unprocessable Entity)Response text: {"error":{"type":"INVALID_REQUEST_MISSING_FIELDS","message":"Could not find field \"fields\" in the request body"}}
Open in new window
When I run the stored procedure again I get the error
Open in new window
Any help is greatly appreciated