Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Generate named credentials with no authentication.

    1. put there URL of the URL you want to call

      1. Code Block
        https://e2e.pricefx.eu/pricefx/seeddata/formulamanager.executeformula/SalesforcePackage_getPrice

  2. Write the Apex Code that will authorize with JWT Token

    1. Code Block
      languagejava
          Auth.JWT jwt = new Auth.JWT();
          jwt.setSub('topon');               //username of the pricefx user
          jwt.setAud('e2e');                 //cluster name
          jwt.setIss('salesforceScratch');   //name of the external configuration
      
          Map<String, Object> claims = new Map<String, Object>();
          claims.put('partition', 'seeddata'); //partition name
      
          jwt.setAdditionalClaims(claims);
          Auth.JWS jws = new Auth.JWS(jwt, 'pricefx_jwt_2048');
      
          String token = jws.getCompactSerialization();
          System.debug('------------- > : ' + token);
      
          HttpRequest req = new HttpRequest();
          req.setEndpoint('callout:pfx_getPriceNoAuth');
          req.setMethod('POST');
          Http http = new Http();
          req.setHeader('Authorization', 'BEARER salesforceScratch;' + token);
          req.setTimeout(120000);
          req.setBody('{"data": {"SFProduct": "Mercedes"}}');
      
          HTTPResponse res = http.send(req);
          System.Debug('#### response:getBody:  ' + res.getBody());
          System.Debug('#### response:getStatusCode ' + res.getStatusCode());
          System.Debug('#### response:getStatus ' + res.getStatus());
          System.Debug('#### response:getStatusCode ' + res.getHeaderKeys());
      
          //System.debug(res.getBody());
      
          if (res.getStatusCode() == 200) {
            return res.getBody();
          }

  3. Call the APEX code and see the debug in the Salesforce Develop Console

    1. You can validate JWT token

  4. Check this other documentation https://ambassadorpatryk.com/2020/07/secure-calls-from-salesforce-to-mulesoft-with-jwt/