• Gaurav Idnani
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
User-added image


The snapshot shows the values in a collection obtained from a JSON response , i am unable to access the individual values for name or date.Kindly help


public class HolidayAPI {
    
    public static void test (){
        
    Http http = new Http();
    HttpRequest request = new HttpRequest();
    request.setEndpoint('https://holidayapi.com/v1/holidays?key=47d973e9-40e0-4a54-b751-2f4da80ad403&country=IN&year=2017');
    request.setMethod('GET');
    HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
    if (response.getStatusCode() == 200) {
    // Deserialize the JSON string into collections of primitive data types.
        Map<String,Object> hoMap = (Map<String , Object>) JSON.deserializeUntyped(response.getBody()) ;
        Map<String,Object> hoList = (Map<String , Object>)hoMap.get('holidays');
        List<object> temp = new List<Object> (hoList.values());
      
        System.debug('HTTP response='+response);        
        System.debug('First level data(deserialied)'+hoMap);
        System.debug('Second level data'+hoList);
        System.debug('Third level data='+temp);
        
        for (Object t:temp){
            System.debug(t);
            
            
        
    }

}
    }}

 
SELECT Id
                                  FROM Leave_Request__c
WHERE
                                  from_date__c>= :reqApp.from_date__c AND from_date__c <= :reqApp.to_date__c                              
OR
                                  to_date__c>= :reqApp.from_date__c AND to_date__c <= :reqApp.to_date__c
AND
                                  Resource__c = :UserInfo.getUserId()


 
Hi ,
I am trying to add a custom api
https://holidayapi.com/v1/holidays?<parameters> to my org to fetch some custom data .
I tried to do this using the external data sources option in setup.

But I recieved the following error
System.CalloutException: Unauthorized endpoint

The code where I used the API

Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://holidayapi.com/v1/holidays?key=47d973e9-40e0-4a54-b751-2f4da80ad403&country=IN&year=2017');
request.setMethod('GET');
HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
   /* // Deserialize the JSON string into collections of primitive data types.
    Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
    // Cast the values in the 'animals' key as a list
    List<Object> animals = (List<Object>) results.get('animals');
    System.debug('Received the following animals:');
    for (Object animal: animals) {*/
        System.debug('Success');
    }

 
<apex:pageBlockSection collapsible="true">
<apex:pageBlockTable title="Leave record" value="{!lrs}" var="lr">
<apex:column >
<Apex:outputText value="{!lr.from_date__c}" />
</Apex:column>
 </apex:pageBlockTable>
</apex:pageBlockSection>




Controller extension for the code:

public with sharing class LeaveControllerExtension {

    public List<Leave_Request__c> lrs { get; set; }
    public LeaveControllerExtension(ApexPages.StandardController controller) {
         Leave_Request__c lr = (Leave_Request__c)controller.getRecord();
         lr.from_date__c = Date.Today();
         lr.to_date__c = Date.Today() + 1;
        
       String cui = UserInfo.getUserId() ;
       List<Leave_Request__c> lrs = [SELECT From_date__c , To_date__c , Approver__c 
                                     FROM Leave_request__c
                                    WHERE Resource__c = :cui] ;
        
    }    

}
User-added image


The snapshot shows the values in a collection obtained from a JSON response , i am unable to access the individual values for name or date.Kindly help


public class HolidayAPI {
    
    public static void test (){
        
    Http http = new Http();
    HttpRequest request = new HttpRequest();
    request.setEndpoint('https://holidayapi.com/v1/holidays?key=47d973e9-40e0-4a54-b751-2f4da80ad403&country=IN&year=2017');
    request.setMethod('GET');
    HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
    if (response.getStatusCode() == 200) {
    // Deserialize the JSON string into collections of primitive data types.
        Map<String,Object> hoMap = (Map<String , Object>) JSON.deserializeUntyped(response.getBody()) ;
        Map<String,Object> hoList = (Map<String , Object>)hoMap.get('holidays');
        List<object> temp = new List<Object> (hoList.values());
      
        System.debug('HTTP response='+response);        
        System.debug('First level data(deserialied)'+hoMap);
        System.debug('Second level data'+hoList);
        System.debug('Third level data='+temp);
        
        for (Object t:temp){
            System.debug(t);
            
            
        
    }

}
    }}

 
Hi ,
I am trying to add a custom api
https://holidayapi.com/v1/holidays?<parameters> to my org to fetch some custom data .
I tried to do this using the external data sources option in setup.

But I recieved the following error
System.CalloutException: Unauthorized endpoint

The code where I used the API

Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://holidayapi.com/v1/holidays?key=47d973e9-40e0-4a54-b751-2f4da80ad403&country=IN&year=2017');
request.setMethod('GET');
HttpResponse response = http.send(request);
// If the request is successful, parse the JSON response.
if (response.getStatusCode() == 200) {
   /* // Deserialize the JSON string into collections of primitive data types.
    Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
    // Cast the values in the 'animals' key as a list
    List<Object> animals = (List<Object>) results.get('animals');
    System.debug('Received the following animals:');
    for (Object animal: animals) {*/
        System.debug('Success');
    }

 
<apex:pageBlockSection collapsible="true">
<apex:pageBlockTable title="Leave record" value="{!lrs}" var="lr">
<apex:column >
<Apex:outputText value="{!lr.from_date__c}" />
</Apex:column>
 </apex:pageBlockTable>
</apex:pageBlockSection>




Controller extension for the code:

public with sharing class LeaveControllerExtension {

    public List<Leave_Request__c> lrs { get; set; }
    public LeaveControllerExtension(ApexPages.StandardController controller) {
         Leave_Request__c lr = (Leave_Request__c)controller.getRecord();
         lr.from_date__c = Date.Today();
         lr.to_date__c = Date.Today() + 1;
        
       String cui = UserInfo.getUserId() ;
       List<Leave_Request__c> lrs = [SELECT From_date__c , To_date__c , Approver__c 
                                     FROM Leave_request__c
                                    WHERE Resource__c = :cui] ;
        
    }    

}