TicketCreate with dynamic Field

Moderator: crythias

Post Reply
rogeriosims
Znuny newbie
Posts: 8
Joined: 21 Mar 2017, 22:07
Znuny Version: OTRS 5
Real Name: Rogerio

TicketCreate with dynamic Field

Post by rogeriosims »

TicketCreate with dynamic Field

I need to create a call and populate a dynamic field, I'm trying with the code below, the call is created, but the dynamic field is still empty.

I already tried value as string and I did not succeed.

I am using OTRS 5.0.16

Code: Select all



$TicketID = $soap->__soapCall(
        "Dispatch", array(
            $username, $password,
            "TicketObject", "TicketCreate",
            "Title", $Title, //Opcional @texto
            "TypeID", $TypeID, //Requerido @inteiro
            "QueueID", $QueueID, //Requerido @inteiro
            "LockID", $LockID, //Requerido @inteiro
            "PriorityID", $PriorityID, //Requerido @inteiro
            "State", $State, //Requerido @texto
            "CustomerUser", $CustomerUser, //Requerido @texto (nome de cliente)
            "CustomerID", $CustomerID, //Requerido @texto (email do cliente)
            "OwnerID", $OwnerID, //Requerido @inteiro
            "ResponsibleID", $OwnerID,
            "UserID", $UserID, //Requerido @inteiro (id do usuário root)
            "ServiceID", $ServiceID,
            "SLAID", $SLAID,
            "DynamicField" => array(
                "Name"   => "Departamento",
                "Value"  => 10,
            )
        )
    );
    
    



Can someone help me?
root
Administrator
Posts: 3960
Joined: 18 Dec 2007, 12:23
Znuny Version: Znuny and Znuny LTS
Real Name: Roy Kaldung
Company: Znuny
Contact:

Re: TicketCreate with dynamic Field

Post by root »

Is this the XML-RPC interface?
Znuny and Znuny LTS running on CentOS / RHEL / Debian / SLES / MySQL / PostgreSQL / Oracle / OpenLDAP / Active Directory / SSO

Use a test system - always.

Do you need professional services? Check out https://www.znuny.com/

Do you want to contribute or want to know where it goes ?
rogeriosims
Znuny newbie
Posts: 8
Joined: 21 Mar 2017, 22:07
Znuny Version: OTRS 5
Real Name: Rogerio

Re: TicketCreate with dynamic Field

Post by rogeriosims »

Exact.

I am using this code in a php script.

I did not understand how to use webservices.

http://wiki.otterhub.org/index.php?titl ... HP_via_RPC
root
Administrator
Posts: 3960
Joined: 18 Dec 2007, 12:23
Znuny Version: Znuny and Znuny LTS
Real Name: Roy Kaldung
Company: Znuny
Contact:

Re: TicketCreate with dynamic Field

Post by root »

AFAIK this is not possible with the XML-RPC interface and TicketCreate. With XML-RPC you expose the API and there are no parameter for dynamic fields: http://doc.otrs.com/doc/api/otrs/stable ... cketCreate. For dynamic fields you have to implement more API calls.

I strongly recommend using the Generic Interface.
Znuny and Znuny LTS running on CentOS / RHEL / Debian / SLES / MySQL / PostgreSQL / Oracle / OpenLDAP / Active Directory / SSO

Use a test system - always.

Do you need professional services? Check out https://www.znuny.com/

Do you want to contribute or want to know where it goes ?
rogeriosims
Znuny newbie
Posts: 8
Joined: 21 Mar 2017, 22:07
Znuny Version: OTRS 5
Real Name: Rogerio

Re: TicketCreate with dynamic Field

Post by rogeriosims »

Thank you!

Would you have any generic interface examples in php?
root
Administrator
Posts: 3960
Joined: 18 Dec 2007, 12:23
Znuny Version: Znuny and Znuny LTS
Real Name: Roy Kaldung
Company: Znuny
Contact:

Re: TicketCreate with dynamic Field

Post by root »

HI,

I'll add some example to my Github account and post the URL to the repository here.

- Roy
Znuny and Znuny LTS running on CentOS / RHEL / Debian / SLES / MySQL / PostgreSQL / Oracle / OpenLDAP / Active Directory / SSO

Use a test system - always.

Do you need professional services? Check out https://www.znuny.com/

Do you want to contribute or want to know where it goes ?
rogeriosims
Znuny newbie
Posts: 8
Joined: 21 Mar 2017, 22:07
Znuny Version: OTRS 5
Real Name: Rogerio

Re: TicketCreate with dynamic Field

Post by rogeriosims »

Hello Roy, I'm waiting!

Thank you very much!
root
Administrator
Posts: 3960
Joined: 18 Dec 2007, 12:23
Znuny Version: Znuny and Znuny LTS
Real Name: Roy Kaldung
Company: Znuny
Contact:

Re: TicketCreate with dynamic Field

Post by root »

Znuny and Znuny LTS running on CentOS / RHEL / Debian / SLES / MySQL / PostgreSQL / Oracle / OpenLDAP / Active Directory / SSO

Use a test system - always.

Do you need professional services? Check out https://www.znuny.com/

Do you want to contribute or want to know where it goes ?
rogeriosims
Znuny newbie
Posts: 8
Joined: 21 Mar 2017, 22:07
Znuny Version: OTRS 5
Real Name: Rogerio

Re: TicketCreate with dynamic Field

Post by rogeriosims »

Hello Roy,

Thanks for the help, with your help I'm walking.

Some doubts:

I am using an admin user to execute the correct requests?

When trying to execute the sessioncreate with the following code I get an error with strange characters, it seems to be in another encode.

Code: Select all

require_once 'unirest-php-master/src/Unirest.php';
Unirest\Request::defaultHeader("Accept", "application/json");
Unirest\Request::defaultHeader("Content-Type", "application/json");
Unirest\Request::verifyPeer(true);
$BaseURL = 'http://otrsteste.xxx.com.br/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST';
$headers = [];
$body = json_encode(
    [
        "UserLogin" => "rmoura",
        "Password"  => "iaaa@2017",
    ]
);

/**
 * SessionCreate
 *
 * http://doc.otrs.com/doc/api/otrs/stable/Perl/Kernel/GenericInterface/Operation/Session/SessionCreate.pm.html
 */
$response = Unirest\Request::post($BaseURL."/Session", $headers, $body);

var_dump($response);


if (!$response->body->SessionID) {
    print "No SessionID returnd \n";
    exit(1);
}

$SessionID = $response->body->SessionID;
Erro:

Code: Select all

C:\wamp\www\otrs-rest\index.php:24:
object(Unirest\Response)[1]
  public 'code' => int 0
  public 'raw_body' => string '‹������ó		Ð7Ô3T020Pð÷æårÎÏ+IÍ+Ñ
©,HµRH,(ÈÉLN,ÉÌÏÓÏ*ÎϳVHÎH,*N-±

qÓµ@(÷IÍK/É°R0ˆå¥&ƒôX)$çä§òrñrU+§Å<]”¬”ƒœÍ}Â]s\
=Ü=r‚½¼Ó‹],,]L-”jWT‹V™���' (length=157)
  public 'body' => string '‹������ó		Ð7Ô3T020Pð÷æårÎÏ+IÍ+Ñ
©,HµRH,(ÈÉLN,ÉÌÏÓÏ*ÎϳVHÎH,*N-±

qÓµ@(÷IÍK/É°R0ˆå¥&ƒôX)$çä§òrñrU+§Å<]”¬”ƒœÍ}Â]s\
=Ü=r‚½¼Ó‹],,]L-”jWT‹V™���' (length=157)
  public 'headers' => 
    array (size=1)
      0 => string '' (length=0)


( ! ) Notice: Trying to get property of non-object in C:\wamp\www\otrs-rest\index.php on line 27
Call Stack
#	Time	Memory	Function	Location
1	0.0000	135624	{main}( )	...\index.php:0
No SessionID returnd 


I tried to use the other methods as well, but all to no avail.

Sorry for ignorance, but I do not know much about rest, soap and these other methods.
rogeriosims
Znuny newbie
Posts: 8
Joined: 21 Mar 2017, 22:07
Znuny Version: OTRS 5
Real Name: Rogerio

Re: TicketCreate with dynamic Field

Post by rogeriosims »

I was able to create calls using the code below.

Code: Select all

/**
 * TicketCreate
 *
 * http://doc.otrs.com/doc/api/otrs/stable/Perl/Kernel/GenericInterface/Operation/Ticket/TicketCreate.pm.html
 */

$body = json_encode([
        "UserLogin" => "rmoura",
        "Password"  => "iurd@2017",
        'Ticket' => [
            'Title' => 'Example ticket',
            'QueueID' => 2,
            'CustomerUser' => 'info@znuny.com',
            'StateID' => 1,
            'PriorityID' => 3,
            'OwnerID' => 1,
            'TypeID' => 5,
        ],
        'Article' =>[
            'ArticleSend' => 1,
            'ArticleTypeID' => 1,
            'SenderTypeID' => 1,
            'Subject' => 'Example',
            'Body' => 'This is a GenericInterface example.',
            'ContentType' => 'text/plain; charset=utf8',
            'Charset' => 'utf8',
            'MimeType' => 'text/plain',
            'To' => 'info@znuny.com',
        ]
    ]
);

$response = Unirest\Request::post($BaseURL."/Ticket", $headers, $body);

echo "<br><br> var_dump body";
var_dump($response->body);


However the feedback I receive is still in this illegible format.

Code: Select all

var_dump body

C:\wamp\www\otrs-rest\index.php:70:string '‹������E˱‚0@ѝ„h:‹¼"Rã`4F£Q‡úؼH[ÏÁÿ]dÐõäÞµÖÇXŒK�ØaïEúÙ beÓÔ֔d½‹¯wSfª²íf'½ŠŠ¾Cw¡J±<Ì¡ù>Š™Úwaðâ󖬩q³äŠOd‚¸¶æ†´ÜÏØöœ€È!iž€,䯦ÞSÉߒdg³���' (length=257)

In the other debug it informs that it sent the json correctly.

Code: Select all

Outgoing data after mapping (2017-06-14 10:27:57, debug)

$VAR1 = {
  'ArticleID' => '35592',
  'TicketID' => '14736',
  'TicketNumber' => '2017061476000496'
};

Returning provider data to remote system (HTTP Code: 200) (2017-06-14 10:27:57, debug)

{"ArticleID":"35592","TicketNumber":"2017061476000496","TicketID":"14736"}
rogeriosims
Znuny newbie
Posts: 8
Joined: 21 Mar 2017, 22:07
Znuny Version: OTRS 5
Real Name: Rogerio

Re: TicketCreate with dynamic Field

Post by rogeriosims »

After much trying I solved the problem.

The unirest library seems to be in trouble.

I was able to make it work using the library:
Http://phphttpclient.com/

Here is sample code:

Code: Select all

<?php
ini_set('default_charset', 'UTF-8');

require_once 'Httpful-master/Bootstrap.php';

// URL do Webservice
$BaseURL = 'http://otrsteste.com.br/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST';

// Cabeçalhos
$headers = [];

// Corpo da Solicitação
$body = json_encode(
    [
        'UserLogin' => 'root@localhost',
        'Password'  => '1qasas',
    ]
);


/*
* Cria a session
*/

// Url base + Parametro do Invoker
$URL = $BaseURL.'/Session';

// Cria a instancia Httpful passando a URL e o Corpo
$response = \Httpful\Request::get($URL)

  ->body($body)

  ->send();

  // Verifica se a solicitação retornou erro
  if(isset($response->body->Error)) {
    // Printa o Codigo de Erro
    echo $response->body->Error->ErrorCode;
    echo '<br>';
    echo $response->body->Error->ErrorMessage;
  }

  if(isset($response->body->SessionID)) {
    echo "<pre>";
    print_r($response->body);
    echo "</pre>";
    $SessionID = $response->body->SessionID;
  }



/*
* Cria um chamado usando a session
*/

$body = json_encode([
        'SessionID' => $SessionID,
        //'UserLogin' => 'root@localhost',
        //'Password'  => '1qasasa,
        'Ticket' => [
            'Title' => 'Example ticket',
            'QueueID' => 2,
            'CustomerUser' => 'info@znuny.com',
            'StateID' => 1,
            'PriorityID' => 3,
            'OwnerID' => 1,
            'TypeID' => 5,
        ],
        'Article' =>[
            'ArticleSend' => 1,
            'ArticleTypeID' => 1,
            'SenderTypeID' => 1,
            'Subject' => 'Example',
            'Body' => 'This is a GenericInterface example.',
            'ContentType' => 'text/plain; charset=utf8',
            'Charset' => 'utf8',
            'MimeType' => 'text/plain',
            'To' => 'info@znuny.com',
        ],
        'DynamicField' =>[
            'Name'   => 'Departamento',
            'Value'  => 'a',
        ]
    ]
);

// Url base + Parametro do Invoker
$URL = $BaseURL.'/Ticket';

// Cria a instancia Httpful passando a URL e o Corpo
$response = \Httpful\Request::get($URL)

  ->body($body)

  ->send();

  // Verifica se a solicitação retornou erro
  if(isset($response->body->Error)) {
    // Printa o Codigo de Erro
    echo $response->body->Error->ErrorCode;
    echo '<br>';
    echo $response->body->Error->ErrorMessage;
  }

    echo "<pre>";
    print_r($response->body);
    echo "</pre>";

Post Reply