使用curl命令通过REST API创建项目

时间:2018-04-24 07:16:58

标签: rest curl otrs cmdb

我通过configitem模块在OTRS中配置了以下CMDB类结构:

[
{ 
        Key => 'Field1', 
        Name => 'Name1', 
        Searchable => 1, 
        Input => { 
            Type => 'Text', 
            Size => 50, 
            MaxLength => 50,     Required => 1,
        },     { 
        Key => 'Field2', 
        Name => 'Name2', 
        Searchable => 1, 
        Input => { 
            Type => 'Text', 
            Size => 50, 
            MaxLength => 50,     Required => 1,
        }, 
        Sub=>[    { 
        Key => 'Field2-1', 
        Name => 'Name2-1', 
        Searchable => 1, 
        Input => { 
            Type => 'Text', 
            Size => 50, 
            MaxLength => 50, 
        }, 
    },  { 
        Key => 'Field2-2', 
        Name => 'Name2-2', 
        Searchable => 1, 
        Input => { 
            Type => 'Text', 
            Size => 50, 
            MaxLength => 50, 
        }, 
    },  { 
        Key => 'Field2-3', 
        Name => 'Name2-3', 
        Searchable => 1, 
        Input => { 
            Type => 'Text', 
            Size => 50, 
            MaxLength => 50, 
        }, 
    },  
];

我正在尝试通过REST-API(正确配置)创建一个新的配置项,并使用以下curl:

  

卷曲   " http://url/nph-genericinterface.pl/Webservice/ws/ConfigItem?UserLogin=username&Password=password"   -H" Content-Type:application / json" -d" {\" ConfigItem \":{\" Class \":\" class_name \",   \"名称\":\" ci_name \" \" CIXMLData \":{\"字段1 \":\ " text_value_for_field1 \" \"字段2 \":\" text_value_for_field2 \"}}}"   -X POST

但服务器以500内部服务器错误回答:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator at 
 root@localhost to inform them of the time this error occurred,
 and the actions you performed just before this error.</p>
<p>More information about this error may be available
in the server error log.</p>
</body></html>

如果&#34; Field2&#34;不是必填字段,我执行以下卷曲:

  

卷曲   &#34; http://url/nph-genericinterface.pl/Webservice/ws/ConfigItem?UserLogin=username&Password=password&#34;   -H&#34; Content-Type:application / json&#34; -d&#34; {\&#34; ConfigItem \&#34;:{\&#34; Class \&#34;:\&#34; class_name \&#34;,   \&#34;名称\&#34;:\&#34; ci_name \&#34; \&#34; CIXMLData \&#34;:{\&#34;字段1 \&#34;:\ &#34; text_value_for_field1 \&#34;}}}&#34;   -X POST

该项目已正确创建,但是,如果不需要,我会为Field2分配一些值,然后返回500错误。

由于Field2有一些子字段(即使它们不是必需的字段),我认为我的卷曲中存在一些语法错误。

注意:当我使用相同的数据通过GUI创建CI时,它已正确创建。

0 个答案:

没有答案