Skip to main content
Answer

REST API Programming: Login Error

  • August 28, 2025
  • 5 replies
  • 65 views

Hey everyone! New to acumatica REST API. Getting this error when trying to simply login using the HTTPClient in MS visual studio:

StatusCode: 415, ReasonPhrase: 'Unsupported Media Type', Version: 1.1, Content: System.Net.Http.StreamContent

Grateful for any assist on this.

Thanks!

Best answer by Dmitrii Naumov

@alandgates it seems you do not convert your logindata to JSON properly

 

Should be like that:

Dim json As String = JsonSerializer.Serialize(logindata)

Dim content As New StringContent(json, Encoding.UTF8, "application/json")

5 replies

Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • August 28, 2025

@alandgates please add the code to review.

Seems like you send the boy with a wrong content type. It should be application/json


  • Author
  • Freshman II
  • August 28, 2025

of course! Though when I add it, now I get a different error.

Code:

            Dim logindata As New Dictionary(Of String, String) From {{"name", "testuser"}, {"password", "Hello1234!"}}
            Dim content As New StringContent(logindata.ToString, Encoding.UTF8, "application/json")
New error:

StatusCode: 400, ReasonPhrase: 'Bad Request'

I suspect that this means I have the json incorrectly formatted.


JSpikowski
Jr Varsity II
Forum|alt.badge.img
  • Jr Varsity II
  • August 28, 2025

How are you handling cookies and auth?


Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • Answer
  • August 28, 2025

@alandgates it seems you do not convert your logindata to JSON properly

 

Should be like that:

Dim json As String = JsonSerializer.Serialize(logindata)

Dim content As New StringContent(json, Encoding.UTF8, "application/json")


  • Author
  • Freshman II
  • August 28, 2025

Dmitri,

That was it! Such a basic oversight on my part. Thank you for the additional set of eyes to look at it.

Alan