I have this code to meka an API POST request, see attached file:
Log(jsn) = {"summary_score_sorting_direction":"asc","name":"Landing","heading":"Landing","index":1,"autosum_scores":true,"contest":695}
I get this respose = ResponseError. Reason: Bad Request, Response: {"name":["This field is required."],"heading":["This field is required."],"contest":["This field is required."]}
B4X:
Private Sub PostResTasks(Index As Int, ConId As Int)
Dim job As HttpJob
Dim Data As String
Dim Map2 As Map
Dim jsn As String
Dim gen As JSONGenerator
job.Initialize("", Me)
Map2.Initialize
Map2.Put("summary_score_sorting_direction", "asc")
Map2.Put("name", "Landing")
Map2.Put("heading", "Landing")
Map2.Put("index", Index)
Map2.Put("autosum_scores", True)
Map2.Put("contest", ConId)
gen.Initialize(Map2)
jsn = gen.ToString
Log(jsn)
job.PostString(Starter.strURL & "contests/" & ConId & "/tasks/", jsn)
job.GetRequest.SetHeader("Authorization", "Token " & Starter.gToken)
Wait For (job) JobDone(job As HttpJob)
If job.Success Then
Data = job.GetString
Log(Data)
Else
Log("Something wrong")
End If
End Sub
Log(jsn) = {"summary_score_sorting_direction":"asc","name":"Landing","heading":"Landing","index":1,"autosum_scores":true,"contest":695}
I get this respose = ResponseError. Reason: Bad Request, Response: {"name":["This field is required."],"heading":["This field is required."],"contest":["This field is required."]}