0

I am trying to implement the sentiment api but having issue while generating the access token.

I have uploaded einstein_platform.pem file in Files in Salesforce.

ContentVersion con = [SELECT  Title
                ,VersionData
        FROM    ContentVersion
        WHERE   Title = 'einstein_platform'
        OR      Title = 'predictive_services'
        ORDER BY Title
        LIMIT 1];

    String key = con.VersionData.tostring();
    key = key.replace( '-----BEGIN RSA PRIVATE KEY-----', '' );
    key = key.replace( '-----END RSA PRIVATE KEY-----', '' );
    key = key.replace( '\n', '' );
    JWT jwt = new JWT( 'RS256' );
    jwt.pkcs8 = key;
    jwt.iss = 'developer.force.com';
    jwt.sub = '[email protected]'; // Update with your own email ID
    jwt.aud = 'https://api.einstein.ai/v2/oauth2/token';
    jwt.exp = String.valueOf(3600);
    String access_token = JWTBearerFlow.getAccessToken( 'https://api.einstein.ai/v2/oauth2/token', jwt );
    String keyaccess = access_token;
    System.debug('******keyaccess**'+keyaccess);

Output: 18:34:11:987 USER_DEBUG [21]|DEBUG|******keyaccess**null

2

1 Answer 1

0

In addition to storing the einstein_platform.pem file you also need to update the following line with the email address you used when creating the Einstein account.

jwt.sub = '[email protected]';

Also, check that you have https://api.einstein.ai configured as a Remote Site so the callout will be allowed.

1
  • Yes, I did update my email id, here I just put it for demo purpose only. Commented Jan 8, 2019 at 7:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .