Skip to main content
Level 2
March 9, 2024
질문

Calling AEM REST API always results in 401 Unauthorized

  • March 9, 2024
  • 1 답변
  • 1092 조회

Hello,

I created a c# application that is attempting to use the AEM API to upload assets into our AEM As a Cloud Service instance.  I am able to use the API to generate a valid token, but whenever I try to call any AEM APIs with that token, I always get a 401 - Unauthorized response.  If I use the same url and token in Postman, it works everytime.  Here is my code for reference:

using (var lClient = new HttpClient()) { // issue the request var lRequestContent = new MultipartFormDataContent(); lRequestContent.Add(new StringContent(pFileName), "fileName"); lRequestContent.Add(new StringContent(pFile.Length.ToString()), "fileSize"); lClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", pToken); var lResponse = lClient.PostAsync($"{BaseUrl}/{BaseFolderPath}.initiateUpload.json", lRequestContent).Result; }

Has anyone experienced this before, and if so, do you have any advice you would be willing to share?

이 주제는 답변이 닫혔습니다.

1 답변

PhillipKo작성자
Level 2
March 11, 2024

I think the 401 may be a result of the way the token is getting created.  If I use the developer console to generate a temp local token, the code works as expected.  I think I need to maybe adjust my scopes on the token request...