0
public class getContactUsingRESTAPI {

   public static list<Contact> callgetContact (String accId)
   {
              // Create Rest Request                              
              http http= new http();
              HttpRequest feedRequest= new httprequest();
              HttpResponse res1= new HttpResponse ();
              **feedRequest.setEndPoint('callout:full_dev_connection/services/apexrest/v1/getContacts');**
              feedRequest.setHeader('content-type','application/json');
              feedRequest.setMethod('GET');
               res1=http.send(feedRequest);
            String trimmedResponse = res1.getBody().unescapeCsv().remove('\\');
           system.debug('RESPONSE@@'+trimmedResponse);

   }

}

12:00:26:512 USER_DEBUG [57]|DEBUG|@@@RESPONSE@@[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]

Please advise

Target Org code for response ----

@RestResource(urlMapping='/v1/getContacts/*')
   global with sharing class getContact {
     @Httpget
      global static list<contact> fetchAccount(){
        RestRequest req = RestContext.request;
        RestResponse res = Restcontext.response;
        Id accId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);

        list<contact> lstcontact =[Select id , name,Phone,Fax,Email from contact where Accountid='001O000000Yk7tl'];

        return lstcontact ;
      }
   }
1

Please use Workbench and cURL to test if you can invoke the @HttpGet in combination with this Trailhead section.

You also take a look and follow these steps to make sure you have authentification components in place.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.