Unable to fetch API response
I have taken clone from your code samples in C# .Net Core and I have authenticated via your code and [HttpGet("{id}")]
public async Task<IActionResult> GetById(string id, CancellationToken cancellationToken)
{
try
{
var model = await _constituentsService.GetConstituentAsync(id, cancellationToken);
return Ok(model);
}
catch (UnauthorizedAccessException)
{
return RedirectToAction("LogIn", "Authentication");
}
} public async Task<ConstituentModel> GetConstituentAsync(string id, CancellationToken cancellationToken)
{
var httpClient = await GetClient(cancellationToken);
var response = await httpClient.GetAsync($"constituents/{id}", cancellationToken);
if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
{
return null!;
}
if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
{
throw new UnauthorizedAccessException();
}
response.EnsureSuccessStatusCode();
var model = await response.Content.ReadFromJsonAsync<ConstituentModel>(cancellationToken: cancellationToken);
return model;
} (function () {
'use strict';
// Check user access token.
fetch('/auth/authenticated')
.then(response => response.json())
.then(data => {
if (data.authenticated === false) {
document.getElementById('login-section').style.display = 'block';
document.getElementById('loading-message').style.display = 'none';
return;
}
// Access token is valid. Fetch constituent record.
fetch('/api/constituents/280')
.then(response => response.json())
.then(data => {
document.getElementById('constituent-name').textContent = data.name;
document.getElementById('constituent-id').textContent = data.id;
document.getElementById('constituent-type').textContent = data.type;
document.getElementById('constituent-lookup-id').textContent = data.lookup_id;
document.getElementById('constituent-first').textContent = data.first;
document.getElementById('constituent-last').textContent = data.last;
document.getElementById('login-section').style.display = 'none';
document.getElementById('constituent-data').style.display = 'block';
document.getElementById('loading-message').style.display = 'none';
})
.catch(error => {
document.getElementById('constituent-error').textContent = 'Error fetching constituent data: ' + error;
document.getElementById('constituent-error').style.display = 'block';
document.getElementById('loading-message').style.display = 'none';
});
}); for constitutent id is hardcoded as 280 and response is coming like this System.Net.Http.HttpRequestException: Response status code does not indicate success: 400 (Bad Request).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode() why coming like this?
Categories
- All Categories
- 6 Blackbaud Community Help
- 206 bbcon®
- 1.4K Blackbaud Altru®
- 394 Blackbaud Award Management™ and Blackbaud Stewardship Management™
- 1.1K Blackbaud CRM™ and Blackbaud Internet Solutions™
- 15 donorCentrics®
- 357 Blackbaud eTapestry®
- 2.5K Blackbaud Financial Edge NXT®
- 646 Blackbaud Grantmaking™
- 561 Blackbaud Education Management Solutions for Higher Education
- 3.2K Blackbaud Education Management Solutions for K-12 Schools
- 934 Blackbaud Luminate Online® and Blackbaud TeamRaiser®
- 84 JustGiving® from Blackbaud®
- 6.4K Blackbaud Raiser's Edge NXT®
- 3.6K SKY Developer
- 242 ResearchPoint™
- 117 Blackbaud Tuition Management™
- 165 Organizational Best Practices
- 238 The Tap (Just for Fun)
- 33 Blackbaud Community Challenges
- 28 PowerUp Challenges
- 3 (Open) Raiser's Edge NXT PowerUp Challenge: Product Update Briefing
- 3 (Closed) Raiser's Edge NXT PowerUp Challenge: Standard Reports+
- 3 (Closed) Raiser's Edge NXT PowerUp Challenge: Email Marketing
- 3 (Closed) Raiser's Edge NXT PowerUp Challenge: Gift Management
- 4 (Closed) Raiser's Edge NXT PowerUp Challenge: Event Management
- 3 (Closed) Raiser's Edge NXT PowerUp Challenge: Home Page
- 4 (Closed) Raiser's Edge NXT PowerUp Challenge: Standard Reports
- 4 (Closed) Raiser's Edge NXT PowerUp Challenge: Query
- 777 Community News
- 2.9K Jobs Board
- 53 Blackbaud SKY® Reporting Announcements
- 47 Blackbaud CRM Higher Ed Product Advisory Group (HE PAG)
- 19 Blackbaud CRM Product Advisory Group (BBCRM PAG)