Server error 500 when making API call

I’m trying to create feature requests (“posts”) in my feature request website at https://mothsoftware.productlift.dev . I’ve done other API calls with GET so that I know that both the url and the authorisation are okay.

The docs for the API here here:

https://developer.productlift.dev/api/documentation/#posts-POSTapi-v1-posts

The CURL call is the following:

curl --request POST
“{YOUR-PORTAL-URL}/api/v1/posts”
–header “Authorization: Bearer {YOUR_AUTH_KEY}”
–header “Content-Type: application/json”
–header “Accept: application/json”
–data “{
"title": "wtappxutfdqndgpdzljqw",
"description": "t",
"category_id": 7,
"status_id": 9,
"section_id": 7,
"user_id": "2d661045-36c7-369d-b06f-0796825097aa"
}”

Title and description are required, the other fields are optional.

Why does my Xojo code only give me the error 500:

Dim urlConnection As New URLConnection
urlConnection.RequestHeader("Authorization") = Auth
urlConnection.RequestHeader("Content-Type") = "application/json"
urlConnection.RequestHeader("Accept") = "application/json"
Dim apiUrl As String = ProductLiftUrl + "api/v1/posts"

Dim jsonItem As New JSONItem
jsonItem.Value("title") = "test"
jsonItem.Value("description") = "mehr test"
Dim jsonData As String = jsonItem.ToString

urlConnection.SetRequestContent(jsonData, "application/json")
Dim responseText As String = urlConnection.SendSync("POST", apiUrl)

If urlConnection.HTTPStatusCode <> 200 Then
  MessageBox("It wasn't possible to add the new feature. Request failed with status: " + Str(urlConnection.HTTPStatusCode))
  Break
  Return
End If

Check if you get more info from the content:

Dim responseText As String = urlConnection.SendSync("POST", apiUrl)

If urlConnection.HTTPStatusCode <> 200 Then
  MessageBox("It wasn't possible to add the new feature. Request failed with status: " + Str(urlConnection.HTTPStatusCode))
  MessageBox("Response txt: ["+responseText +"]"
  break
  Return
End If

Is this correct?

Or it should be

Dim apiUrl As String = ProductLiftUrl + "/api/v1/posts"

The constant ProductLiftUrl already has the slash: “https://mothsoftware.productlift.dev/

responseText has the value:

{� “message”: "Server Error"�}

Does CURL work or it gets a 500 too?

I haven’t tried to use CURL, yet.

Looks like the server is really avoiding calls (at least at the moment). Not sure how it reacts to improper requests, I hope it does not send a 500 generic fail. 500 usually is not your fault, but the server is reporting “I can’t process your request due to some internal reason” (gateway fail, out of memory, whatever…).

No, the server is working fine because I get results from a GET call fine:

Dim apiUrl As String = ProductLiftUrl + "api/v1/posts"
dim theResult as String = urlConnection.SendSync("GET", apiUrl)

I’ll try the direct CURL call. If this also doesn’t work I’ll contact the support.

By “the server” we don’t say specifically the hardware, more like the hardware + the software, and the software part have some granularity too, as functions 1 to 5 work, but function 6 crashes (as GET works but POST causes an exception and ends reported as error 500)

:+1:t2:

I did the CURLs in Rapid API (formerly Paw). Again the GET works fine and the POST makes an error 500:


I’ve contacted support.

1 Like

Weird.