Created
December 9, 2014 23:45
-
-
Save emoran/6bb0df0bcbf418c33663 to your computer and use it in GitHub Desktop.
Get ASANA Users from Apex salesforce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static List<ASANA_User_wrapper> getUsers() { | |
List<ASANA_User_wrapper> list_asana_users = new List<ASANA_User_wrapper>(); | |
HttpRequest aRequest = new HttpRequest(); | |
aRequest.setEndpoint('https://app.asana.com/api/1.0/users'); | |
aRequest.setMethod('GET'); | |
String username = API_KEY; | |
String password = ''; | |
Blob headerValue = Blob.valueOf(username + ':' + password); | |
String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue); | |
aRequest.setHeader('Authorization', authorizationHeader); | |
Httpresponse aResponse = new Http().send(aRequest); | |
JSONParser parser = JSON.createParser(aResponse.getBody()); | |
ASANA_User_wrapper user = new ASANA_User_wrapper(); | |
while (parser.nextToken() != null) { | |
if (parser.getCurrentToken() == JSONToken.START_ARRAY) { | |
while (parser.nextToken() != null) { | |
if (parser.getCurrentToken() == JSONToken.START_OBJECT){ | |
user = (ASANA_User_wrapper)parser.readValueAs(ASANA_User_wrapper.class); | |
list_asana_users.add(user); | |
} | |
} | |
} | |
} | |
return list_asana_users; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment