passing using the same uri paramater, getting two different outcomes
up vote
1
down vote
favorite
I am trying to get a list of 100 help desk tickets from an API. the url is below.
https://sdpondemand.manageengine.com/app/itdesk/api/v3/requests?input_data={"list_Info":{"row_count":100,"start_index":101}}
I am able to produce successful results, meaning it brings back 100 rows starting at index 101, when I put the uri into a string like this:
string extra = "app/itdesk/api/v3/requests?input_data={"list_info":{"row_count":100,"start_index":101}}";
but if I try to put the json into classes, then serialize it with the Json.Net library, it will fail, meaning it brings back just 10 rows on index 1.
private class input_data
{
public list_info list_Info = new list_info();
}
private class list_info
{
public int row_count = 100;
public int start_index = 101;
}
input_data input = new input_data();
string json = Newtonsoft.Json.JsonConvert.SerializeObject(input);
string extra1 ="app/itdesk/api/v3/requests?input_data="+json;
I look at both of the request coming out an there exactly the same. what am I doing wrong?
what the vars look like in the code
extra: app/itdesk/api/v3/requests?input_data={"list_info":{"row_count":100,"start_index":101}}
extra1: app/itdesk/api/v3/requests?input_data={"list_Info":{"row_count":100,"start_index":101}}
c# json rest
|
show 1 more comment
up vote
1
down vote
favorite
I am trying to get a list of 100 help desk tickets from an API. the url is below.
https://sdpondemand.manageengine.com/app/itdesk/api/v3/requests?input_data={"list_Info":{"row_count":100,"start_index":101}}
I am able to produce successful results, meaning it brings back 100 rows starting at index 101, when I put the uri into a string like this:
string extra = "app/itdesk/api/v3/requests?input_data={"list_info":{"row_count":100,"start_index":101}}";
but if I try to put the json into classes, then serialize it with the Json.Net library, it will fail, meaning it brings back just 10 rows on index 1.
private class input_data
{
public list_info list_Info = new list_info();
}
private class list_info
{
public int row_count = 100;
public int start_index = 101;
}
input_data input = new input_data();
string json = Newtonsoft.Json.JsonConvert.SerializeObject(input);
string extra1 ="app/itdesk/api/v3/requests?input_data="+json;
I look at both of the request coming out an there exactly the same. what am I doing wrong?
what the vars look like in the code
extra: app/itdesk/api/v3/requests?input_data={"list_info":{"row_count":100,"start_index":101}}
extra1: app/itdesk/api/v3/requests?input_data={"list_Info":{"row_count":100,"start_index":101}}
c# json rest
why are you passing the class object in the querystring? This is the worst implementation of get request according to the documentation.
– Hassaan
Nov 9 at 16:17
then how does one correctly do it?
– Franco Pettigrosso
Nov 9 at 16:29
is this api implemented by you?
– Hassaan
Nov 9 at 16:38
no, I am following the manage engines API manageengine.com/products/service-desk/sdpod-v3-api/…
– Franco Pettigrosso
Nov 9 at 17:40
please see the documentation input_data is supposed to in a post or put request, you need to change the calling
– Hassaan
Nov 9 at 18:00
|
show 1 more comment
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I am trying to get a list of 100 help desk tickets from an API. the url is below.
https://sdpondemand.manageengine.com/app/itdesk/api/v3/requests?input_data={"list_Info":{"row_count":100,"start_index":101}}
I am able to produce successful results, meaning it brings back 100 rows starting at index 101, when I put the uri into a string like this:
string extra = "app/itdesk/api/v3/requests?input_data={"list_info":{"row_count":100,"start_index":101}}";
but if I try to put the json into classes, then serialize it with the Json.Net library, it will fail, meaning it brings back just 10 rows on index 1.
private class input_data
{
public list_info list_Info = new list_info();
}
private class list_info
{
public int row_count = 100;
public int start_index = 101;
}
input_data input = new input_data();
string json = Newtonsoft.Json.JsonConvert.SerializeObject(input);
string extra1 ="app/itdesk/api/v3/requests?input_data="+json;
I look at both of the request coming out an there exactly the same. what am I doing wrong?
what the vars look like in the code
extra: app/itdesk/api/v3/requests?input_data={"list_info":{"row_count":100,"start_index":101}}
extra1: app/itdesk/api/v3/requests?input_data={"list_Info":{"row_count":100,"start_index":101}}
c# json rest
I am trying to get a list of 100 help desk tickets from an API. the url is below.
https://sdpondemand.manageengine.com/app/itdesk/api/v3/requests?input_data={"list_Info":{"row_count":100,"start_index":101}}
I am able to produce successful results, meaning it brings back 100 rows starting at index 101, when I put the uri into a string like this:
string extra = "app/itdesk/api/v3/requests?input_data={"list_info":{"row_count":100,"start_index":101}}";
but if I try to put the json into classes, then serialize it with the Json.Net library, it will fail, meaning it brings back just 10 rows on index 1.
private class input_data
{
public list_info list_Info = new list_info();
}
private class list_info
{
public int row_count = 100;
public int start_index = 101;
}
input_data input = new input_data();
string json = Newtonsoft.Json.JsonConvert.SerializeObject(input);
string extra1 ="app/itdesk/api/v3/requests?input_data="+json;
I look at both of the request coming out an there exactly the same. what am I doing wrong?
what the vars look like in the code
extra: app/itdesk/api/v3/requests?input_data={"list_info":{"row_count":100,"start_index":101}}
extra1: app/itdesk/api/v3/requests?input_data={"list_Info":{"row_count":100,"start_index":101}}
c# json rest
c# json rest
edited Nov 9 at 15:29
gunr2171
7,401104466
7,401104466
asked Nov 9 at 15:26
Franco Pettigrosso
1,1911618
1,1911618
why are you passing the class object in the querystring? This is the worst implementation of get request according to the documentation.
– Hassaan
Nov 9 at 16:17
then how does one correctly do it?
– Franco Pettigrosso
Nov 9 at 16:29
is this api implemented by you?
– Hassaan
Nov 9 at 16:38
no, I am following the manage engines API manageengine.com/products/service-desk/sdpod-v3-api/…
– Franco Pettigrosso
Nov 9 at 17:40
please see the documentation input_data is supposed to in a post or put request, you need to change the calling
– Hassaan
Nov 9 at 18:00
|
show 1 more comment
why are you passing the class object in the querystring? This is the worst implementation of get request according to the documentation.
– Hassaan
Nov 9 at 16:17
then how does one correctly do it?
– Franco Pettigrosso
Nov 9 at 16:29
is this api implemented by you?
– Hassaan
Nov 9 at 16:38
no, I am following the manage engines API manageengine.com/products/service-desk/sdpod-v3-api/…
– Franco Pettigrosso
Nov 9 at 17:40
please see the documentation input_data is supposed to in a post or put request, you need to change the calling
– Hassaan
Nov 9 at 18:00
why are you passing the class object in the querystring? This is the worst implementation of get request according to the documentation.
– Hassaan
Nov 9 at 16:17
why are you passing the class object in the querystring? This is the worst implementation of get request according to the documentation.
– Hassaan
Nov 9 at 16:17
then how does one correctly do it?
– Franco Pettigrosso
Nov 9 at 16:29
then how does one correctly do it?
– Franco Pettigrosso
Nov 9 at 16:29
is this api implemented by you?
– Hassaan
Nov 9 at 16:38
is this api implemented by you?
– Hassaan
Nov 9 at 16:38
no, I am following the manage engines API manageengine.com/products/service-desk/sdpod-v3-api/…
– Franco Pettigrosso
Nov 9 at 17:40
no, I am following the manage engines API manageengine.com/products/service-desk/sdpod-v3-api/…
– Franco Pettigrosso
Nov 9 at 17:40
please see the documentation input_data is supposed to in a post or put request, you need to change the calling
– Hassaan
Nov 9 at 18:00
please see the documentation input_data is supposed to in a post or put request, you need to change the calling
– Hassaan
Nov 9 at 18:00
|
show 1 more comment
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
Passing serialized DTO object in the Get request is not the proper way of implementing an API. Get request supposed to be having params rather than a serialize object. If you wish to do so and have to send an object then why not using a post request.
The sample implementation for a rest api could be as:
Via GET
[Route("{rowCount}/{startIndex}"), HttpGet]
public IHttpActionResult Get(int rowCount, int startIndex)
{
//Your logic Implementation
}
calling would be like
www.xyz.com/controllerName/100/101
This is the rest implementation of the request
Via POST
[Route(""), HttpPost]
public IHttpActionResult Post([FromBody]YourDTOClass obj)
{
//Your logic Implementation
}
For example you have the DTO class
//In C# the class name should be capital
private class ListInfo
{
//In c# the property name should be Capital
public int RowCount {get; set;} = 100;
public int StartIndex {get; set;}= 101;
}
So your Post method would look like
//Route attribute is for configuring the custom route
//It is a feature in MVC 5
//FromBody attribute will search for data in the request body
[Route(""), HttpPost]
public IHttpActionResult Post([FromBody]ListInfo info)
{
//Your logic Implementation
}
If you are using the C# for calling the API too, then you could use HttpClient
where passing the json object of your class a data.
Edited: As you are using a third party API, therefore you need to correct the calling.
using (var client = new HttpClient())
{
//Setting the base address of the server
client.BaseAddress = new Uri("https://sdpondemand.manageengine.com");
//creating an anonymous object
var jsonObject = new {
input_data = new {
row_count = 100,
start_index = 101
}
};
//Converting into the content string
var content = new StringContent(JsonConvert.SerializeObject(jsonObject), Encoding.UTF8, "application/json");
//waiting for the post request to complete
var result = await client.PostAsync("app/itdesk/api/v3/requests", content);
//reading the response string
string resultContent = await result.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
//Deserialize your string into custom object here
var obj = JsonConvert.DeserializeObject<YourDTO>(resultContent);
}
else
{
//Todo: Log the Exception here
throw new Exception(contentString);
}
}
add a comment |
up vote
0
down vote
extra : app/itdesk/api/v3/requests?input_data={"list_info"{"row_count":100,"start_index":101}}
extra1:app/itdesk/api/v3/requests?input_data={"list_Info":{"row_count":100,"start_index":101}}
messed up the list info
extra : app/itdesk/api/v3/requests?input_data={"list_info"{"row_count":100,"start_index":101}}
extra1:app/itdesk/api/v3/requests?input_data={"list_info":{"row_count":100,"start_index":101}}
[shrug emoji]
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Passing serialized DTO object in the Get request is not the proper way of implementing an API. Get request supposed to be having params rather than a serialize object. If you wish to do so and have to send an object then why not using a post request.
The sample implementation for a rest api could be as:
Via GET
[Route("{rowCount}/{startIndex}"), HttpGet]
public IHttpActionResult Get(int rowCount, int startIndex)
{
//Your logic Implementation
}
calling would be like
www.xyz.com/controllerName/100/101
This is the rest implementation of the request
Via POST
[Route(""), HttpPost]
public IHttpActionResult Post([FromBody]YourDTOClass obj)
{
//Your logic Implementation
}
For example you have the DTO class
//In C# the class name should be capital
private class ListInfo
{
//In c# the property name should be Capital
public int RowCount {get; set;} = 100;
public int StartIndex {get; set;}= 101;
}
So your Post method would look like
//Route attribute is for configuring the custom route
//It is a feature in MVC 5
//FromBody attribute will search for data in the request body
[Route(""), HttpPost]
public IHttpActionResult Post([FromBody]ListInfo info)
{
//Your logic Implementation
}
If you are using the C# for calling the API too, then you could use HttpClient
where passing the json object of your class a data.
Edited: As you are using a third party API, therefore you need to correct the calling.
using (var client = new HttpClient())
{
//Setting the base address of the server
client.BaseAddress = new Uri("https://sdpondemand.manageengine.com");
//creating an anonymous object
var jsonObject = new {
input_data = new {
row_count = 100,
start_index = 101
}
};
//Converting into the content string
var content = new StringContent(JsonConvert.SerializeObject(jsonObject), Encoding.UTF8, "application/json");
//waiting for the post request to complete
var result = await client.PostAsync("app/itdesk/api/v3/requests", content);
//reading the response string
string resultContent = await result.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
//Deserialize your string into custom object here
var obj = JsonConvert.DeserializeObject<YourDTO>(resultContent);
}
else
{
//Todo: Log the Exception here
throw new Exception(contentString);
}
}
add a comment |
up vote
1
down vote
accepted
Passing serialized DTO object in the Get request is not the proper way of implementing an API. Get request supposed to be having params rather than a serialize object. If you wish to do so and have to send an object then why not using a post request.
The sample implementation for a rest api could be as:
Via GET
[Route("{rowCount}/{startIndex}"), HttpGet]
public IHttpActionResult Get(int rowCount, int startIndex)
{
//Your logic Implementation
}
calling would be like
www.xyz.com/controllerName/100/101
This is the rest implementation of the request
Via POST
[Route(""), HttpPost]
public IHttpActionResult Post([FromBody]YourDTOClass obj)
{
//Your logic Implementation
}
For example you have the DTO class
//In C# the class name should be capital
private class ListInfo
{
//In c# the property name should be Capital
public int RowCount {get; set;} = 100;
public int StartIndex {get; set;}= 101;
}
So your Post method would look like
//Route attribute is for configuring the custom route
//It is a feature in MVC 5
//FromBody attribute will search for data in the request body
[Route(""), HttpPost]
public IHttpActionResult Post([FromBody]ListInfo info)
{
//Your logic Implementation
}
If you are using the C# for calling the API too, then you could use HttpClient
where passing the json object of your class a data.
Edited: As you are using a third party API, therefore you need to correct the calling.
using (var client = new HttpClient())
{
//Setting the base address of the server
client.BaseAddress = new Uri("https://sdpondemand.manageengine.com");
//creating an anonymous object
var jsonObject = new {
input_data = new {
row_count = 100,
start_index = 101
}
};
//Converting into the content string
var content = new StringContent(JsonConvert.SerializeObject(jsonObject), Encoding.UTF8, "application/json");
//waiting for the post request to complete
var result = await client.PostAsync("app/itdesk/api/v3/requests", content);
//reading the response string
string resultContent = await result.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
//Deserialize your string into custom object here
var obj = JsonConvert.DeserializeObject<YourDTO>(resultContent);
}
else
{
//Todo: Log the Exception here
throw new Exception(contentString);
}
}
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Passing serialized DTO object in the Get request is not the proper way of implementing an API. Get request supposed to be having params rather than a serialize object. If you wish to do so and have to send an object then why not using a post request.
The sample implementation for a rest api could be as:
Via GET
[Route("{rowCount}/{startIndex}"), HttpGet]
public IHttpActionResult Get(int rowCount, int startIndex)
{
//Your logic Implementation
}
calling would be like
www.xyz.com/controllerName/100/101
This is the rest implementation of the request
Via POST
[Route(""), HttpPost]
public IHttpActionResult Post([FromBody]YourDTOClass obj)
{
//Your logic Implementation
}
For example you have the DTO class
//In C# the class name should be capital
private class ListInfo
{
//In c# the property name should be Capital
public int RowCount {get; set;} = 100;
public int StartIndex {get; set;}= 101;
}
So your Post method would look like
//Route attribute is for configuring the custom route
//It is a feature in MVC 5
//FromBody attribute will search for data in the request body
[Route(""), HttpPost]
public IHttpActionResult Post([FromBody]ListInfo info)
{
//Your logic Implementation
}
If you are using the C# for calling the API too, then you could use HttpClient
where passing the json object of your class a data.
Edited: As you are using a third party API, therefore you need to correct the calling.
using (var client = new HttpClient())
{
//Setting the base address of the server
client.BaseAddress = new Uri("https://sdpondemand.manageengine.com");
//creating an anonymous object
var jsonObject = new {
input_data = new {
row_count = 100,
start_index = 101
}
};
//Converting into the content string
var content = new StringContent(JsonConvert.SerializeObject(jsonObject), Encoding.UTF8, "application/json");
//waiting for the post request to complete
var result = await client.PostAsync("app/itdesk/api/v3/requests", content);
//reading the response string
string resultContent = await result.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
//Deserialize your string into custom object here
var obj = JsonConvert.DeserializeObject<YourDTO>(resultContent);
}
else
{
//Todo: Log the Exception here
throw new Exception(contentString);
}
}
Passing serialized DTO object in the Get request is not the proper way of implementing an API. Get request supposed to be having params rather than a serialize object. If you wish to do so and have to send an object then why not using a post request.
The sample implementation for a rest api could be as:
Via GET
[Route("{rowCount}/{startIndex}"), HttpGet]
public IHttpActionResult Get(int rowCount, int startIndex)
{
//Your logic Implementation
}
calling would be like
www.xyz.com/controllerName/100/101
This is the rest implementation of the request
Via POST
[Route(""), HttpPost]
public IHttpActionResult Post([FromBody]YourDTOClass obj)
{
//Your logic Implementation
}
For example you have the DTO class
//In C# the class name should be capital
private class ListInfo
{
//In c# the property name should be Capital
public int RowCount {get; set;} = 100;
public int StartIndex {get; set;}= 101;
}
So your Post method would look like
//Route attribute is for configuring the custom route
//It is a feature in MVC 5
//FromBody attribute will search for data in the request body
[Route(""), HttpPost]
public IHttpActionResult Post([FromBody]ListInfo info)
{
//Your logic Implementation
}
If you are using the C# for calling the API too, then you could use HttpClient
where passing the json object of your class a data.
Edited: As you are using a third party API, therefore you need to correct the calling.
using (var client = new HttpClient())
{
//Setting the base address of the server
client.BaseAddress = new Uri("https://sdpondemand.manageengine.com");
//creating an anonymous object
var jsonObject = new {
input_data = new {
row_count = 100,
start_index = 101
}
};
//Converting into the content string
var content = new StringContent(JsonConvert.SerializeObject(jsonObject), Encoding.UTF8, "application/json");
//waiting for the post request to complete
var result = await client.PostAsync("app/itdesk/api/v3/requests", content);
//reading the response string
string resultContent = await result.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
//Deserialize your string into custom object here
var obj = JsonConvert.DeserializeObject<YourDTO>(resultContent);
}
else
{
//Todo: Log the Exception here
throw new Exception(contentString);
}
}
edited Nov 9 at 18:11
answered Nov 9 at 17:32
Hassaan
1,75092149
1,75092149
add a comment |
add a comment |
up vote
0
down vote
extra : app/itdesk/api/v3/requests?input_data={"list_info"{"row_count":100,"start_index":101}}
extra1:app/itdesk/api/v3/requests?input_data={"list_Info":{"row_count":100,"start_index":101}}
messed up the list info
extra : app/itdesk/api/v3/requests?input_data={"list_info"{"row_count":100,"start_index":101}}
extra1:app/itdesk/api/v3/requests?input_data={"list_info":{"row_count":100,"start_index":101}}
[shrug emoji]
add a comment |
up vote
0
down vote
extra : app/itdesk/api/v3/requests?input_data={"list_info"{"row_count":100,"start_index":101}}
extra1:app/itdesk/api/v3/requests?input_data={"list_Info":{"row_count":100,"start_index":101}}
messed up the list info
extra : app/itdesk/api/v3/requests?input_data={"list_info"{"row_count":100,"start_index":101}}
extra1:app/itdesk/api/v3/requests?input_data={"list_info":{"row_count":100,"start_index":101}}
[shrug emoji]
add a comment |
up vote
0
down vote
up vote
0
down vote
extra : app/itdesk/api/v3/requests?input_data={"list_info"{"row_count":100,"start_index":101}}
extra1:app/itdesk/api/v3/requests?input_data={"list_Info":{"row_count":100,"start_index":101}}
messed up the list info
extra : app/itdesk/api/v3/requests?input_data={"list_info"{"row_count":100,"start_index":101}}
extra1:app/itdesk/api/v3/requests?input_data={"list_info":{"row_count":100,"start_index":101}}
[shrug emoji]
extra : app/itdesk/api/v3/requests?input_data={"list_info"{"row_count":100,"start_index":101}}
extra1:app/itdesk/api/v3/requests?input_data={"list_Info":{"row_count":100,"start_index":101}}
messed up the list info
extra : app/itdesk/api/v3/requests?input_data={"list_info"{"row_count":100,"start_index":101}}
extra1:app/itdesk/api/v3/requests?input_data={"list_info":{"row_count":100,"start_index":101}}
[shrug emoji]
answered Nov 9 at 16:04
Franco Pettigrosso
1,1911618
1,1911618
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228611%2fpassing-using-the-same-uri-paramater-getting-two-different-outcomes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
why are you passing the class object in the querystring? This is the worst implementation of get request according to the documentation.
– Hassaan
Nov 9 at 16:17
then how does one correctly do it?
– Franco Pettigrosso
Nov 9 at 16:29
is this api implemented by you?
– Hassaan
Nov 9 at 16:38
no, I am following the manage engines API manageengine.com/products/service-desk/sdpod-v3-api/…
– Franco Pettigrosso
Nov 9 at 17:40
please see the documentation input_data is supposed to in a post or put request, you need to change the calling
– Hassaan
Nov 9 at 18:00