我正在尝试使用我的React应用程序中的axios通过WHMCS Api(最新版本)创建票证。当我打电话时,有两个来自客户端的呼叫:一个是OPTIONS(CORS),第二个是实际POST,带有all the the necessary fields,但是,我收到两个错误:
1。请求一个:
Request URL: https://my-domain/includes/api.php?accesskey=<KEY>q&identifier=<ID>&secret<SECRET>&action=OpenTicket
Request Method: OPTIONS
Status Code: 200 OK
Remote Address: 62.*.*.*:443
响应:
result=error;message=An admin user is required
2。请求2:
Request URL: https://my-domain/includes/api.php?accesskey=<KEY>q&identifier=<ID>&secret<SECRET>&action=OpenTicket
Request Method: POST
Status Code: 200 OK
Remote Address: 62.*.*.*:443
有效负载:
{
admin: true
deptid: "1"
email: "[email protected]"
markdown: true
message: "test"
name: "text"
priority: "Medium"
responsetype: "json"
subject: "test"
}
Response:
result=error;message=Name and email address are required if not a client
JS代码:
...
const ticketObject = {
admin: true
deptid: "1"
email: "[email protected]"
markdown: true
message: "test"
name: "text"
priority: "Medium"
responsetype: "json"
subject: "test"
};
const res = await axios.post(
"https://my-domain/includes/api.php?accesskey=<KEY>q&identifier=<ID>&secret<SECRET>&action=OpenTicket",
ticketObject
);
...
服务器详细信息:
Nginx conf:
server {
server_name my-domain www.my-domain;
error_log /var/log/httpd/domains/my-domain.error.log error;
location / {
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|html|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls|xlsx|ppt|pptx|odf|odp|ods|odt|pdf|psd|ai|eot|eps|ps|zip|tar|tgz|gz|rar|bz2|7z|aac|m4a|mp3|mp4|ogg|wav|wma|3gp|avi|flv|m4v|mkv|mov|mpeg|mpg|wmv|exe|iso|dmg|swf)$ {
root /home/admin/web/my-domain/public_html;
access_log /var/log/httpd/domains/my-domain.log combined;
access_log /var/log/httpd/domains/my-domain.bytes bytes;
expires max;
try_files $uri @fallback;
}
# Check if the origin of th request
set $cors '';
if ($http_origin ~* (https?://.*\.proudtech\.ro?(:[0-9]+)?$)) {
set $cors 'on';
}
if ($request_method = OPTIONS) {
set $cors "${cors}_options";
}
# Allow CORS on preflight request
if ($cors = 'on_options') {
add_header 'Content-Length' 0;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept';
return 204;
}
# Proxy pass to upstream
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
# Allow CORS on other requests after returning from the upstreams
if ($cors = 'on') {
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
add_header 'Access-Control-Allow-Headers' 'Origin, X-Requested-With, Content-Type, Accept';
}
proxy_pass http://62.*.*.*:8080;
}
location /error/ {
alias /home/admin/web/my-domain/document_errors/;
}
location @fallback {
proxy_pass http://62.*.*.*:8080;
}
include /home/admin/conf/web/nginx.my-domain.conf*;
}
server {
if ($host = my-domain) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 62.*.*.*:80;
server_name my-domain www.my-domain;
return 404; # managed by Certbot
}
VirtualHost conf:
ServerName my-domain
ServerAlias www.my-domain
ServerAdmin info@my-domain
DocumentRoot /home/admin/web/my-domain/public_html
ScriptAlias /cgi-bin/ /home/admin/web/my-domain/cgi-bin/
Alias /vstats/ /home/admin/web/my-domain/stats/
Alias /error/ /home/admin/web/my-domain/document_errors/
#SuexecUserGroup admin admin
CustomLog /var/log/httpd/domains/my-domain.bytes bytes
CustomLog /var/log/httpd/domains/my-domain.log combined
Header always set Access-Control-Allow-Origin "*"
Header always set Access-Control-Max-Age "1000"
Header always set Access-Control-Allow-Headers "X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
ErrorLog /var/log/httpd/domains/my-domain.error.log
<Directory /home/admin/web/my-domain/public_html>
AllowOverride All
Options +Includes -Indexes +ExecCGI
php_admin_value open_basedir /home/admin/web/my-domain/public_html:/home/admin/tmp
php_admin_value upload_tmp_dir /home/admin/tmp
php_admin_value session.save_path /home/admin/tmp
</Directory>
<Directory /home/admin/web/my-domain/stats>
AllowOverride All
</Directory>
<IfModule mod_ruid2.c>
RMode config
RUidGid admin admin
RGroups apache
</IfModule>
<IfModule itk.c>
AssignUserID admin admin
</IfModule>
IncludeOptional /home/admin/conf/web/httpd.my-domain.conf*
请参阅有关OpenTicket API函数的本文档:https://developers.whmcs.com/api-reference/openticket/
您不应该同时使用admin
和email
。仅当创建票证的客户端不存在时,才应输入电子邮件。您也不应该使用name
。