osTicket API:在 python 中创建新票证
osTicket API: create a new ticket in python
我正在尝试使用 python
创建新票证,但我无法让 osticket
接受我的 API 密钥。
这是我的代码:
def post_ticket(json):
headers = {'API-Key': 'mykey'}
response = requests.post("http://mydomani.com/api/tickets.json", data=create_json_ticket(json), headers=headers)
for r in response:
print(r)
我遇到错误 'Valid API key required'
。
如果我使用作为示例给出的 PHP
脚本(使用相同的 url、密钥和 JSON 数据)它工作正常。
header 键应该是 "X-API-Key"
而不是 "API-Key"
。
来自 osTicket API
页:
HTTP Access
Access to the HTTP API is restricted to valid API keys. An X-API-Key
HTTP header must be sent to indicate which API key is to be used with
the request.
The API key must match the remote IP of the connected
HTTP client. The remote IP is checked as usual. If the osTicket server
is sitting behind a reverse proxy, the original IP of the client will
be retrieved from the X-Forwarded-For header, if provided by your
proxy.
Example:
X-API-Key: BA00B76BAA30F62E1940B46CC1C3C73C
Command line Example with Curl:
curl -d "{}" -H "X-API-Key: BA00B76BAA30F62E1940B46CC1C3C73C" https://support.you.tld/api/tickets.json
我正在尝试使用 python
创建新票证,但我无法让 osticket
接受我的 API 密钥。
这是我的代码:
def post_ticket(json):
headers = {'API-Key': 'mykey'}
response = requests.post("http://mydomani.com/api/tickets.json", data=create_json_ticket(json), headers=headers)
for r in response:
print(r)
我遇到错误 'Valid API key required'
。
如果我使用作为示例给出的 PHP
脚本(使用相同的 url、密钥和 JSON 数据)它工作正常。
header 键应该是 "X-API-Key"
而不是 "API-Key"
。
来自 osTicket API
页:
HTTP Access
Access to the HTTP API is restricted to valid API keys. An X-API-Key HTTP header must be sent to indicate which API key is to be used with the request.
The API key must match the remote IP of the connected HTTP client. The remote IP is checked as usual. If the osTicket server is sitting behind a reverse proxy, the original IP of the client will be retrieved from the X-Forwarded-For header, if provided by your proxy.Example:
X-API-Key: BA00B76BAA30F62E1940B46CC1C3C73C
Command line Example with Curl:
curl -d "{}" -H "X-API-Key: BA00B76BAA30F62E1940B46CC1C3C73C" https://support.you.tld/api/tickets.json