This guide simplifies the process, covering JWT Authentication setup, GPT actions, schema… and key configurations.
1- Install the JWT Authentication Plugin
- Download and install from: JWT Authentication for WP REST API
- Access your WordPress site’s root directory using FTP.
- Open and edit the
.htaccess
file to enable PHP HTTP Authorization Header. Add the following lines:
RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
Save the .htaccess
file. (Note: Ensure your hosting allows .htaccess
file modifications.)
2-Configure the Secret Key
- Open and edit
wp-config.php
. - Add a new constant called
JWT_AUTH_SECRET_KEY
:
define('JWT_AUTH_SECRET_KEY', 'your-top-secret-key');
Replace 'your-top-secret-key'
with a unique secret key, you can use a string from here.
3-Configure CORS Support
In wp-config.php
, add a new constant called JWT_AUTH_CORS_ENABLE
:
define('JWT_AUTH_CORS_ENABLE', true);
Save wp-config.php
.
4-Testing with Postman or HTTPie
Submit a POST request to the following endpoint (no authentication, only JSON body):
https://yourwordpress.com/wp-json/jwt-auth/v1/token
JSON body:
{
"username": "your-username",
"password": "your-password"
}
Copy and save your token.
Now, submit a POST request to this endpoint:
wp-json/wp/v2/posts/
Header:
Authorization: Bearer {token}
good!
now, Create a new action in your GPT configuration, and use the API schema below ( don’t forget to edit your server URL. )
{
"openapi": "3.1.0",
"info": {
"title": "WordPress API",
"description": "API for creating and editing posts in WordPress",
"version": "1.0.0"
},
"servers": [
{
"url": "https://yourwordpress.com/wp-json"
}
],
"paths": {
"/wp/v2/posts": {
"post": {
"summary": "Create a new post",
"operationId": "createPost",
"tags": ["Posts"],
"requestBody": {
"description": "Post data",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Post"
}
}
},
"required": true
},
"responses": {
"201": {
"description": "Post created",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Post"
}
}
}
}
}
}
},
"/wp/v2/posts/{id}": {
"put": {
"summary": "Edit an existing post",
"operationId": "editPost",
"tags": ["Posts"],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "integer"
},
"description": "The ID of the post to edit"
}
],
"requestBody": {
"description": "Updated post data",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Post"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Post updated",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Post"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Post": {
"type": "object",
"properties": {
"title": {
"type": "string"
},
"content": {
"type": "string"
},
"status": {
"type": "string"
}
}
}
}
}
}
Change the Authentication type to Bearer Token and paste your saved token.
Now ,Test the integration by sending a request through chat or click here
that’s it!
for any problems or feedback, don’t hesitate to share.