imRohan/Pantry

I created a library to use Pantry from .Net

Closed this issue · 1 comments

https://github.com/Krutonium/libPantryDotNet

The issue is that I can't seem to get any data it sends to work.

My programs output is as follows (With commentary from me)

{"Item1":"item1","Item2":"1"} //This is the json I am sending
Your pantry is called TestPantry 
Your pantry is 1% full.
You have 1 baskets.
Your Baskets:
test_basket
Deleting test_basket
test_basket was removed from your Pantry!            //This works
Creating a basket called test_basket                        //This works, but the basket is left empty but should have the json above
Your Pantry was updated with basket: test_basket! //This is direct output from your API
Updating a value in that basket                                //I changed a value, re-encoded it as JSON, and wrote it to the API
{}                                                                               //Response from API
Reading back the Basket                                         //Reading it back
{}                                                                               //Still nothing

I cannot figure out why it's not getting the JSON. Any thoughts?
This is the code that's running to generate that output and this is the code that's doing the actual requests

@Krutonium Awesome work, I'd love to include your library here one day once you're done!

While I'm not too familiar with .NET a few things did stick out when I was looking at the request logic.

I have a hunch that the POST request (used to create a new basket) needs to have a Content-Type header added to it for things to work as intended. Also, the content itself may need to be parsed a certain way?

I'm not 100% sure if that's the fix but I hope that helps?

Here's a snippet (C#) that creates a basket and logs the response

var client = new RestClient("https://getpantry.cloud/apiv1/pantry/YOUR_PANTRY_ID/basket/YOUR_BASKET_NAME");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
var body = @"{" + "\n" +
@"	""derp"": ""flerp123""," + "\n" +
@"	""testPayload"": true," + "\n" +
@"	""keysLength"": 3" + "\n" +
@"}";
request.AddParameter("application/json", body,  ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);