Home > Blockchain >  JSON HttpWebRequest always returns 400
JSON HttpWebRequest always returns 400

Time:03-04

I tried to make a request to test if people should be able to pay on invoice.

I've never made an API call with JSON data before so i read through some documentations and stack overflow questions and found this thread right here, which was pretty promissing: enter image description here

The error message says: System.Net.WebException: "The remoteserver responded with an error: (400) bad request"

Those are the details to the exception:

System.Net.WebException
  HResult=0x80131509
  Message = The remote server returned an error: (400) Invalid request.
  Source = <The exception source cannot be evaluated.>.
  Stack monitoring:
<The exception stack monitor cannot be evaluated.>.

That's the model i'm trying to serialize and add to the httpWebRequest:

    internal class CreditReformModel
    {
        public string ShopId { get; set; }
        public string OrderProcessId { get; set; }
        public string IpAddress { get; set; }
        public string MacAddress { get; set; }
        public string CustomerId { get; set; }
        public CreditReformAddressModel ShippingAddress { get; set; }
        public CreditReformAddressModel BillingAddress { get; set; }
    }

    internal class CreditReformAddressModel
    {
        public string Type { get; set; }
        public string BusinessName { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Co { get; set; }
        public string Street { get; set; }
        public string HouseNumber { get; set; }
        public string PostCode { get; set; }
        public string LocationName { get; set; }
        public string Country { get; set; }
        public string Email { get; set; }
        public string Phone { get; set; }
        public string DateOfBirth { get; set; }
    }

That's the requested data in the API documentation:

{
  "shopId": "20071992",
  "orderProcessId": "ref001",
  "ipAddress": null,
  "macAddress": null,
  "customerId": "cus001",
  "billingAddress": {
    "type": "Consumer",
    "businessName": null,
    "firstName": "Martin",
    "lastName": "Früh",
    "co": null,
    "street": "Funkenbüelstrasse",
    "houseNumber": "1",
    "postCode": "9243",
    "locationName": "Jonschwil",
    "country": "CH",
    "email": null,
    "phone": null,
    "dateOfBirth": null
  },
  "shippingAddress": null,
  "orderAmount": 1200
}

When i look at the model while debugging there should be all the required data:

enter image description here

enter image description here

enter image description here

Does someone know why this happens?

If you need more code or information just say it and i edit the question.

CodePudding user response:

I finally found the error.

The problem was that the business name on the database was null even tho the address type was a business address.

enter image description here

Thanks for everyone who wrote a comment.

  • Related