• CHAYAN BATABYAL
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
public class AuthCallout {
    public void basicAccessTokenGeneration() {
     HttpRequest req = new HttpRequest();
     req.setEndpoint('https://');
     req.setMethod('POST');

     // Specify the required username and password to access the endpoint
     // As well as the header and header information

     String username = '';
     String password = '';
     String vendor   = '';
     String businessunit ='';
     String application ='';

     Blob headerValue = Blob.valueOf(application + '@' + vendor + ':' + businessunit);
     String authorizationHeader = 'BASIC ' +
     EncodingUtil.base64Encode(headerValue);
     req.setHeader('Authorization', authorizationHeader);


    JSONGenerator gen = JSON.createGenerator(true);    

    gen.writeStartObject();      
    gen.writeStringField('grant_type ', 'password');
    gen.writeStringField('username', username);
    gen.writeStringField('password',password);
    gen.writeStringField('scope','');
    gen.writeEndObject();
    String jsonS = gen.getAsString();
    system.debug('DAta in '+str);
    system.debug('Data in gen'+jsonS);
    req.setBody(jsonS);
     // Create a new http object to send the request object
     // A response object is generated as a result of the request  

     Http http = new Http();
     HTTPResponse res = http.send(req);
     System.debug(res.getBody());
        System.debug(res.getStatusCode());
        System.debug(res.getBodyDocument());
   }
}

'm new to integration. I am going to generate an access token for the third-party application.
I tried to build following javascript request in sfdc.

But the response body is blank. I need to retrieve access token & other things to call specific endpoint in another class.
Please let me know where i did wrong

I am searlize JSON string also while sending the body

They gave same code request sample in java format like below.

Sample request
var result = {};
var application = "";
var vendor = "";
var businessunit = "";
var user = "";
var pass = "";
var authCode = window.btoa(application + "@" + vendor + ":" + businessunit);
$.ajax({
    "url": 'https://',
    "type": 'post',
    "contentType": 'application/json',
    "dataType": 'json',
    "headers": {
        'Authorization': 'basic ' + authCode
    },
    "data": JSON.stringify({
    "grant_type": 'password',
    "username": user,
    "password" : pass,
    "scope": 'AdminApi AgentApi AuthenticationApi PatronApi RealTimeApi'
    }),
    "success": function (resp) {
        result.access_token = resp.access_token;
        result.token_type = resp.token_type;
        result.resource_server_base_uri = resp.resource_server_base_uri;
        result.expires_in = resp.expires_in;
        result.refresh_token = resp.refresh_token;
        result.scope = resp.scope;
        result.refresh_token_server_uri = resp.refresh_token_server_uri;
    },
    "error": function (XMLHttpRequest, textStatus, errorThrown) {
        alert("Failed to retrieve token.\n" + XMLHttpRequest.status + ' ' 
            + XMLHttpRequest.statusText);
    }
});

My Apex

 
I want get a list of all the users who are part of public group of the currently logged in user. In documentations, i have read that  able to pick these values from group and group member objects.

A record exists for every User or Group who is a direct member of a public group whose Type field is set to Regular. User records that are indirect members of Regular public groups are not listed as group members. A User can be an indirect member of a group if he or she is in a UserRole above the direct group member in the hierarchy, or if he or she is a member of a group that is included as a subgroup in that group.

Can we get all users of a group using group id? Please help me ASAP it's urgent.