How-To: Configuring a REST API Call to Salesforce In Magentrix

    Sometimes it is required to make calls to Salesforce Custom REST API through Magentrix to perform certain operations. However, it can be highly confusing to use APIs when one is new to it. Below are the steps to make a call to Salesforce using sample code.

    Configuring a REST API Call to Salesforce:

    1. Login as an Administrator, and navigate to the IDE. To access it, either click the small tab at the top center of the page and select IDE as shown, or via URL (https://<yourportalurlhere.com>/sys/ide/index)

    2. If you don’t already have an existing controller to run your desired call, create one via File > New Controller. If you have an existing controller you wish to modify, click the # tab on the left side and double-click the controller in the list to open it.

    3. Enter your desired code and click Save.

    Below is the pictured sample code for your own use:

    public class KBArticleTestController : AspxController

    {
        public override ActionResponse Index()
        {
           var binding = ForceUtility.GetBinding("Force");
           string uri = binding.Url.Substring(0, binding.Url.ToLower().IndexOf("/services/"));
           string restQuery = string.Format("{0}/services/apexrest/<RestApiMethod and Parameters>", uri);
           HttpRequestInfo request = new HttpRequestInfo {
                Url = restQuery,
                ContentType = MimeContentTypes.Json,
                Accept = MimeContentTypes.Json,
           };
               request.Headers.Add("Authorization", "Bearer " + binding.SessionHeaderValue.sessionId);
               var result = HttpHelper.HttpGet(request).GetResponseContent();
           return View();
        }
    }
    
    « Previous ArticleNext Article »

     0.0 (0)


    Comments


    About the Author

    Looking for Something?

    Subscription

    Follow Knowledge posts
    Please enter your email address to subscribe:

    Email:
    Subscribe