Skip to main content

API Client Configuration

This guide covers HTTP client configuration for optimal Squid API performance. For background on why these settings matter, see API Throughput.

Disable Session Cookies

Why This Matters

ServiceNow enforces session synchronization, processing only one transaction per session at a time. When your HTTP client persists cookies, all requests serialize into a queue—each waiting for the previous one to complete.

With CookiesWithout Cookies
All requests queue behind each otherRequests process in parallel
Single node handles all trafficLoad balancer distributes across cluster
Risk of HTTP 202 silent failuresEach request independent
Long-running queries block everythingOptimal throughput

Squid queries routinely take minutes to complete. A single long-running query would block all other requests from your integration if session cookies are enabled.

HTTP 202: Silent Data Loss

When session queue thresholds are exceeded, ServiceNow returns HTTP 202 Accepted. Despite the seemingly positive status code, these requests are NOT processed—they are silently dropped.

ServiceNow triggers HTTP 202 when:

ConditionThreshold
Queued transactions per session>10 (Tokyo and later)
Current transaction duration>30 seconds

Squid queries frequently exceed 30 seconds, making HTTP 202 a real risk when reusing sessions.

HTTP 202 means data loss

In documented testing, 100 concurrent requests to the same session resulted in only 12 receiving HTTP 200 (processed), while 88 received HTTP 202 and were completely ignored. Do not treat HTTP 202 as success.

Code Examples

Configure your HTTP client to NOT persist cookies between requests:

# No cookie jar = no session reuse (default behavior)
curl -u user:password "https://instance.service-now.com/api/x_a46gh_squidx/v1/data/cmdb_ci_server"

OAuth Authentication

Enterprise integrations typically authenticate against a central identity provider (Active Directory, Entra ID, Okta, etc.) rather than using ServiceNow local accounts. Your identity provider issues an OAuth token that ServiceNow is configured to trust.

Configuration varies by organization

The examples below show Microsoft Entra ID. Your organization may use a different identity provider with different endpoints and parameters. Work with your identity and ServiceNow teams for the correct configuration.

Cookie handling still applies

Even with OAuth, ServiceNow returns session cookies. If your HTTP client persists these cookies, you'll hit the same session synchronization bottleneck. The cookie handling advice above still applies.

Obtaining an Access Token

Request an access token from your identity provider. The exact endpoint and parameters depend on your provider. This example shows Microsoft Entra ID (formerly Azure AD):

# Microsoft Entra ID example
curl -X POST "https://login.microsoftonline.com/YOUR_TENANT_ID/oauth2/v2.0/token" \
-d "grant_type=client_credentials" \
-d "client_id=YOUR_CLIENT_ID" \
-d "client_secret=YOUR_CLIENT_SECRET" \
-d "scope=YOUR_SERVICENOW_APP_ID/.default"

Using the Token

Include the access token in the Authorization header:

curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
"https://instance.service-now.com/api/x_a46gh_squidx/v1/data/cmdb_ci_server"

Token Refresh

OAuth tokens expire (typically after 60-90 minutes, depending on your identity provider configuration). Your integration should handle token refresh:

  • Check expiration before each request, or
  • Catch 401 responses and request a new token

The token response includes expires_in (seconds until expiration). Store the token acquisition time and refresh proactively before expiration.

Configure Appropriate Timeouts

Squid queries can take 10-15 minutes for large datasets. Configure your HTTP client timeouts accordingly:

Timeout TypeRecommended ValueReason
Connection timeout30 secondsEstablish connection quickly
Read timeout900+ secondsAllow long-running queries to complete
# cURL uses --connect-timeout and --max-time (total time including transfer)
curl --connect-timeout 30 --max-time 900 \
-u user:password "https://instance.service-now.com/api/x_a46gh_squidx/v1/data/cmdb_ci_server"
Server-side timeouts

Your ServiceNow administrator must also configure server-side transaction quota rules to allow long-running Squid queries. See ServiceNow Configuration.

HTTP Response Code Reference

CodeMeaningAction
200SuccessRequest processed
202AcceptedRequest NOT processed — session queue full. Check cookie handling.
401UnauthorizedInvalid credentials
403ForbiddenMissing x_a46gh_squidx.rest role
429Too Many RequestsCapacity exceeded. Review ServiceNow Configuration.
503Service UnavailablePlatform overload. Contact ServiceNow administrator.

Complete Example: Squid Client

#!/bin/bash
# Squid API client with Entra ID authentication

TENANT_ID="your_entra_tenant_id"
CLIENT_ID="your_client_id"
CLIENT_SECRET="your_client_secret"
SCOPE="api://your_servicenow_app_id/.default"
INSTANCE_URL="https://instance.service-now.com"

# Get OAuth token from Entra ID
get_token() {
curl -s -X POST "https://login.microsoftonline.com/$TENANT_ID/oauth2/v2.0/token" \
-d "grant_type=client_credentials" \
-d "client_id=$CLIENT_ID" \
-d "client_secret=$CLIENT_SECRET" \
-d "scope=$SCOPE" | jq -r '.access_token'
}

# Call Squid API
TOKEN=$(get_token)
curl --connect-timeout 30 --max-time 900 \
-H "Authorization: Bearer $TOKEN" \
"$INSTANCE_URL/api/x_a46gh_squidx/v1/data/cmdb_ci_server?limit=1000"
We track. Ok?