I understand it is possible to leverage the API from within a workflow to return data for use in a workflow. Is there any document to explain how to authenticate and retrieve data?
Question
Question
How to call the Laserfiche API and return repository information from within a workflow
Answer
Hi Sean,
In this case you won't need to 'use a token to get a token'.
In the developer console > applications > <your service application>, go to the authentication tab, click create key, then "Create a long-lasting 'Authorization Key' secret used to obtain Laserfiche API Access Tokens".
The in 'Integrations' in your 'web service connection', here are your settings. (This is minimally documented!). And you can change your scope as necessary. I swear that repository.ReadWrite worked at one point but I think you need to list them separately (repository.Read repository.Write).
And make sure your authorization starts with "Bearer" and then a space, then your auth token. The auth token is the token from above "long lasting..."
heres your next step of the web service connection:
and the final screen just to make it "do something". In my case I am requesting an entry and my entry ID is 67. Also replace my r value with your repository ID r-value.
I hope this gets you going. I made a video walkthrough last weekend of how to create 'Laserfiche API to Laserfiche API' but it needs some editing which I hope I can get posted this weekend.
Replies
Hi Sean,
Here's the page on the Laserfiche API. This will give you an overview of what's possible. Is this for Laserfiche cloud or on-prem? If you post more detail on the use case, I or someone should be able to give you some more insight.
We are cloud, we wish to use workflows to leverage the laserfiche api to search the repository and return metadata to overcome the workflow service restriction of max 100 rows. Specifically, how do we authenticate the connection from Laserfiche to the Laserfiche API. Is it a service principal account, do we need to use a token to get another token to make the call or can we use oauth2. Is there a one pager on this specific use case?
There are a number of methods you can use. You can use OAUTH2. This method below is the 'token to get another token' method. I recommend starting here. There are so many different paths you can take and it all depends ultimately on how you will use the API in production.
High level:
- Create a service account in Laserfiche cloud (in Accounts)
- In the Cloud Developer Console, create a new App (Service App)
- In the App you just created, link the app the the service account in the first step. Be sure the configure the OAUTH scopes on this page also.
- Still in the App you created, go to the Authentication tab and click 'Create Key' - select the 2nd option "Create a long lasting Authentication key" (make sure you save these! You cannot get the key again)
As far as Authentication goes, you now have everything configured from the Laserfiche side. From here, it all depends on your use-case.
Unless you have a very specific need, my advice at this point is to test everything with Postman (download and install if you don't have it)
The part you need to understand is you that you need to get an authentication token - and it's a two step process.
- Using Postman get send this POST to https://signin.laserfiche.com/oauth/token
- This is the cURL you can import in to Postman
curl --location 'https://signin.laserfiche.com/oauth/token' \ --header 'Content-Type: application/x-www-form-urlencoded' \ --header 'Authorization: Bearer PUT YOUR AUTH KEY HERE' \ --data-urlencode 'grant_type=client_credentials' \ --data-urlencode 'scope=repository.Read repository.Write'
-
In the header Authorization section, where it says PUT YOUR AUTH KEY HERE - this is where you would put your auth key that you downloaded earlier in the step to 'download your long lasting auth key'
-
After running this is Postman, you will get an access token. Copy this and paste it into another test API call. For example:
curl --location 'https://api.laserfiche.com/repository/v2/Repositories/YOUR REPOSITORY/Entries/YOUR ENTRY' \ --header 'Content-Type;' \ --header 'Authorization: Bearer ACCESS TOKEN'
- You have to replace three values above:
- YOUR REPOSITORY is the repository ID. Not the number you log in with, the "r" number repository usually 'r-xxxxxxx'
- YOUR ENTRY is the entry number of a folder or doc
- ACCESS TOKEN is the access token you got from the first auth call.
The authorization part is critical when learning the API. It may not be interesting but it's really import that you get this part working because you will need to understand and rely on this moving forward.
After you do this a few dozen times it will be second nature!
tnx but this post is very general in nature and doesn't answer my question for a step-by-step one-page guide on how to use an api request in a laserfiche workflow to access the LF API. I don't want to know about curl and postman, pretend your trying to explain this to your mom ;-0
I'm familiar with the 'use a token to get another token' method. If i'm working inside laserfiche using the oauth2 authentication, can i skip that and call the api directly without needing to obtain a short lived token? Is there an easier way using the other authentication options like oath2? I've read the developer guide but finding it tough going and looking for a step by step guide. We're seeking to use the LF API in workflow to overcome some of the restrictions like the limit on returning search results. Are we on the right track using the LF Workflow to connect to the LF API?
Hi Sean,
In this case you won't need to 'use a token to get a token'.
In the developer console > applications > <your service application>, go to the authentication tab, click create key, then "Create a long-lasting 'Authorization Key' secret used to obtain Laserfiche API Access Tokens".
The in 'Integrations' in your 'web service connection', here are your settings. (This is minimally documented!). And you can change your scope as necessary. I swear that repository.ReadWrite worked at one point but I think you need to list them separately (repository.Read repository.Write).
And make sure your authorization starts with "Bearer" and then a space, then your auth token. The auth token is the token from above "long lasting..."
heres your next step of the web service connection:
and the final screen just to make it "do something". In my case I am requesting an entry and my entry ID is 67. Also replace my r value with your repository ID r-value.
I hope this gets you going. I made a video walkthrough last weekend of how to create 'Laserfiche API to Laserfiche API' but it needs some editing which I hope I can get posted this weekend.
Hi Anthony - thanks so much for this, i think we can follow it from here but look forward to the video content.
This is working, thanks for the help.