API Forum

This forum is in read-only mode.
Please refer to our API support in case you have any questions.
We can be reached at api@e-conomic.com
e-conomic API developer forum

REST "cannot be null" problem

0
Hi I am trying to make a C# customers POST and PUT. When i try sending the json i get the following respons: "Term of payment cannot be null. How will your customer know when to pay you?"

But when i try to send the same JSON string in Chrome Advanced REST client it works all fine.

JSON i send:
"{\"customerNumber\":10000000,\"email\":\"my@mail.com\",\"name\":\"My Name\",\"address\":\"My Address 17\",\"zip\":\"9999\",\"city\":\"My city\",\"country\":\"Denmark\",\"currency\":\"DKK\",\"customerGroup\":{\"customerGroupNumber\":11,\"self\":\"https://restapi.e-conomic.com/customer-groups/11\"},\"paymentTerms\":{\"paymentTermsNumber\":4,\"self\":\"https://restapi.e-conomic.com/payment-terms/4\"},\"vatZone\":{\"vatZoneNumber\":1,\"self\":\"https://restapi.e-conomic.com/vat-zones/1\"}}"

I have also tried:
"{'customerNumber':10000000,'email':'my@mail.com','name':'My Name','address':'My Address 17','zip':'9999','city':'My city','country':'Denmark','currency':'DKK','customerGroup':{'customerGroupNumber':11,'self':'https://restapi.e-conomic.com/customer-groups/11'},'paymentTerms':{'paymentTermsNumber':4,'self':'https://restapi.e-conomic.com/payment-terms/4'},'vatZone':{'vatZoneNumber':1,'self':'https://restapi.e-conomic.com/vat-zones/1'}}"

API responce:
"{\"message\":\"Term of payment cannot be null. How will your customer know when to pay you?\",\"errorCode\":\"E04300\",\"developerHint\":\"Inspect validation errors and correct your request.\",\"logId\":\"b099f2a32f278978a4f5ba8b46c4cb8b\",\"httpStatusCode\":400,\"logTime\":\"2015-10-06T12:01:01\"}"

C# code:
using (WebClient APIresponce = new WebClient()) {
APIresponce.Headers.Add("appId", "xxx");
APIresponce.Headers.Add("accessId", "xxx");
APIresponce.Headers.Add("accept", "application/json");
APIresponce.Headers[HttpRequestHeader.ContentType] = "application/json";
APIUri = "https://restapi.e-conomic.com/customers";

object customerGroup = new { customerGroupNumber = 11, self = "https://restapi.e-conomic.com/customer-groups/11" };
object paymentTerms = new { paymentTermsNumber = 4, self = "https://restapi.e-conomic.com/payment-terms/4" };
object vatZone = new { vatZoneNumber = 1, self = "https://restapi.e-conomic.com/vat-zones/1" };

string jsonstring = new JavaScriptSerializer().Serialize(new {
customerNumber = User.UserId,
email = email,
name = User.Name,
address = User.Address,
zip = User.PostCode,
city = User.City,
country = User.Country,
currency = "DKK",
customerGroup = customerGroup,
paymentTerms = paymentTerms,
vatZone = vatZone });

try {
APIresponceString = APIresponce.UploadString(APIUri, "POST", jsonstring);
}
catch (WebException webEx) {
if (webEx.Response != null) {
var responseStream = webEx.Response.GetResponseStream();
if (responseStream != null) {
using (var reader = new StreamReader(responseStream)) {
APIresponceString = reader.ReadToEnd(); }
}
}
}
created Oct 6, 2015 by IQn
0% Accept Rate

edited Oct 6, 2015 by IQn
Q 1 A 0 C 0

1 Answer

0
Hi IQn,

Have you tried using a web debugging proxy such as Fiddler? Try comparing the json document you send using Advanced Rest Client and what you capture with Fiddler.

If you still get this error try contacting us at api@e-conomic.com
answered Nov 18, 2015 by rbb
Visma e-conomic A/S
...