So my question might be a noob question as I am not a developper and don’t have some of the basics.
I have the exact same question as here (probably for the exact same API too).
I make an API call to get a token which I then can use. I have noticed the token expires but the documentation provided is really light and the INPI (french IP office does not provide any support) so I don’t really know when.
I use this token in half a dozen workflows.
Getting a new one cancels any previous one.
I have an idea in mind but I don’t know if it’s optimal or if there is now some built-in way to manage this issue. Here it is
Setting up a “get token” workflow with the following steps:
a. Activated when called
b. Test if token works
c. If yes, continue – If not, get a new one
d. Answer with token
Putting this “get token” workflow at the beginning of all workflow requesting this API.
My issue is that it will heavily impact API rate because I will need to trigger it for before each enrichment and it adds an additional call to the API for each row enriched.
So now I am considering getting the token only in case of error but if the error is unrelated it seems sketchy.
How do you handle managing a token like that?
Any best practice?
If it was me I would build a custom node for the service and handle it in the credential file, Without seeing API docs though it is a bit hard to say. I think your approach of a workflow to manage that would work although rather than at the start of the worklfow you could trigger it if the node that calls the API fails so you would set it to continue on fail then check the output if it has failed get a new token and try again.
The workflow below successfully keeps a token stored on github.
I still have the issue of wasting API rate checking if the token works.
I see I can delete or create a credential but the best solution for me would be to update the credential in the event the token is renewed.
Is it possible to update a credential using this workflow?
Thanks!
UPDATE
Made some progress. To avoid wasting API rate to check the token, I know have a parameter in my webhook trigger depending on if it was trigerred following an error or not.
So now I ask the workflow for the latest token, and if it doesn’t work I can refresh it using the same workflow:
I would prefer to have this logic handled in credentials but at least it works for now.
Any advice on improvement is welcome!