Use case: Using Apex to call or test ServiceNow CPQ APIs
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:
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:
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
---
title: Use case: Using Apex to call or test ServiceNow CPQ APIs
description: Learn how to use Apex to call or to test ServiceNow CPQ APIs.
locale: en-US
canonical_url: https://www.servicenow.com/docs/r/order-management/use\_case\_how\_to\_use\_apex\_to\_calltest\_logik\_apis.html
release: brazil
topic_type: concept
last_updated: "2026-03-12"
reading_time_minutes: 1
breadcrumb: [Use cases, Using ServiceNow CPQ, ServiceNow CPQ Configurator, Configure, price, quote apps, Use, Sales Customer Relationship Management]
---
# Use case: Using Apex to call or test ServiceNow CPQ APIs
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:
```
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:
```
1 public class testGetConfig {
2 public static void exec(){
3
4 HttpRequest httpRequest = new HttpRequest();
httpRequest.setEndpoint('https://tenant.sector.logik.io/api/[config id here]');
httpRequest.setTimeout(5000);
5
6 httpRequest.setMethod('GET'); httpRequest.setHeader('Content-Type', 'application/json');
7
8 httpRequest.setHeader('Authorization', 'Bearer [INSERT TOKEN HERE]');
httpRequest.setHeader('Origin', 'https://tenant.sector.logik.io/');
9
10 Http http = new Http(); HttpResponse httpResponse;
11
12 httpResponse = http.send(httpRequest);
13
14 }
15 }
```
This code would be executed as `testGetConfig.exec();`.
**Parent Topic:**[Use cases](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/brazil/markdown/order-management/use-cases.md)
This file has no frontmatter.