-
-
Notifications
You must be signed in to change notification settings - Fork 70
Fix enhance api requests #309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -100,6 +100,7 @@ public function get_fields() { | |
| return [ | ||
| 'WU_ENHANCE_API_TOKEN' => [ | ||
| 'type' => 'password', | ||
| 'html_attr' => ['autocomplete' => 'new-password'], | ||
| 'title' => __('Enhance API Token', 'ultimate-multisite'), | ||
| 'placeholder' => __('Your bearer token', 'ultimate-multisite'), | ||
| ], | ||
|
|
@@ -137,13 +138,11 @@ public function on_add_domain($domain, $site_id): void { | |
| $domain_response = $this->send_enhance_api_request( | ||
| '/servers/' . $server_id . '/domains', | ||
| 'POST', | ||
| [ | ||
| 'domain' => $domain, | ||
| ] | ||
| $domain | ||
| ); | ||
|
|
||
| // Check if domain was added successfully | ||
| if (wu_get_isset($domain_response, 'id')) { | ||
| if (wu_get_isset($domain_response, 'domainid')) { | ||
| wu_log_add('integration-enhance', sprintf('Domain %s added successfully. SSL will be automatically provisioned via LetsEncrypt when DNS resolves.', $domain)); | ||
| } elseif (isset($domain_response['error'])) { | ||
| wu_log_add('integration-enhance', sprintf('Failed to add domain %s. Error: %s', $domain, wp_json_encode($domain_response))); | ||
|
|
@@ -179,10 +178,10 @@ public function on_remove_domain($domain, $site_id): void { | |
|
|
||
| $domain_id = null; | ||
|
|
||
| if (isset($domains_list['items']) && is_array($domains_list['items'])) { | ||
| foreach ($domains_list['items'] as $item) { | ||
| if (isset($item['domain']) && $item['domain'] === $domain) { | ||
| $domain_id = $item['id']; | ||
| if (isset($domains_list['domains']) && is_array($domains_list['domains'])) { | ||
| foreach ($domains_list['domains'] as $item) { | ||
| if (isset($item['domainName']) && $item['domainName'] === $domain) { | ||
| $domain_id = $item['domainId']; | ||
| break; | ||
| } | ||
| } | ||
|
|
@@ -250,8 +249,7 @@ public function test_connection(): void { | |
|
|
||
| // Test by attempting to list domains | ||
| $response = $this->send_enhance_api_request( | ||
| '/servers/' . $server_id . '/domains', | ||
| 'GET' | ||
| '/servers/' . $server_id | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cd inc/integrations/host-providers && wc -l class-enhance-host-provider.phpRepository: Multisite-Ultimate/ultimate-multisite Length of output: 116 🏁 Script executed: cd inc/integrations/host-providers && sed -n '240,270p' class-enhance-host-provider.phpRepository: Multisite-Ultimate/ultimate-multisite Length of output: 1009 🏁 Script executed: cd inc/integrations/host-providers && sed -n '1,50p' class-enhance-host-provider.phpRepository: Multisite-Ultimate/ultimate-multisite Length of output: 1179 🏁 Script executed: git -C . log --oneline --all -- inc/integrations/host-providers/class-enhance-host-provider.php | head -20Repository: Multisite-Ultimate/ultimate-multisite Length of output: 151 🏁 Script executed: git -C . show HEAD:inc/integrations/host-providers/class-enhance-host-provider.php | sed -n '240,270p'Repository: Multisite-Ultimate/ultimate-multisite Length of output: 1009 🏁 Script executed: git -C . log -p --all -- inc/integrations/host-providers/class-enhance-host-provider.php | grep -A 5 -B 5 "servers.*domains\|servers.*{id}" | head -100Repository: Multisite-Ultimate/ultimate-multisite Length of output: 1784 🏁 Script executed: git -C . show 0e6b983 --statRepository: Multisite-Ultimate/ultimate-multisite Length of output: 50393 🏁 Script executed: git -C . show 0e6b983 -- inc/integrations/host-providers/class-enhance-host-provider.php | grep -A 20 "test_connection"Repository: Multisite-Ultimate/ultimate-multisite Length of output: 690 🏁 Script executed: rg "servers.*domains" inc/integrations/host-providers/class-enhance-host-provider.php -A 2 -B 2Repository: Multisite-Ultimate/ultimate-multisite Length of output: 564 🏁 Script executed: sed -n '1,100p' inc/integrations/host-providers/class-enhance-host-provider.php | head -50Repository: Multisite-Ultimate/ultimate-multisite Length of output: 1179 🏁 Script executed: sed -n '300,423p' inc/integrations/host-providers/class-enhance-host-provider.phpRepository: Multisite-Ultimate/ultimate-multisite Length of output: 3585 🏁 Script executed: git -C . show 0e6b983:inc/integrations/host-providers/class-enhance-host-provider.php | sed -n '240,260p'Repository: Multisite-Ultimate/ultimate-multisite Length of output: 669 🏁 Script executed: git -C . show 1ddcfc1:inc/integrations/host-providers/class-enhance-host-provider.php 2>/dev/null | sed -n '240,260p'Repository: Multisite-Ultimate/ultimate-multisite Length of output: 685 Update inline comment and simplify success condition. The endpoint change from 🤖 Prompt for AI Agents |
||
| ); | ||
|
|
||
| if (isset($response['items']) || isset($response['id'])) { | ||
|
|
@@ -261,7 +259,8 @@ public function test_connection(): void { | |
| ] | ||
| ); | ||
| } else { | ||
| $error = new \WP_Error('connection-failed', __('Failed to connect to Enhance API', 'ultimate-multisite')); | ||
| // Translators: %s the full error message. | ||
| $error = new \WP_Error('connection-failed', sprintf(__('Failed to connect to Enhance API: %s', 'ultimate-multisite'), $response['error'] ?? 'Unknown error')); | ||
| wp_send_json_error($error); | ||
| } | ||
| } | ||
|
|
@@ -270,9 +269,9 @@ public function test_connection(): void { | |
| * Sends a request to the Enhance API with the configured bearer token. | ||
| * | ||
| * @since 2.0.0 | ||
| * @param string $endpoint API endpoint (relative to base URL). | ||
| * @param string $method HTTP method (GET, POST, DELETE, etc.). | ||
| * @param array $data Request body data (for POST/PUT/PATCH). | ||
| * @param string $endpoint API endpoint (relative to base URL). | ||
| * @param string $method HTTP method (GET, POST, DELETE, etc.). | ||
| * @param array|string $data Request body data (for POST/PUT/PATCH). | ||
| * @return array|object | ||
| */ | ||
| public function send_enhance_api_request($endpoint, $method = 'GET', $data = []) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 1278
🌐 Web query:
Enhance Control Panel API documentation adding domain to server💡 Result:
Which control panel (cPanel, Plesk, Cloud provider, or a custom Control Panel) and which doc format do you want (OpenAPI YAML/JSON, Markdown, or HTML)? Also confirm the required fields for the domain (e.g., domain name, server_id, DNS zone, SSL cert, aliases) and auth method (API key, OAuth, etc.).
Meanwhile — a concise OpenAPI-style endpoint template and minimal doc checklist you can drop into docs:
OpenAPI endpoint template (YAML — adapt names/types to your schema)
paths:
/servers/{server_id}/domains:
post:
summary: Add a domain to a server
tags: [Domains]
security:
- ApiKeyAuth: []
parameters:
- name: server_id
in: path
required: true
schema:
type: string
description: Server identifier
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [domain]
properties:
domain:
type: string
format: hostname
example: example.com
zone_template:
type: string
description: Optional DNS zone/template name
enable_ssl:
type: boolean
default: true
aliases:
type: array
items:
type: string
examples:
addDomain:
value: { "domain": "example.com", "enable_ssl": true }
responses:
'201':
description: Domain added
content:
application/json:
schema:
$ref: '#/components/schemas/Domain'
'400':
description: Invalid request (validation error)
'401':
description: Unauthorized
'404':
description: Server not found
'409':
description: Domain already exists on server
components:
securitySchemes:
ApiKeyAuth:
type: apiKey
in: header
name: X-API-Key
schemas:
Domain:
type: object
properties:
id:
type: string
domain:
type: string
server_id:
type: string
dns_status:
type: string
ssl_status:
type: string
created_at:
type: string
format: date-time
Minimal documentation checklist (recommended)
If you confirm control panel and desired format, I’ll produce a finalized OpenAPI YAML or Markdown doc section (including curl and SDK examples) tailored to your API, plus sample error payloads and a small CI lint workflow.
Sources: OpenAPI best practices and API design guidance used above. [1] OpenAPI Best Practices. [2] API Design / REST best-practices. [3] Internal doc-generation & examples. (learn.openapis.org)
Citations:
🏁 Script executed:
grep -n "function send_enhance_api_request" inc/integrations/host-providers/class-enhance-host-provider.phpRepository: Multisite-Ultimate/ultimate-multisite
Length of output: 168
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 390
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 63
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 1768
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 1516
🏁 Script executed:
# Check git log for recent changes to understand what was changed git log --oneline -20 -- inc/integrations/host-providers/class-enhance-host-provider.phpRepository: Multisite-Ultimate/ultimate-multisite
Length of output: 113
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 122
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 167
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 63
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 63
🏁 Script executed:
# Check if there's a git show for the specific commit to see what changed git show --stat 0e6b983Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 50393
🏁 Script executed:
cat .wiki/Enhance-Integration.md | head -100Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 3860
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 2641
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 178
🏁 Script executed:
Repository: Multisite-Ultimate/ultimate-multisite
Length of output: 167
Fix the API request payload format — domain must be wrapped in an object.
The Enhance API documentation specifies the POST body should be
{"domain": "example.com"}, but the current code passes$domainas a plain string, which JSON-encodes to just"example.com". This will cause the API call to fail. Wrap the domain in an object:['domain' => $domain]before passing tosend_enhance_api_request().The response field
domainidappears correct based on the integration patterns, though the API documentation does not explicitly document the POST response schema.🤖 Prompt for AI Agents