You are viewing limited content. For full access, please sign in.

Question

Question

Laserfiche Cloud API V2

asked on November 16, 2023

Hello,


I wrote a function to connect to the Laserfiche cloud repository with which I export files. Until now it worked perfectly with API V1. The export function has been deprecated RestRequest request = new RestRequest{ Method = Method.Get,};
request.AddHeader("Authorization", $"Bearer {sToken}");
....
request = new RestRequest { Method = Method.Head, };

It was replaced by a POST
https://api.eu.laserfiche.com/repository/v2/Repositories/:repositoryId/Entries/:entryId/Export?pageRange=<string>

The problem encountered concerns the creation of the token which works but which is no longer valid for V2 type calls.
Apparently, the scope is missing to be able to use it.

I did a simple test with a GET
https://api.eu.laserfiche.com/repository/v2/Repositories
Response: Error: Forbidden request. Ensure your access token has the correctly configured scope.
If I make the same query using https://api.eu.laserfiche.com/repository/v1/Repositories
it works perfectly.

I don't understand this problem.

Thanks for your help

0 0

Replies

replied on November 16, 2023

Hi,

OAuth 2.0 scopes are mandatory in repository api V2. It's mentioned in the "Other" section in V2 changelog https://api.eu.laserfiche.com/repository/v2/changelog.

When requesting OAuth 2.0 access token, you need to specify the scopes needed. See "Requesting an Access Token with Scopes" section in https://developer.laserfiche.com/guides/guide_oauth_2.0_scopes.html.

The scope required for each api could be found in the Swagger page. For example, for "https://api.eu.laserfiche.com/repository/v2/Repositories", you need to use an access token with "repository.Read" scope to be able to get response successfully.

2 0
replied on November 16, 2023

Hello Chen,

Thank you for your reply
To remove any ambiguity I used Postman to create a token
the Bearer used is the one generated by https://app.eu.laserfiche.com/devconsole/apps

The token is generated without problem.
When I use {{baseUrl}}/v2/Repositories?scope=repository.Read
I have an error as if the scope is not taken into account.
type": "forbidden",
     "title": "Error: Forbidden request. Ensure your access token has the correctly configured scope.",

I think there is a problem with the creation of the token which ignores the requested scope.
Below is the code used to generate the token
The sFile variable is the name of the file which contains the information to generate the token (this file is generated by console_dev)
I don't see anything in this file that indicates which scope to use.

string oauthConfig = File.ReadAllText(sFile);
ClientCredentialsOptions configuration = JsonConvert.DeserializeObject<ClientCredentialsOptions>(oauthConfig);
ClientCredentialsHandler handler = new ClientCredentialsHandler(configuration);
accessToken = handler.GetAccessToken().Result;

 

0 0
replied on November 16, 2023

Hi,

You might still using the old code. There are new versions of repository api client library and OAuth client library.

Here's the sample code for C# https://github.com/Laserfiche/lf-sample-repository-api-dotnet-srv/blob/v2/Program.cs, which uses the latest client libraries. If you clone the Git repository to your machine and then follow the steps here to create configuration file https://github.com/Laserfiche/lf-sample-repository-api-dotnet-srv/blob/v2/README.md#cloud-prerequisites, the code should be ready to use.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.