Post

3 followers Follow
0
Avatar

Create a new item - Error is 'An unexpected error occured during execution'

I am trying to create a new item in my app but getting

(i) 'Internal Server Error' in response.StatusDescription 

(ii) 'InternalServerError' in response.StatusCode and 

(iii) '{"error_propagate":false,"error_parameters":{},"error_detail":null,"error_description":"An unexpected error occured during execution","error":"unexpected"} in response.Content

Here is code.

var client = new RestClient(" https://api.podio.com/"); 

var request = new RestRequest(); 

request.Method = Method.POST; 

request.RequestFormat = DataFormat.Json;

request.AddParameter("oauth_token", token); 

request.Resource = "item/app/2161028//"; 

request.AddBody(request.JsonSerializer.Serialize( 

new 



title = "TITLE 1"

}));

var response = client.Execute<OauthToken>(request);

Please note, there is only one field 'Title' in this app.

Please help me in this regard.

Thanks,

-Shahid

Shahid Sheraz Answered

Please sign in to leave a comment.

13 comments

0
Avatar

What is the raw HTTP request (headers and body) and the raw HTTP response (http body)?

Andreas Haugstrup Pedersen 0 votes
0
Avatar

Can you please send me a code sample? I would love if it uses raw http sample.

Shahid Sheraz 0 votes
0
Avatar

The tutorial I linked above has the raw HTTP body needed. Another thing that could be wrong is that RestSharp could be sending your body as HTTP query parameters instead of sending them in the http body. You will need to debug your own code to figure out if that is the case.

Andreas Haugstrup Pedersen 0 votes
0
Avatar

And if the problem is about having a HTTP body, so exception should be specific to the problem instead of having a general statement like 'Internal Server Error'.

Shahid Sheraz 0 votes
0
Avatar

I agree we need a better error message for this case, but first we need to figure out what you are doing wrong. Can you please provide the raw http request that fails?

Casper Fabricius 0 votes
0
Avatar

Hi Casper,

I have given the code above as I am using RestSharp. Please have a look on that code.

Thanks,

Shahid

Shahid Sheraz 0 votes
0
Avatar

I'll recommend you don't use Restsharp for creating items, I've never been able to get that working myself. If you want support on this, you will have to provide the actual raw http request you do to the API, not just the C# code, since we can't tell anything from that.

We are collaborating with Kasper on .NET API client, and it should support creating items very soon. I'll recommend you wait for this instead of spending more time on Restsharp.

Casper Fabricius 0 votes
0
Avatar
0
Avatar

FYI the internal server error should be fixed; you'll now get a 404 Not Found (though perhaps a 400 Bad request is more appropriate) with error_description "No matching operation could be found. No body was given."

George 0 votes
0
Avatar

I ran into this issue as well recently and have a workaround for RestSharp v 104.1.

Below is a working example that calls add item.  The key is that you cannot use the RestRequest.AddParameter method to add query parameters such as your access token.  You must add it to the resource URL string instead.  The underlying problem is that RestSharp will not allow parameters to be added in coordination with a body.  The API will just strip the body which is why Podio rejects the API call indicating that no body was given. You can use an app like Fiddler to sniff your packets and troubleshoot to see this in action.

var request = new RestRequest("/item/app/" + appID + "//" + "?oauth_token=" + authToken.AccessToken, Method.POST);

request.RequestFormat = DataFormat.Json;

// DO NOT  request.AddParameter("oauth_token", authToken.AccessToken);

request.AddParameter("application/json; charset=utf-8", itemBody, ParameterType.RequestBody);

Andrew Roberts 0 votes