Skip to Content

Access Token Reuse in SalesForce integration in CPI

Hi CPI Experts,

I am working on SalesForce Integration.(ECC -> CPI -> SalesForce).It is Idoc to REST API call for Material master interface.

We are using access token for authorization.For each Idoc, authentication login API is called which causes performance problem.Salesforce team asked to reuse the access token until its validity.But in Login API,there is no expiry time and SF is not sure of access token validity time.

How to reuse the access token until its validity.Once gets expired ,new token should be retrieved and call the REST API again. Please let me know how to achieve this in CPI?

Regards,

Karthiga

Add a comment
10|10000 characters needed characters exceeded

Related questions

5 Answers

  • Best Answer
    Posted on May 18 at 06:28 PM

    Hi Karthiga,

    To achieve your use case, one way is to fetch the token again, as and when the API call fail due to expiry token.

    Kindly check the following content for your reference:

    https://api.sap.com/integrationflow/ADP_Tax_Credits_SuccessFactors_Connector_Call_ADP_API

    In this, a seperate integration flow is used to manage the access token and to make an API call.

    The following algorithm is used:

    1. Read the access token from the local variable and in case nothing is there(for the first time), fetch the new token and save as a local variable in data store.

    2. Make the API call and in case of authentication exception (due to access token expiry), fetch the new access token in exception subprocess and update the local variable again.

    In the above content, they are also calculating and checking the token expiry but you can ignore this as you do not have any information on token validity.

    I hope this will help.

    Regards,

    Sunny

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 18 at 05:19 PM

    Hello Karthiga,

    There is no standard way to achieve it and you need to model your iflow to handle it.You can below consideration.

    1) Get the token from Salesforce for first call and store it in variable and use it for first time.

    2) Afterwards you read the variable and validate the Token validity if Salesforce provides api to do the same.In case if you receive error response get a new token if not resuse the same.

    You might consider multiple scenarios while designing and once you get started complexity eases.

    Regards,

    Sriprasad Shivaram Bhat

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 18 at 05:17 PM
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 18 at 05:34 PM

    Hi Sriprasad,

    How to validate the token expire..SF provided the login API,but it returns only access token and not the expiry/Validity time..

    Regards,

    Karthiga

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 26 at 05:29 PM

    Hi Sriprasad/Sunny,

    SF confirmed token will be valid for 15 minutes and i am using groovy for token validation.Adding 15 minutes to the session time and comparing with current time ,finally setting the session valid var either true/false .Based on this condition ,calling the default router or login API.

    Issue:

    In case of bulk Idocs(10,000) received from ECC,in one second 10 Idocs received from ECC and after expiry time,authentication Iflow was called 5 to 6 times.Login API should be called only once after 15 minutes.How to fix this issue.

    Regards,

    Karthiga

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.