Hello Everyone,
I developed the console application for upload the base 64 document and its running in daily 5 minutes which is configured on windows task scheduler ,Sometime I'm encountering an authorization issue while trying to perform a specific function on the API calls. I would appreciate any help or insights you can provide regarding this error.
Error Message:
Authorization failed. You are not authorized to perform this function.
Context:
I'm currently working on integrating our application with the Hexagon EAM using the REST API. I'm attempting to make a request to the "upload document" endpoint in order to upload a new document.
Authentication Method:
I'm using basic authentication to authenticate my requests. I'm providing the username and password in the Authorization header using the "Basic" scheme. Here's a code snippet showing how I'm setting the headers:
using (HttpClient attclient = new HttpClient())
{
var apiPayload = "";
var attContent = new StringContent(apiPayload, Encoding.UTF8, "application/json");
attclient.BaseAddress = new Uri(apiUrl);
attclient.DefaultRequestHeaders.Add("Organization", organization);
attclient.DefaultRequestHeaders.Add("Tenant", tenant);
var authValue = Encoding.ASCII.GetBytes(userName + ":" + password);
attclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(authValue));
attclient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = attclient.PostAsync(apiUrl, attContent).Result;
if (response.IsSuccessStatusCode)
{
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
}
else
{
Console.WriteLine("Request failed with status code: " + response.StatusCode);
}
}
Expected Behavior: I expect the API to upload the document with the provided details and return a success response with the newly upload document`s information.
Additional Information: I have verified that the provided username and password are correct. I have also double-checked the API documentation to ensure that I'm using the correct endpoint and the required fields in the request payload.
Help Needed: I would greatly appreciate any assistance or insights you can provide to help me troubleshoot this authorization issue. If you have encountered a similar problem or have any suggestions on what might be causing this error, please share your thoughts.
Thank you in advance for your time and help!
Best regards,
Ajaz Khan
What I have tried:
I have verified that the provided username and password are correct. I have also double-checked the API documentation to ensure that I'm using the correct endpoint and the required fields in the request payload.