I'm trying to come up with a small utility that will connect to an IDO in Syteline (Cloud) through the API, and download the results into an on-prem SQL Server. My code looks like it is successfully getting a token, but when I try accessing the IDO I get an "Invalid Token" message. This is the code I'm using. Any thoughts would be appreciated.
string tokenTest = "https://csi10b-erpsl.inforgov.com/IDORequestService/ido/token/TRN_Default/User/Password";
using (var client = new HttpClient())
{
try
{
var tokenResponse = await client.GetAsync(tokenTest);
tokenResponse.EnsureSuccessStatusCode();
var content = await tokenResponse.Content.ReadAsStringAsync();
Console.WriteLine("Token Response: " + content);
var token = JsonConvert.DeserializeObject<TokenResponse>(content);
using (var client2 = new HttpClient())
{
client2.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken);
//client2.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", token.AccessToken);
client2.DefaultRequestHeaders.Add("accept", "application/json");
client2.DefaultRequestHeaders.Add("X-Infor-MongooseConfig", "TRN_Default");
var idoUrl = "https://csi10b-erpsl.inforgov.com/IDORequestService/ido/load/SLItems?properties=Item,Description,DerQtyOnHand,DerQtyWip";
var idoResponse = await client2.GetAsync(idoUrl);
if (idoResponse.IsSuccessStatusCode)
{
var idoContent = await idoResponse.Content.ReadAsStringAsync();
Console.WriteLine("IDO Response: " + idoContent);
}
else
{
Console.WriteLine($"IDO call failed: {idoResponse.StatusCode} - {idoResponse.ReasonPhrase}");
}
}
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
}
}