Debug API in Web SDK

VerifiedSafe

Diagnose HTTP/network/API failures in mParticle Web SDK through systematic request/response inspection and API client debugging.

Sby Skills Guide Bot
DevelopmentIntermediate
7/23/2026
Claude CodeCursorWindsurfCopilotCodex
#mparticle#api-debugging#web-sdk#http-errors#network-inspection

Recommended for

Automated summary

This skill guides diagnosis of network and API failures in the mParticle Web SDK, covering the Events, Identity and Config APIs through systematic request and response inspection.

Strengths

  • Classifies failures into precise buckets (request never sent, request fails, response wrong) with matching root causes
  • Points to the real SDK files (apiClient.ts, identityApiClient.ts, configAPIClient.ts, batchUploader.ts) to steer investigation
  • Explains fetch-mock versus real API divergence, usually caused by contract drift
  • Provides a concrete workflow: Network tab, client state logging, endpoint verification

Limitations

  • Highly specific to the mParticle Web SDK, not usable for other libraries or mobile SDKs
  • Does not cover destination kit errors beyond a brief mention of kit filtering
  • Assumes access to the SDK source code and the browser Network tab
When to use it

Use it when an HTTP request or API call from the mParticle Web SDK fails, returns an unexpected response, or appears stuck.

When not to use it

Do not use it to debug UI rendering issues or problems unrelated to the SDK's network and API layer.

Security analysis

Safe
Quality score88/100

The skill is a debugging guide and does not instruct destructive, exfiltrating, or obfuscated actions. It uses browser DevTools and console logging for legitimate diagnostics. The only notable concern is that it encourages logging potentially sensitive SDK state and identity payloads, which should be handled carefully.

Findings
  • •Recommends logging internal SDK state such as `mpInstance._Store`, `identityRequest`, and batch queues, which may expose API keys/devTokens, MPIDs, and user identity data in console logs; redaction guidance would improve safety.
How this analysis is made

Examples

Batch upload failing
Our mParticle Web SDK is logging 'batch upload failed' with a 500 from the events endpoint. Help me inspect the batch payload and figure out why the upload is rejected.
Identity callback never fires
The mParticle identify() callback never fires in production but works fine with fetch-mock in tests. Walk me through comparing the mock response to the real identity API DTO.
Config fetch returns 401
The config API call in our mParticle Web SDK returns 401 unauthorized on startup, so kits never initialize. Help me verify the devToken and workspace ID in the request.

name: debug-api description: Debug HTTP/network/API failures in mParticle Web SDK including fetch failed/fetch error/request failed/API call failed/endpoint not responding/401 unauthorized/403 forbidden/404 not found/500 internal server error/502 bad gateway/503 service unavailable/504 gateway timeout/network error/timeout/ETIMEDOUT/connection timeout/ECONNREFUSED/response format wrong/DTO mismatch/type mismatch in response/unexpected response/null response/undefined response/empty response/missing data/API contract changed/batch upload failed/identity API failed/config API failed/events API failed

API Debug Skill - Web SDK

Purpose

Diagnose network/API failures in the mParticle Web SDK through systematic request/response inspection and API client debugging.

Core Principles

  • Network tab is truth: Inspect actual requests, not assumptions
  • Mock vs real divergence: fetch-mock works but real API fails → contract drift
  • Batch timing matters: Events batched before upload (100 events or 30 seconds)
  • Three API systems: Events, Identity, and Config APIs have different shapes

Architecture Context

HTTP clients in src/apiClient.ts (Events), src/identityApiClient.ts (Identity), src/configAPIClient.ts (Config). Uses fetch API. Batch upload in src/batchUploader.ts. Tests use fetch-mock for HTTP mocking.

Failure Classification

Request never sent:

  • Network offline → browser blocking
  • Batch not full → waiting for 100 events or 30 second interval
  • API client not initialized → SDK init failed
  • Config disabled feature → server config blocking

Request fails:

  • 401 → Auth token invalid/expired
  • 403 → Workspace permissions issue
  • 404 → URL wrong (trailing slash, workspace ID, endpoint)
  • 500 → Backend error (check server logs)
  • Timeout → slow network/server hang
  • CORS → should not happen with mParticle APIs (same-origin or configured)

Response wrong:

  • DTO mismatch → backend changed contract
  • Null/undefined → optional fields missing
  • Type error → response shape unexpected
  • Empty response → valid but no data

SDK-specific issues:

  • Batch upload stuck → timer not advancing
  • Identity callback not fired → response parsing failed
  • Config not loading → initial config fetch failed
  • Events not forwarding → kits not initialized

Investigation Strategy

1. Network Inspection

Use browser DevTools Network tab:

  • Request URL (exact match with workspace ID)
  • Request headers (Content-Type, User-Agent)
  • Request payload (batch structure, identity request)
  • Response status (200/401/403/404/500)
  • Response body (success flags, error messages)
  • Timing (slow? timeout?)

2. API Client State

Log client state:

// In apiClient.ts
console.log({ url, payload, config: mpInstance._Store })

// In identityApiClient.ts
console.log({ identityRequest, callback })

// In batchUploader.ts
console.log({ batchSize, uploadInterval, queuedEvents })

3. Verify API Endpoints

Check endpoint construction:

  • Events: /v1/[workspace]/events
  • Identity: /v1/[workspace]/identify (or /login, /logout, /modify)
  • Config: /v1/[workspace]/config

Ensure workspace ID (devToken/apiKey) is correct.

4. fetch-mock vs Real API

If fetch-mock works but real fails:

  • Compare mock URL vs real endpoint
  • Check mock response shape vs real DTO
  • Verify auth headers match
  • Look for hardcoded test data

Common Root Causes

Auth failures:

  • API key (devToken) missing or wrong
  • API key passed incorrectly in request
  • Workspace disabled or suspended
  • Environment mismatch (dev key in production)

Events API issues:

  • Batch structure malformed
  • Event validation failed (data plan)
  • Consent state blocking events
  • Kit filtering rules blocking

Identity API issues:

  • Identity request validation failed
  • MPID not found (new user)
  • Identity callback error → silent failure
  • User identities malformed

Config API issues:

  • Config fetch failed → kits not initialized
  • Config cache stale → using old settings
  • Server-side config override → unexpected behavior

Batch upload issues:

  • Timer not advancing → events never sent
  • Batch size threshold not met → waiting for 100 events
  • Upload interval not met → waiting for 30 seconds
  • Network offline → queued but not sent

Obscure Debugging Vectors

  • Network throttling: Fast 3G reveals timeout issues
  • Disable cache: Force fresh requests to test caching theory
  • Copy as fetch: Right-click network request → replay in console
  • fetch-mock logging: Enable fetch-mock logging in tests
  • Batch queue inspection: Log mpInstance._Batch to see queued events
  • Identity MPID check: Verify MPID exists in localStorage
  • Config inspection: Check mpInstance._Store for loaded config
  • Session ID check: Verify session ID in event payload

Debugging Flow

  1. Reproduce failure, open network tab
  2. Identify request: sent? failed? wrong response?
  3. Check API key (devToken) in request
  4. Verify endpoint URL format (workspace ID, path)
  5. Compare fetch-mock handler vs real API response
  6. Log API client state before/after request
  7. Check batch queue status (if Events API)
  8. Test with network throttling enabled

Success Criteria

  • Request succeeds with correct response
  • Events uploaded to mParticle servers
  • Identity callbacks fire correctly
  • Config loaded and applied
  • Works across 3+ attempts (no fluke)
  • Screenshot: network tab + successful response

SDK-Specific API Patterns

Events API (/v1/[workspace]/events):

  • Batch of events in payload
  • Response indicates success/failure per event
  • Retry logic for failed uploads
  • Validate event structure before sending

Identity API (/v1/[workspace]/identify):

  • Single identity request
  • Callback with result (success/error)
  • MPID returned in response
  • User identities in request

Config API (/v1/[workspace]/config):

  • Fetched on SDK init
  • Contains kit configurations
  • Workspace settings
  • Feature flags

Common Headers:

Content-Type: application/json
User-Agent: mParticle web SDK

Test Debugging

fetch-mock configuration:

import fetchMock from 'fetch-mock/esm/client'

fetchMock.post('/v1/test-workspace/events', {
  status: 200,
  body: { Store: true }
})

Verify mock called:

expect(fetchMock.called('/v1/test-workspace/events')).toBe(true)

Check request payload:

const calls = fetchMock.calls('/v1/test-workspace/events')
console.log(JSON.parse(calls[0][1].body))

Self-Improvement

CRITICAL: Update with:

  • Events API contract changes
  • Identity API error patterns
  • Config API structure updates
  • Batch upload timing solutions
  • fetch-mock anti-patterns
  • Common SDK API failures

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/debug-api-in-web-sdk-mrx3xznw/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/debug-api-in-web-sdk-mrx3xznw' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/debug-api-in-web-sdk-mrx3xznw/download' --output '.skill-downloads/debug-api-in-web-sdk-mrx3xznw/SKILL.md.part' && mv '.skill-downloads/debug-api-in-web-sdk-mrx3xznw/SKILL.md.part' '.skill-downloads/debug-api-in-web-sdk-mrx3xznw/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/debug-api-in-web-sdk-mrx3xznw/SKILL.md' && test -s '.skill-downloads/debug-api-in-web-sdk-mrx3xznw/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/debug-api' && cp -R '.skill-downloads/debug-api-in-web-sdk-mrx3xznw' '.claude/skills/debug-api'

Cursor
test -f '.skill-downloads/debug-api-in-web-sdk-mrx3xznw/SKILL.md' && test -s '.skill-downloads/debug-api-in-web-sdk-mrx3xznw/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/debug-api' && cp -R '.skill-downloads/debug-api-in-web-sdk-mrx3xznw' '.cursor/skills/debug-api'

Codex
test -f '.skill-downloads/debug-api-in-web-sdk-mrx3xznw/SKILL.md' && test -s '.skill-downloads/debug-api-in-web-sdk-mrx3xznw/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/debug-api' && cp -R '.skill-downloads/debug-api-in-web-sdk-mrx3xznw' '.agents/skills/debug-api'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/debug-api-in-web-sdk-mrx3xznw'

openskills read 'debug-api-in-web-sdk-mrx3xznw'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/debug-api-in-web-sdk-mrx3xznw/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills