C#C
C#2y ago
22 replies
Isaaaak

API request, working in Postman but not C#

I'm trying to call a certain API and then get a response back. When I run the code in Postman it works fine, I get the right response. But when I run it in C#, I get 403 forbidden. If I run the code in Postman without the JSON body, then I get 400 bad request. So I know it's not the JSON that's the issue, meaning it's probably the headers. Could someone give me a hint at what I should look at to solve this problem?
string jsonString = "{\"purpose\":\"MAX\",\"applicants\":[{\"birthYear\":2003,\"qualifiesEmploymentLength\":true,\"monthlyIncome\":55000,\"employmentType\":\"PERMANENT\",\"employmentRole\":\"\",\"maritalStatus\":\"SINGLE\"}],\"existingProperties\":[],\"household\":{\"children\":[],\"amortizationStudentDebt\":729,\"otherAssets\":0,\"carCost\":[{\"type\":\"OWNED\"}]},\"intermediaryType\":\"454\",\"newProperty\":{\"propertyType\":\"HOUSE\",\"mortgage\":null,\"downPayment\":700000,\"municipality\":\"Örebro\",\"livingSpace\":130}}";

var client = new HttpClient();
client.BaseAddress = new Uri("https://api.sbab.se/api/pre-approval/2.0/");

var content = new StringContent(jsonString, Encoding.UTF8, "application/json");

var response = client.PostAsync("loan-offer", content).Result;


Console.WriteLine(jsonString);
image.png
image.png
Was this page helpful?