question

GabIod avatar image
0 Votes"
GabIod asked GabIod edited

Sharepoint API Error ID3035

Hello,

I am trying to download a file using the Sharepoint API.
I get the Access Token then I use the following API to read a folder (or any other API to download a file), but I always have the following error

GET https://{site_url}/_api/web/GetFolderByServerRelativeUrl('/Shared Documents')
Auth: Bearer {toke}

as explained here https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest

{"error_description":"ID3035: The request was not valid or is malformed."}


The authentication token must be correct because when I change it I have a different error.


Thanks!
Gabri

office-sharepoint-online
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

GabIod avatar image
1 Vote"
GabIod answered GabIod edited

Hi @MichaelHan-MSFT,
thanks for your help.

You were right: the authentication was the problem. But the documents you shared were not exactly what I was looking for. This is the thing that helped me a lot:

https://www.ktskumar.com/2017/01/access-sharepoint-online-using-postman/

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MichaelHan-MSFT avatar image
1 Vote"
MichaelHan-MSFT answered MichaelHan-MSFT commented

Hi @GabIod ,

I'm not an expert with java. From your code, you are acquiring AAD token using app client ID and secret. This way is to authenticate with Graph API. And It would not work for SharePoint Rest API.

For SharePint Rest API with AAD app, you need to get the token with the certificate opion. You can refer to this article for more: https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azuread

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @GabIod ,

If my reply helps you, you could accept it as answer. It would be helpful to others who have similar issues in the future.

0 Votes 0 ·
MichaelHan-MSFT avatar image
0 Votes"
MichaelHan-MSFT answered GabIod commented

Hi @GabIod ,

How did you retrieve the Access Token? Please share more details. Use SharePoint APP or AAD APP?

If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.




· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi MichaelHan,
so basically I have used the msal4j lib in a Java Maven Project.

I configured it as follow:


final String authenticationType = "ServicePrincipal";
final String clientId = "xxxxxxx";
final String appSecret = "xxxxxxxx";
final String tenantId = "xxxxxxx";

 public static final String authorityUrl = "https://login.microsoftonline.com/";
 public static final String scopeUrl = "https://site_url/.default";
    
    
 ConfidentialClientApplication app = ConfidentialClientApplication.builder(
                     clientId,
                     ClientCredentialFactory.createFromSecret(appSecret))
                     .authority(Config.authorityUrl + tenantId)
                     .build();
    
         ClientCredentialParameters clientCreds = ClientCredentialParameters.builder(
                 Collections.singleton(Config.scopeUrl))
                 .build();
    
         // Acquire new AAD token
         IAuthenticationResult result = app.acquireToken(clientCreds).get();
0 Votes 0 ·
sadomovalex avatar image
0 Votes"
sadomovalex answered GabIod commented

few questions: do you work with SPO on onprem? And how exactly you get the token? Here is example of how to get access token for SPO: SharePoint Rest API how to get Access Token.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi sadomovalex,
thanks for your answer.

I am retrieving the token using the ServicePrincipal approach yes.

My only clue for now is this https://answers.microsoft.com/en-us/msteams/forum/msteams_tff-msteams_file-msteams_findfile/id3035-the-request-was-not-valid-or-it-is/b8d93f2d-6524-4623-a719-431b272b4416

0 Votes 0 ·