Jump to content
Suchin

getting response Text/html rather then JSON body

Recommended Posts

Hello sir,

when we pass parameter on demo account for below link

POST https://ciapi.cityindex.com/TradingAPI/order/newstoplimitorder

And got below response header with status code 200.

StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Cache-Control: private
  Server: Microsoft-IIS/8.5
  X-AspNetMvc-Version: 5.2
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  Date: Mon, 31 Aug 2020 05:52:21 GMT
  Connection: keep-alive
  Content-Type: text/html; charset=utf-8
  Content-Length: 2953
}

Now in content type it is text/html rather then JSON.

we are making programming in C#. we are getting getting difficult to get retrieve the response body is the ApiTradeOrderResponseDTO in JSON format as suggest on gain capital "http://docs.labs.gaincapital.com/index.html#HTTP Services/Order.htm?Highlight=newstoplimitorder".

So please give us solution for this issue.

Share this post


Link to post

Hi Suchin,

The response for an entry order call is coming back as JSON from the server. I'm not sure what your initial call looks like that would return text/html, however the server is returning responses correctly.

Kind Regards, PM

image.png

Share this post


Link to post

I have pass this parameter 

{"UserName":"DC2****",
"Session":"031874cc-a084-4c96-8d06-*******",
    "isTrade":false,
"AutoRollover":false,
"AuditId":"ELU7889-63",
"Currency":null,
"Direction":"buy",
"LastChangedDateTimeUTC":null,
"MarketName":"AUD/CAD",
"BidPrice":0.96372,
"PositionMethodId":1,
"ExpiryDateTimeUTCDate":null,
"Status":null,
"MarketId":401484300,
"LastChangedDateTimeUTCDate":null,
"Reference":null,
"OfferPrice":0.96396,
"TriggerPrice":0.96400,
"OrderId":0,
"Quantity":1,
"QuoteId":null,
"IfDone":[],
"TradingAccountId":40302****,
"OcoOrder":null,
"Type":null,
"Applicability":"GTC",
"ExpiryDateTimeUTC":null}

Share this post


Link to post

Hi Suchin,

In your request Header, have you specified the "Content-Type" to be "application/json"?

image.png

 

As a side note: although this does not affect the response type your request will fail as your order size of 1 is below the minimum spot FX size of 1,000. You'll need to send the order size within valid bounds of min/max size.

Kind Regards, PM

Share this post


Link to post

If we same above request make through postman then error give 401 session is invalid.

we also tried using C# as below syntax

var NewOrder = new newstoplimitorder() { UserName = "DC*****", Session = user.Session };
                            NewOrder.isTrade = false;
                            NewOrder.AutoRollover = false;
                            NewOrder.AuditId = "LU22344697";
                            NewOrder.Currency = "USD";
                            NewOrder.LastChangedDateTimeUTC = null;
                            NewOrder.MarketName = "AUD/CAD";
                            NewOrder.BidPrice = 0.948050;
                            NewOrder.PositionMethodId = 1;
                            NewOrder.Direction = "buy";
                            NewOrder.ExpiryDateTimeUTCDate = null;
                            NewOrder.Status = null;
                            NewOrder.MarketId = 401484300;
                            NewOrder.LastChangedDateTimeUTCDate = null;
                            NewOrder.Reference = null;
                            NewOrder.OfferPrice = 0.948310;
                            NewOrder.TriggerPrice = 0.948500;
                            NewOrder.OrderId = null;
                            NewOrder.Quantity = 1005;
                            NewOrder.QuoteId = null;
                            NewOrder.IfDone = false;
                            NewOrder.TradingAccountId = ******;
                            NewOrder.OcoOrder = null;
                            NewOrder.Type = null;
                            NewOrder.Applicability = "GTC";
                            NewOrder.ExpiryDateTimeUTC = null;


                            sURL = sMainURL + "order/newstoplimitorder";
                            var postNewOrder = client.PostAsJsonAsync<newstoplimitorder>(sMainURL, NewOrder);
                            postNewOrder.Wait();


                            HttpResponseMessage responseNewOrder = postNewOrder.Result;
                            //HttpResponseHeader responsemsg = new HttpResponseHeader();
                            //responsemsg = responseNewOrder.TrailingHeaders;
                            if (responseNewOrder.IsSuccessStatusCode)
                            {
                                object responseContentNewOrder = await responseNewOrder.Content.ReadAsAsync<object>();

}
 

-- So please suggest us with full example hoe to place new order. with its full request body and formate. also if possible using .Net C#.

we tried lots of time with chnage in various parameter values but not getting success

 

response.png

Share this post


Link to post

Unable to place new trade order via postman.

please share us full information on this if any body have done this or admin can support this on this issue.NewTrade.thumb.jpg.bcc2f0b80e76355dc058240d48c12a7e.jpg

Share this post


Link to post

Hi Suchin,

From the error message, are you passing the authentication message through with your call in the headers? Every call sent through the API must contain the authentication of your accoutn username and the login session you receive back in reponse to the login request. For eample, your trade request header should have the following:

image.png

 

Kind Regards, PM

Share this post


Link to post

Thanks for above reply with this update we got order id. as we are passing username,session,content-type in body so we changed it to Headers and we got response with order Id.

Now we are trying this to make call from .Net C#.

Can you suggest how to pass header parameter from it??

Share this post


Link to post

Hi Suchin,

Glad to hear the error code 401 is now resolved. 

Unfortunately, we are not able to provide assistance in C#.Net coding. 

Kind Regards, PM

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×