The NMI payment gateway API is not one API. It is a set of endpoints: the classic Payment API (transact.php) that creates transactions, Collect.js that tokenizes card data in the browser, the Query API that reads transactions back, webhooks that push events to you, and a newer REST API (v5). Most WooCommerce plugins use the first two. This guide tells you which piece does what, so you know where to look when something breaks.
What each part of the NMI API does
NMI’s own documentation now steers new builds toward the Payment Component and REST API v5, and describes Collect.js and the classic API as documented for existing integrations. They remain documented and are what most WooCommerce plugins call today. Check docs.nmi.com for the current state before you build anything custom.
- Payment API.
POST https://secure.nmi.com/api/transact.phpwith asecurity_keyand atypesuch as sale, auth, capture, void, refund or validate. The reply is a plainname=value&name=valuestring. - Collect.js. A script that puts NMI-hosted fields on your checkout, so card numbers go to NMI and your site only receives a single-use
payment_token. It is not a payment API by itself; you send the token to the Payment API. - Query API.
POST https://secure.nmi.com/api/query.php, returns XML. Use it to look up a transaction by ID or order ID, or to pull vault and recurring records. - Webhooks. NMI posts signed events (sale, refund, settlement batch and so on) to an HTTPS URL you set in the Merchant Portal.
The three key types
Credentials cause more integration trouble than code. A private security key goes with Payment API and Query API calls from your server. A public tokenization key is for Collect.js only, is visible in page source by design, and does not work for other calls. An API key will not work with Collect.js. Both are created under Settings, Security Keys. Details are on our gateway credentials page.
How a card payment flows
- Collect.js on your checkout loads NMI iframes for card number, expiry and CVV.
- The customer submits; NMI returns a
payment_token(single use, expires after 24 hours if unused). - Your server posts that token with the amount and order ID to the Payment API.
- The reply carries
response(1 approved, 2 declined, 3 error),responsetext,transactionid,authcode, AVS and CVV results and a numericresponse_code. - Your store records the result. You can confirm it later with the Query API.
This split is why card data never needs to touch your server. The idea is covered in what tokenisation really is.
Reading the response correctly
Branch on response first, then use response_code for the detail. The 2xx codes are issuer declines, 300 is a gateway rejection, and 4xx are processor or merchant configuration errors. Always log responsetext too, because NMI documents numeric codes but the text is free form and usually includes a REFID that support will ask for. The full table is in NMI gateway response codes.
Rules of thumb before you call it
- Test against a sandbox account or test mode first. Under test conditions an amount below 1.00 declines and a fatal error follows an invalid card number. See test cards and scenarios.
- Never log the security key or full request bodies with card data. If you must debug, redact.
- Respect rate limits. NMI documents a rate-limit reply (
response_code=301) and HTTP 429. Do not retry in a tight loop. - Treat a timeout as unknown, not failed. Query the transaction before you retry, or you risk a double charge.
- Keep the key server-side and out of the repository.
What your gateway provider controls
The API is NMI’s, but your account may live under a reseller or ISO. They control which processor you use, which features (ACH, Level 3, Apple Pay, 3DS) are enabled, and sometimes the domain you log in to. A call that is valid can still fail with a 4xx or feature-not-available error because of account setup. Not sure who you are with? Read gateway, processor, merchant account and is your gateway NMI powered.
How NMIWP helps
The free NMIWP plugin handles the integration for you: hosted card fields through Collect.js, sale, authorize and validate transaction types, partial capture and refund, and the gateway response (auth code, transaction ID, AVS and CVV results, raw response code) written into the order notes, with redacted logging. Pro adds 3D Secure 2, Apple Pay and Google Pay, ACH and the Customer Vault. Whether a given custom Query API workflow is covered is not stated on the site, so check the current docs. Developers can start at the developer resources hub.
Quick answers
Is NMI’s API free to use?
Access depends on your gateway account, and pricing is set by your provider. Ask them; this site cannot quote it.
Do I need Collect.js?
Not strictly, but without it card numbers pass through your server, which raises your PCI scope. Confirm with your acquirer.
Why does my key work for one call and not another?
Keys inherit the permissions of the user they are tied to, and tokenization keys only work with Collect.js. See bad auth response causes.
Where do I start debugging?
Read response_code and responsetext in the order notes, then check the credentials and account setup before changing code.
Running NMI on WooCommerce? Free covers the basics and Pro adds the paid features. Compare Free and Pro.
More in this series: NMI White Label Payment Gateway: How Reseller Branding Works | What Is the NMI Payment Gateway? A Plain Guide for WooCommerce Owners | NMI Login: Finding Your Gateway Merchant Portal
Last reviewed November 2026.