I'm facing an issue currently, where I have an object setup which is then serialized into JSON for a POST request to an API I'm using. My application is using Microsoft's UWP in C# and the API is IGDB for game data.
I was receiving 401 unauthorized access, and I noticed it's because my Client ID item was typed as "Client_ID" instead of the "Client-ID" as the API docs states.
However, when I try to change the object item to include a hyphen, a lot of errors show up I'm assuming as it's trying to subtract instead of calling the item name. Does anyone know how to overcome this because the API specifically requires "Client-ID" and I can't find or figure out an successful outcome.
Here's the object and code before serialization:
public class IGDBCredentials
{
public string Client_ID { get; set; }
public string Authorization { get; set; }
public string fields { get; set; }
}
private async void gamehub_search_TextChanged(object sender, TextChangedEventArgs e)
{
ObservableCollection<GameObject> dataList = new ObservableCollection<GameObject>();
gamehub_list.ItemsSource = dataList;
dataList.Clear();
var SearchQuery = gamehub_search.Text;
var idgbcredentials = new IGDBCredentials
{
Client_ID = $"{App.GlobalClientidIGDB}",
Authorization = $"Bearer {App.GlobalAccessIGDB}",
fields = "*"
};
string igbdrequeststring = JsonSerializer.Serialize(idgbcredentials);
TLDR; I need to set the "Client_ID" member of the object as "Client-ID" for the API request to work successfully. Thanks :)