API Call Returns XML instead of JSON

Comments

7 comments

  • Avatar
    Sam Ovenshine

    Hi David,

    Just tried that call in Postman and Python (with the requests module). Got results in JSON in both. Let's see if someone with experience in C# chimes in.

    Sam

    0
    Comment actions Permalink
  • Avatar
    David Oyler

    Thank you for verifying that Sam. 

    0
    Comment actions Permalink
  • Avatar
    Malinda Jepsen

    Sam,

    I have some experience with the API in C# and have not run across this one. How are you doing your security?  If you can shoot me some code I can try to take a look.  I use LINQPad to test my calls out before putting them into code, so I can try that. 

    This is how we set up our request. 

    string token = JWT.JsonWebToken.Encode(payload, "<yourAPIKeyHere>", JWT.JwtHashAlgorithm.HS256); 
    WebClient _client = new WebClient();

    _client.Headers["X-API-KEY"] = token;

    responseString = _client.DownloadString("<http call>");
    Console.WriteLine(responseString);

     

    1
    Comment actions Permalink
  • Avatar
    David Oyler

    Melinda;

    I'm currently doing it like this:

    Dim client = New RestClient(String.Format("https://serverAddress/api/elasticubes/servers/{0}/status", server))
    Dim request = New RestRequest(Method.GET)
    request.AddHeader("cache-control", "no-cache")
    request.AddHeader("authorization", Convert.ToString("Bearer ") & token)
    request.AddHeader("accept", "application/json")
    Dim response As IRestResponse = client.Execute(request)

    0
    Comment actions Permalink
  • Avatar
    Malinda Jepsen

    David,

    The first thing I notice is that we're using a WebClient instead of a RestClient. The other thing we ran into was having to use the JWT library to get our token instead of using "Bearer" in the header. That was an issue early on that we discovered. I'll also add, that when I use our standard authentication for all other calls, I'm getting a 403 Forbidden when I try that endpoint. I haven't had time to look into it any further, but you might want to try the WebClient. If I get some time, I'll try to see if I can get it working in LINQPad.

    Malinda

    0
    Comment actions Permalink
  • Avatar
    David Oyler (Edited )

    Put this in place but get the same as you mentioned above - 403 error.

     

    Dim payload As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
    payload.Add("iat", DateTime.Now)
    payload.Add("sub", "<username>")
    payload.Add("jti", New Guid())

    Dim lToken As String = JWT.JsonWebToken.Encode(payload, "<apiKey>", JWT.JwtHashAlgorithm.HS256)

    Dim wClient As WebClient = New WebClient()
    wClient.Headers("X-API-KEY") = lToken
    Dim resp As String = wClient.DownloadString("https://serverAddress/api/elasticubes/servers/localhost/status")

    0
    Comment actions Permalink
  • Avatar
    Malinda Jepsen

    You may want to open a ticket with support if this is a pressing issue.  I'm not sure when I'll have time to dig into it.

    0
    Comment actions Permalink

Please sign in to leave a comment.