function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

How to call my api rest class

I'm not really a developer but have used apex in the past to write triggers. Now I'm trying to use the Rest API to make a call to GoToWebinar's API. I've written some code but am not sure how to test to see if my API call is even working. How do a test that from the Developer Console? Also, when I implement the feature, I am hoping to have it execute without human interaction as a job that runs each night. How do you do that?

Here's my code:
public class g2wCallout {
    public void getWebinars(){
      HttpRequest req = new HttpRequest(); 
      //Set HTTPRequest Method
      //Set HTTPRequest header properties
      req.setHeader('content-type', 'application/json');
      req.setHeader('Authorization','OAuth ');
      req.setEndpoint( '' );
      //Set the HTTPRequest body	
      Http http = new Http();
       try {
            //Execute web service call here		
           // HTTPResponse res = http.send(req);	
            //Helpful debug messages
             System.debug('this is a test');
        } catch(System.CalloutException e) {
        //Exception handling goes here....

Amit Chaudhary 8Amit Chaudhary 8
Create a scheduler class and schedule the same in night. And call your code like below in scheduler class

g2wCallout obj = new g2wCallout ();
Hi Amit,

Thanks for the help. I created the scheduler class and then used the "Schedule Apex" button in the UI to schedule it to run. However, is there a way to test it "On Demand" so that I don't have to wait for the scheduled job to execute? 
global class g2wCalloutScheduler implements Schedulable {
    global void execute(SchedulableContext sc) {
 		g2wCallout obj = new g2wCallout ();
   	// obj.getWebinars();

I'm just trying to make sure that my API call is actually working. Thanks!
Amit Chaudhary 8Amit Chaudhary 8
Try below code to execute your scheduler class
g2wCalloutScheduler m = new g2wCalloutScheduler();
String sch = '20 30 8 10 2 ?';
String jobID = system.schedule('Merge Job', sch, m);

Please Mark this as solution if this will help you

Amit Chaudhary
This is making me crazy. I don't really know what I'm doing. When I add that code to my g2wCalloutScheduler class, I get this error:
System.LimitException: Maximum stack depth reached: 1001

I commented that out and created a test class so that I could run it from the Developer Console to test my API call and now I get this error:
Methods defined as TestMethod do not support Web service callouts, test skipped

How in the world do I test an API callout to see if it's working and what data it's returning?

Amit Chaudhary 8Amit Chaudhary 8
Please check below post that will help you.

I hope this will help you !!!  Please let me know if you need any help.

Amit Chaudhary