Hi,
I am currently having a problem adding a model to a user's cart on my website. When I reach the request.GetResponse() line, I receive an internal server error from the API.
The code I'm using is posted below. It's based off the code posted on the Github site.
I've verified that the JSON is valid and I am using model #835118 which is used in this example:
https://www.shapeways.com/tutorials/shoppingcart
I'm not exactly sure where I'm going wrong with this - any help would be appreciated. If you need any more information please let me know.
Code:
public object AddShoppingCartItem(int modelID, int materialID, int quantity = 1)
{
OAuthRequest client = new OAuthRequest()
{
Method = "POST",
Type = OAuthRequestType.ProtectedResource,
SignatureMethod = OAuthSignatureMethod.HmacSha1,
ConsumerKey = this.consumerKey,
ConsumerSecret = this.consumerSecret,
RequestUrl = "https://api.shapeways.com/orders/cart/v1",
Version = "1.0a",
Realm = "shapeways.com",
TokenSecret = this.OAuthSecret,
Token = this.OAuthToken
};
string auth = client.GetAuthorizationQuery();
string requestUrl = client.RequestUrl + "?" + auth;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUrl);
request.ContentType = "application/json; charset=utf-8";
request.Method = "POST";
CartItem cartItem = new CartItem
{
materialId = materialID,
modelId = modelID,
quantity = quantity
};
using(StreamWriter writer = new StreamWriter(request.GetRequestStream()))
{
string json = JsonConvert.SerializeObject(cartItem);
writer.Write(json);
writer.Flush();
writer.Close();
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string content = new StreamReader(response.GetResponseStream()).ReadToEnd();
return JsonConvert.DeserializeObject(content);
}
Last edited: Mar 16, 2014