0
I am new with programming and I’m having difficulty accessing a Token that is as variable in the file application.json
. It is a console application, the goal is only to use the token of the global variable and use as a user to make an authentication in a GET method of an API. I don’t know what kind of prints I owe around here, I’ll put some down:
Application.json
{
"Config": {
"Environment": "Development",
"ApiTokenSecretQA": "meuToken",
"UrlApi": "https://api.mundipagg.com/core/v1"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
Program.Cs
namespace Gateway_Pagamento
{
class Program
{
static void Main(string[] args)
{
GetOrder.GetOrderId();
//CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices(services =>
{
services.AddHostedService<Worker>();
});
Metodo Get Order - tried to do to access the API
public class GetOrder
{
[HttpGet]
public static void GetOrderId()
{
Authenticator auth = new Authenticator();
Authenticator.Authorization();
try
{
var client = new RestClient("https://api.mundipagg.com/core/v1");
//var request = new RestRequest(("orders/" + orderId), Method.GET, DataFormat.Json);
var request = new RestRequest(("orders/"), Method.GET, DataFormat.Json);
client.Authenticator = new HttpBasicAuthenticator(auth.BasicAuthUserName, auth.BasicAuthPassword);
var response = client.Get(request);
client.Execute(request);
Console.WriteLine(response.Content);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
and where do you need to access it? on Main, Createhost or any other method?
– Ricardo Pontual
@Ricardopunctual , is in a GET method, calling the API to query and authenticate, I will try to paste it above into the question.
– Gabriel Rio