API Call Returns XML instead of JSON
I am making a call to api/elasticubes/servers/localhost/status through C#. The call is successful, but the response comes back in XML format. All other calls I make come back in JSON format.
When I make the call through the API reference in Sisense, it returns JSON.
I can make an identical call - same parameters, token etc to api/Elasticubes/metadata and it comes back as JSON, so I know it's not the format of the request.
Has anyone run into this?
-
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); -
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) -
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
-
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")
Please sign in to leave a comment.
Comments
7 comments