1

I am new to Salesforce. Planning to integrate third party REST API (http://rt4.marcura.com/REST/1.0/search/ticket/?user=salesforce&pass=salesforcepass&query=CX::Team1) into Salesforce. What are steps invovled, can you please explain to me.

I wrote below code in Apex class.

public class RTCallouts {

public static HttpResponse makeGetCallout() {
    Http http = new Http();
    HttpRequest request = new HttpRequest();
    request.setEndpoint('http://rt4.marcura.com/REST/1.0/search/ticket/?user=salesforce&pass=salesforcepass&query=CX::Team1');
    request.setMethod('GET');
    HttpResponse response = http.send(request);
    // If the request is successful, parse the JSON response.
    if (response.getStatusCode() == 200) {
        // Deserializes 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 'tickets' key as a list
        List<Object> tickets = (List<Object>) results.get('tickets');
        System.debug('Received the following tickets:');
        for (Object ticket: tickets) {
            System.debug(ticket);
        }
    }
    return response;
}

public static HttpResponse makePostCallout() {
    Http http = new Http();
    HttpRequest request = new HttpRequest();
    request.setEndpoint('http://rt4.marcura.com/REST/1.0/search/ticket/?user=salesforce&pass=salesforcepass&query=CX::Team1');
    request.setMethod('POST');
    request.setHeader('Content-Type', 'application/json;charset=UTF-8');
    request.setBody('{"Accont name":"Test RT"}');
    HttpResponse response = http.send(request);
    // Parse the JSON response
    if (response.getStatusCode() != 201) {
        System.debug('The status code returned was not expected: ' +
            response.getStatusCode() + ' ' + response.getStatus());
    } else {
        System.debug(response.getBody());
    }
    return response;
}        

}

No errors found. But i need to display the third party details into salesforce in case page. I created field. After that i dont know to how to call those methods and write the code . Can you please send me the code to display the data in case Page whatever in the REST API. how can i write the code.

Thanks in Advance,

  • Do you want to dynamically load this data from the API each time the page is loaded? Are you using the Lightning UI? – Daniel Ballinger Jun 26 '17 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.