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.
Authorization failed. You are not authorized to perform this function.
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.
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);
var authValue = Encoding.ASCII.GetBytes(userName + ":" + password);
attclient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
HttpResponseMessage response = attclient.PostAsync(apiUrl, attContent).Result;
var responseBody = await response.Content.ReadAsStringAsync();
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!
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.