Use case: Using Apex to call or test ServiceNow CPQ APIs

use_case_how_to_use_apex_to_calltest_logik_apis.md
Raw file

Learn how to use Apex to call or to test ServiceNow CPQ APIs.

The easiest way to test Apex code for use of ServiceNow CPQ is through the developer console in SFDC.

[Omitted image "cpq-using-apex-developer-console.png"] Alt text: User interface

To test the script from in the console, the code must be wrapped in a larger class with the “exec” function. For example:

Text
public class testGetConfig { public static void exec() {

Save the code, and then in the Debug menu, click Execute Anonymous Window.

[Omitted image "cpq-using-apex-anonymous-window.png"] Alt text: Debug menu

In the execute anonymous window, execute the code functionName.exec();

Example Apex code to call a ServiceNow CPQ API

The following code is an example of an Apex class that will get information about a potential configuration:

JavaScript
1 public class testGetConfig {2 	public static void exec(){34 		HttpRequest httpRequest = new HttpRequest();httpRequest.setEndpoint('https://tenant.sector.logik.io/api/[config id here]');httpRequest.setTimeout(5000);56 		httpRequest.setMethod('GET'); httpRequest.setHeader('Content-Type', 'application/json');78 		httpRequest.setHeader('Authorization', 'Bearer [INSERT TOKEN HERE]');httpRequest.setHeader('Origin', 'https://tenant.sector.logik.io/');910 		Http http = new Http(); HttpResponse httpResponse;1112 		httpResponse = http.send(httpRequest);1314 	}15 }

This code would be executed as testGetConfig.exec();.

Parent Topic:Use cases

Search documentation
Search document titles and file paths on the brazil branch