Try to get access token from serverless

Hi guys,

We need to send an access token via third party node package(Eg: axios, request) for to make an API call.

Already you have said that the way of how to make an API call in the serverless app using access token like:

var options = {
headers: {
Authorization: “bearer<%= access_token %>”
},
isOAuth: true
}

$request.post(url, options)

Yeah that is fine!.

Now we need to send with attachment for to make a API call.

We were know how to send an attachment for the API using third party node package.

The problem is:

Lets say If now we proceed to send an attachment followed by the way, here we need access token to call API.

Third party node package does not read access token when we wrote like <%= access_token %>.

Now how we can to resolve this.

Thank you.

@Karuppu_Samy ,
It is not possible to use the template compiler outside of platform feature such as request API.
if you want to use third party package, then you need to pass the actual value in the request.

Hope it helps :slight_smile:

Thanks

2 Likes

Yes right we should give an exact value when we call API using third party package.

We were now using oauth.

How we can get exact value of access token which is stored in local automcatically when installation is done by using oauth.

How to access exact access_token value from serverless.

@Karuppu_Samy ,
so, you are trying to invoke an SMI call from the installation page, or on the app setup events, you are trying to get the access_token? can you please clarify?
but why can’t you use the request API to solve your case or is there any blocker to use the request API?

Thanks

We should send with attachments when make API call using Access Token.

Without OAuth: We can able to send attachment using third party package.

If OAuth: You said, the third party package does not support template

Can you refer this below link,

https://community.developers.freshworks.com/t/send-multipart-form-data-using-request-api-in-client-side-app/319

could you find out the reason why we moved to third party package.

Could you help us to resolve this issue.

How can send attachment with OAuth access token using API call,

Thank you.

Hi @Karuppu_Samy ,
It is not possible with the straightforward approach,
but there is a workaround that you can use the middleware to solve your use case,

step 1:
on app setup events (on Install) → you need to pass the Access token via request API with template literal to the middleware, and store the access token and generate webhook and pass it to middleware

step 2:
use your third party package to call the middleware and attach the access token from middleware and pass it to your backend

step 3:
if the token is expired, use the external events to make any API to refresh the access token and pass it in your middleware

another alternative which I suggest:
use API token instead of Oauth.

Hope it helps :slight_smile:

Thanks

Thanks for the response.

We will try.

1 Like

Hi @Santhosh ,

We were get access token via middleware and using to call API’s , It is working fine for un till that token has expired.

After the token expiration time has reached. it did not work when we try to call API.

For the every API call before need access token which is refreshed by framework and updated in the local db as it is secured.