You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于OTRS配置的CMDB类结构,如何用curl通过REST API创建配置项

Alright, let's break down exactly how to create a ConfigItem for your custom CMDB class using curl and OTRS's REST API. Here's a step-by-step guide tailored to your class structure:

Prerequisites First
  • Make sure your OTRS instance has the Generic Interface REST Webservice enabled (the pre-configured GenericTicketConnectorREST usually includes ConfigItem operations, but double-check it's active).
  • You'll need an OTRS user account with permissions to create ConfigItems and access the REST API.
  • Grab your CMDB class's ClassID (we'll cover how to fetch this if you don't know it yet).
Step 1: Get Your CMDB Class ID

If you don't know the ID of the CMDB class you configured, run this curl command to list all available classes:

curl -u "your-otrs-username:your-otrs-password" \
  "https://your-otrs-domain/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/ConfigItem/Class"

Look for the class matching your fields (Field1, Field2, etc.) and note its ClassID value (typically a numeric ID like 5 or 12).

Step 2: Construct the curl Command

Below is the full curl command to create your ConfigItem, built to match your class's structure. Replace all placeholder values with your actual data:

curl -X POST \
  "https://your-otrs-domain/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/ConfigItem" \
  -H "Content-Type: application/json" \
  -u "your-otrs-username:your-otrs-password" \
  -d '{
    "ConfigItem": {
      "ClassID": "123",  # Replace with your CMDB class ID
      "Version": {
        "Name": "Sample CI Name",  # OTRS usually expects a top-level name; adjust if your class uses Field1 as the primary name
        "Attribute": [
          {
            "Key": "Field1",
            "Value": "Your Field1 Required Value"  # Mandatory per your class config
          },
          {
            "Key": "Field2",
            "Value": "Your Field2 Required Value",  # Mandatory per your class config
            "Sub": [
              {
                "Key": "Field2-1",
                "Value": "Your Field2-1 Value"
              }
            ]
          }
        ]
      }
    }
  }'
Key Tips to Avoid Mistakes
  • Authentication: If your OTRS uses API tokens instead of password auth, replace the password with your token (format: username:api-token).
  • Required Fields: Since Field1 and Field2 are marked as Required => 1, omitting either will trigger a 400 error—don't skip these.
  • Self-Signed Certificates: If your OTRS uses a self-signed SSL cert, add the -k flag to the curl command (avoid this in production; better to add the cert to your trusted store).
  • JSON Validity: Use a tool like jq to validate your payload if you run into syntax errors.
Troubleshooting Common Errors
  • 401 Unauthorized: Double-check your username/password/token is correct, and the user has API access permissions.
  • 403 Forbidden: The user lacks permission to create ConfigItems for this specific class.
  • 400 Bad Request: Invalid JSON, missing required fields, or an incorrect ClassID are the most likely culprits.
  • 500 Internal Server Error: This usually points to a misconfiguration in your CMDB class or REST webservice—check OTRS logs for detailed debugging info.

内容的提问来源于stack exchange,提问作者Zumo de Vidrio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:21:57