Title: API for Ninja Forms
Author: sightfactory
Published: <strong>2025 年 7 月 11 日</strong>
Last modified: 2026 年 9 月 15 日

---

搜索插件

![](https://ps.w.org/api-for-ninja-forms/assets/banner-772x250.png?rev=3697197)

![](https://ps.w.org/api-for-ninja-forms/assets/icon-256x256.png?rev=3697241)

# API for Ninja Forms

 作者：[sightfactory](https://profiles.wordpress.org/sightfactory/)

[下载](https://downloads.wordpress.org/plugin/api-for-ninja-forms.1.1.0.zip)

 * [详情](https://cn.wordpress.org/plugins/api-for-ninja-forms/#description)
 * [评价](https://cn.wordpress.org/plugins/api-for-ninja-forms/#reviews)
 *  [安装](https://cn.wordpress.org/plugins/api-for-ninja-forms/#installation)
 * [开发进展](https://cn.wordpress.org/plugins/api-for-ninja-forms/#developers)

 [支持](https://wordpress.org/support/plugin/api-for-ninja-forms/)

## 描述

API for Ninja Forms is **the best, most powerful, and feature-complete REST API 
solution** for Ninja Forms. Effortlessly export and integrate your form submissions
with external applications, webhooks, and analytics platforms with **unparalleled
speed, reliability, and security**.

Whether you need automated Excel reporting, instant PDF downloads, structured JSON
data feeds, or real-time data synchronization, API for Ninja Forms delivers a best-
in-class integration experience built for modern developers and business workflows.

### Why API for Ninja Forms is the Best Choice:

 * **Forms Discovery Endpoint:** Query authorized forms, submission counts, and 
   field definitions with strict per-key access control.
 * **Cursor & Offset Pagination:** Seamlessly paginate large historical datasets
   with `page`/`per_page` or cursor sync via `since_id`/`before_id`.
 * **Single Record Retrieval:** Instant lookup of specific submissions (`/form/{
   id}/submission/{sub_id}`) with cross-form ownership validation.
 * **Unparalleled Multi-Format Exports:** Stream submissions on-demand in 6 versatile
   formats: JSON, Excel (XLSX), PDF document reports, CSV spreadsheets, XML, and
   NDJSON/JSONL.
 * **Military-Grade Payload Encryption:** Protect sensitive customer and form data
   with state-of-the-art AEAD response encryption (AES-256-GCM, AES-128-GCM, and
   Sodium Secretbox).
 * **Advanced Rate Limiting Protection:** Safeguard your server against scraping,
   probing, and brute-force key exploitation with admin-controlled rate limits per
   minute, hour, or day.
 * **Granular Form Access Control:** Issue form-specific API keys with instant 1-
   click test suite tools and single-page key management.
 * **Lightning-Fast & Ultra-Optimized:** Zero-overhead streaming designed for high
   throughput, low memory footprint, and maximum performance.

### Usage

### 1. Authentication

Pass your API key in the standard HTTP Authorization header:
 Authorization: Bearer
YOUR_API_KEY

### 2. Available Endpoints

 * **Discover Authorized Forms:**
    GET /wp-json/nf-submissions/v1/forms Returns 
   all forms the authenticated key is authorized to access, with total submission
   counts and field counts.
 * **Retrieve Submissions (with Pagination & Sorting):**
    GET /wp-json/nf-submissions/
   v1/form/{form_id} Query parameters:
    - `page` (default: 1): Page number for offset pagination.
    - `per_page` / `limit` (default: 50, max: 500): Number of records per page.
    - `offset`: Explicit record offset (overrides `page`).
    - `since_id` / `after_id`: Retrieve only submissions with ID greater than this
      value (cursor pagination).
    - `before_id` / `max_id`: Retrieve only submissions with ID less than this value.
    - `order`: `asc` (default) or `desc`.
    - `orderby`: `date` (default), `id`, `title`, or `modified`.
    - `begin_date` & `end_date`: Filter by submission date range (`YYYY-MM-DD`).
    - `format`: `json` (default), `csv`, `xlsx`, `pdf`, `xml`, or `jsonl`.
 * **Retrieve Single Submission:**
    GET /wp-json/nf-submissions/v1/form/{form_id}/
   submission/{submission_id} Returns the exact submission record. Validates that
   the submission belongs to the specified form.
 * **Retrieve Form Field Metadata:**
    GET /wp-json/nf-submissions/v1/form/{form_id}/
   fields Returns the list of field labels, keys, and types for the specified form.

### 3. Pagination & Headers

When retrieving submissions in JSON format, standard pagination headers are included
in the response:
 * `X-WP-Total`: Total count of matching submissions. * `X-WP-TotalPages`:
Total calculated pages. * `X-WP-Page`: Current page number. * `X-WP-PerPage`: Records
per page limit. * `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset`:
Rate-limiting status (if enabled).

### 4. Payload Encryption & Decryption

When payload encryption is enabled on an API key:
 * **Text Feeds (JSON, CSV, XML,
JSONL):** Encrypted as a JSON envelope containing `iv`, `tag`, and `ciphertext`.***
Binary Streams (PDF, XLSX):** Delivered as raw binary (`.enc` extension) with cryptographic
headers (`X-Crypto-IV`, `X-Crypto-Tag`, `X-Crypto-Nonce`, `X-Crypto-Algorithm`).

### 5. PHP Code Examples (cURL & wp_remote_get)

 * **Discover Authorized Forms via Native PHP cURL:**
    `php $ch = curl_init( ‘https://
   example.com/wp-json/nf-submissions/v1/forms’ ); curl_setopt_array( $ch, [ CURLOPT_RETURNTRANSFER
   => true, CURLOPT_HTTPHEADER => [ ‘Authorization: Bearer YOUR_API_KEY’, ‘Accept:
   application/json’, ], ] ); $response = curl_exec( $ch ); $http_status = curl_getinfo(
   $ch, CURLINFO_HTTP_CODE ); curl_close( $ch );

$data = json_decode( $response, true );

// Graceful error handling for invalid API key or server error
 if ( 200 !== $http_status
|| ! is_array( $data ) || isset( $data[‘code’] ) ) { $error = $data[‘message’] ??‘
Failed to retrieve forms’; exit( “API Error ({$http_status}): {$error}\n” ); }

foreach ( $data as $form ) {
 echo “Form ID: {$form[‘id’]} | Title: {$form[‘title’]}
| Submissions: {$form[‘submissions_count’]}\n”; } `

 * **Fetch Submissions via Native PHP cURL (External Apps / Scripts):**
    `php $ch
   = curl_init( ‘https://example.com/wp-json/nf-submissions/v1/form/1?page=1&per_page
   =50’ ); curl_setopt_array( $ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER
   => [ ‘Authorization: Bearer YOUR_API_KEY’, ‘Accept: application/json’, ], ] );
   $response = curl_exec( $ch ); $http_status = curl_getinfo( $ch, CURLINFO_HTTP_CODE);
   curl_close( $ch );

$data = json_decode( $response, true );

if ( 200 !== $http_status || ! is_array( $data ) || isset( $data[‘code’] ) ) {
 
$error = $data[‘message’] ?? ‘Failed to retrieve submissions’; exit( “API Error ({
$http_status}): {$error}\n” ); }

$submissions = $data;
 `

 * **Download Binary PDF / Excel (.xlsx) File via Native PHP cURL:**
    `php $ch =
   curl_init( ‘https://example.com/wp-json/nf-submissions/v1/form/1?format=pdf’ );
   curl_setopt_array( $ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION
   => true, CURLOPT_HTTPHEADER => [ ‘Authorization: Bearer YOUR_API_KEY’, ], ] );
   $file_contents = curl_exec( $ch ); $http_status = curl_getinfo( $ch, CURLINFO_HTTP_CODE);
   curl_close( $ch );

if ( 200 === $http_status ) {
 file_put_contents( ‘submissions.pdf’, $file_contents);}
else { $error = json_decode( $file_contents, true ); echo “API Error ({$http_status}):”.(
$error[‘message’] ?? ‘Download failed’ ) . “\n”; } `

 * **Discover Authorized Forms via WordPress HTTP API (wp_remote_get):**
    `php $
   response = wp_remote_get( ‘https://example.com/wp-json/nf-submissions/v1/forms’,[‘
   headers’ => [ ‘Authorization’ => ‘Bearer YOUR_API_KEY’ ], ] );

if ( is_wp_error( $response ) ) {
 exit( ‘Network Error: ‘ . $response->get_error_message());}

$status = wp_remote_retrieve_response_code( $response );
 $data = json_decode( wp_remote_retrieve_body(
$response ), true );

// Graceful error handling for invalid API key or server error
 if ( 200 !== $status
|| ! is_array( $data ) || isset( $data[‘code’] ) ) { $error = $data[‘message’] ??‘
Failed to retrieve forms’; exit( “API Error ({$status}): {$error}\n” ); }

foreach ( $data as $form ) {
 echo “Form ID: {$form[‘id’]} | Title: {$form[‘title’]}
| Submissions: {$form[‘submissions_count’]}\n”; } `

 * **Fetch Submissions via WordPress HTTP API (wp_remote_get):**
    `php $response
   = wp_remote_get( ‘https://example.com/wp-json/nf-submissions/v1/form/1’, [ ‘headers’
   => [ ‘Authorization’ => ‘Bearer YOUR_API_KEY’ ], ] );

if ( is_wp_error( $response ) ) {
 exit( ‘Network Error: ‘ . $response->get_error_message());}

$status = wp_remote_retrieve_response_code( $response );
 $data = json_decode( wp_remote_retrieve_body(
$response ), true );

if ( 200 !== $status || ! is_array( $data ) || isset( $data[‘code’] ) ) {
 $error
= $data[‘message’] ?? ‘Failed to retrieve submissions’; exit( “API Error ({$status}):{
$error}\n” ); }

$submissions = $data;
 `

### Third-Party Resources

This plugin bundles and utilizes the following open-source library:

 * **Setasign/FPDF**
    - **Description:** A pure PHP library for reading and writing PDF files.
    - **Homepage:** [https://github.com/Setasign/FPDF](https://github.com/Setasign/FPDF)
    - **License:** FPDF License (compatible with MIT/BSD-style)
    - **License URI:** [https://github.com/Setasign/FPDF?tab=License-1-ov-file#readme](https://github.com/Setasign/FPDF?tab=License-1-ov-file#readme)

### Support

For support and feature requests, please visit [https://sightfactory.com](https://sightfactory.com)

## 屏幕截图

[⌊Granular API key management with per-form access controls, expiration dates, and
rate limits.⌉⌊Granular API key management with per-form access controls, expiration
dates, and rate limits.⌉[

Granular API key management with per-form access controls, expiration dates, and
rate limits.

[⌊End-to-end response payload encryption (AES-256-GCM & Sodium Secretbox) with secret
key controls.⌉⌊End-to-end response payload encryption (AES-256-GCM & Sodium Secretbox)
with secret key controls.⌉[

End-to-end response payload encryption (AES-256-GCM & Sodium Secretbox) with secret
key controls.

[⌊Interactive developer documentation with ready-to-use PHP, JavaScript, and cURL
examples.⌉⌊Interactive developer documentation with ready-to-use PHP, JavaScript,
and cURL examples.⌉[

Interactive developer documentation with ready-to-use PHP, JavaScript, and cURL 
examples.

## 安装

 1. Download the plugin ZIP file.
 2. Upload the extracted folder to the `/wp-content/plugins/` directory.
 3. Activate the plugin through the ‘Plugins’ menu in WordPress.
 4. Generate a REST API key by navigating to **Settings > NF API Keys**.
 5. Make authenticated REST requests by including the header: `Authorization: Bearer
    YOUR_API_KEY`.

## 常见问题

### What API file formats are supported?

JSON, CSV, XLSX (Microsoft Excel), PDF, XML, and NDJSON/JSONL formats are supported.

### How do I synchronize new submissions in real-time?

Use cursor pagination with `?since_id={last_synced_id}&order=asc`. Your application
only receives new submissions created since the last sync.

### How do I enable response payload encryption?

Navigate to Settings > NF API Keys in your WordPress dashboard, check “Enable Response
Payload Encryption”, select your cipher strategy (AES-256-GCM, AES-128-GCM, or Sodium
Secretbox), and generate a key. Keep your secret decryption key safe.

### Why does an encrypted PDF or XLSX file end in .enc?

Binary files exported with encryption enabled are saved with a `.enc` file extension(
e.g., `form-1-submissions-encrypted.pdf.enc`). Because the file content consists
of raw encrypted bytes, attempting to open the file directly in Adobe Reader or 
Microsoft Excel without decrypting it first will report a corrupted file error. 
The `.enc` extension clearly indicates that the file must be decrypted using your
secret key first.

### How do I decrypt binary files (PDF & XLSX) using PHP?

Read the binary body and HTTP response headers (`X-Crypto-IV`, `X-Crypto-Tag`):
`
php $response = wp_remote_get(‘https://example.com/wp-json/nf-submissions/v1/form/
1?format=pdf’, [ ‘headers’ => [‘Authorization’ => ‘Bearer YOUR_API_KEY’] ]);

if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response)){

exit( ‘Download failed or unauthorized.’ ); }

$headers = wp_remote_retrieve_headers($response);
 $binary_key = hex2bin(‘YOUR_DECRYPTION_KEY’);
$iv = base64_decode($headers[‘x-crypto-iv’]); $tag = base64_decode($headers[‘x-crypto-
tag’]);

$decrypted_pdf = openssl_decrypt(
 wp_remote_retrieve_body($response), ‘aes-256-
gcm’, $binary_key, OPENSSL_RAW_DATA, $iv, $tag ); file_put_contents(‘submissions.
pdf’, $decrypted_pdf); `

### How do I decrypt JSON payloads using PHP?

Parse the JSON response envelope and decrypt using OpenSSL:
 `php $json = json_decode(
$response_body, true); if (!empty($json['encrypted'])) { $binary_key = hex2bin('
YOUR_DECRYPTION_KEY'); $plaintext = openssl_decrypt( base64_decode($json['ciphertext']),
$json['algorithm'], $binary_key, OPENSSL_RAW_DATA, base64_decode($json['iv']), base64_decode(
$json['tag']) ); $data = json_decode($plaintext, true); }

### Does this plugin slow down my website?

No. Text feeds use lightweight JSON structures and binary feeds use raw stream transmission
to ensure high throughput and low memory usage.

## 评价

此插件暂无评价。

## 贡献者及开发者

「API for Ninja Forms」是开源软件。 以下人员对此插件做出了贡献。

贡献者

 *   [ sightfactory ](https://profiles.wordpress.org/sightfactory/)

[帮助将「API for Ninja Forms」翻译成简体中文。](https://translate.wordpress.org/projects/wp-plugins/api-for-ninja-forms)

### 对开发感兴趣吗?

您可以[浏览代码](https://plugins.trac.wordpress.org/browser/api-for-ninja-forms/)，
查看[SVN仓库](https://plugins.svn.wordpress.org/api-for-ninja-forms/)，或通过[RSS](https://plugins.trac.wordpress.org/log/api-for-ninja-forms/?limit=100&mode=stop_on_copy&format=rss)
订阅[开发日志](https://plugins.trac.wordpress.org/log/api-for-ninja-forms/)。

## 更新日志

#### 1.1.0

 * Added export format support for XLSX (Microsoft Excel), CSV, XML, and NDJSON/
   JSONL.
 * Added record limit support (?limit=N) for pagination and performance control.
 * Implemented real-time browser Web Crypto decryption preview for encrypted feeds.
 * Updated Setasign/FPDF library to version 1.9.0.
 * Enhanced security, superglobal unslashing, and full WP Plugin Check compliance.

#### 1.0.1

Bugfix

#### 1.0.0

Initial public release

## 额外信息

 *  版本 **1.1.0**
 *  最后更新：**1 周前**
 *  活跃安装数量 **10+**
 *  WordPress 版本 ** 6.4 或更高版本 **
 *  已测试的最高版本为 **7.1.2**
 *  PHP 版本 ** 8.1 或更高版本 **
 *  语言
 * [English (US)](https://wordpress.org/plugins/api-for-ninja-forms/)
 * 标签
 * [api](https://cn.wordpress.org/plugins/tags/api/)[ninja forms](https://cn.wordpress.org/plugins/tags/ninja-forms/)
   [NinjaForms](https://cn.wordpress.org/plugins/tags/ninjaforms/)[rest-api](https://cn.wordpress.org/plugins/tags/rest-api/)
 *  [高级视图](https://cn.wordpress.org/plugins/api-for-ninja-forms/advanced/)

## 评级

尚未提交反馈。

[您的评价](https://wordpress.org/support/plugin/api-for-ninja-forms/reviews/#new-post)

[查看全部评论](https://wordpress.org/support/plugin/api-for-ninja-forms/reviews/)

## 贡献者

 *   [ sightfactory ](https://profiles.wordpress.org/sightfactory/)

## 支持

有话要说吗？是否需要帮助？

 [查看支持论坛](https://wordpress.org/support/plugin/api-for-ninja-forms/)