Update customer with OTRS rpc.pl

English! place to talk about development, programming and coding
Post Reply
Lubomirsb
Znuny newbie
Posts: 83
Joined: 15 Nov 2013, 15:19
Znuny Version: 4.0.13
Real Name: Lubomir
Company: Expert-M

Update customer with OTRS rpc.pl

Post by Lubomirsb »

I can create customers but when trying to update it returns null and nothing happens. This is the php script.

Code: Select all

            
            $Customer = $oClient->__soapCall("Dispatch", array($aConfig["rpcusername"], $aConfig["rpcpassword"], "CustomerUserObject", 	   "CustomerUserUpdate",
                "Source"         , "CustomerUser", # CustomerUser source config
                "ID", $oCustomer->getID(),
                "UserLogin" , $oCustomer->getUserLogin(),
                "UserFirstname" , $oCustomer->getUserFirstname(),
                "UserLastname"  , $oCustomer->getUserLastname(),
                "UserPassword" , $oCustomer->getUserPassword(), # not required
                "UserEmail" , $oCustomer->getUserEmail(),
                "ValidID" , $oCustomer->getValidID(),
                "UserID" , $aConfig["userid"],

            ));
            
I also edited the file in Kernel -> System -> CustomerUser.pm -> Method CustomerUserUpdate so I can return something instead of Null , like message.

Code: Select all

sub CustomerUserUpdate {
    my ( $Self, %Param ) = @_;

    # check needed stuff
    if ( !$Param{UserLogin} ) {
        $Self->{LogObject}->Log( Priority => 'error', Message => "Need UserLogin!" );
        return "Need UserLogin!";  // RETURN SOMETHING
    }

    # check for UserLogin-renaming and if new UserLogin already exists...
    if ( $Param{ID} && ( lc $Param{UserLogin} ne lc $Param{ID} ) ) {
        my %User = $Self->CustomerUserDataGet( User => $Param{UserLogin} );
        if (%User) {
            $Self->{LogObject}->Log(
                Priority => 'error',
                Message  => "User already exists '$Param{UserLogin}'!",
            );
            return "User already exists '$Param{UserLogin}'!";  // RETURN SOMETHING
        }
    }

    # check if user exists
    my %User = $Self->CustomerUserDataGet( User => $Param{ID} || $Param{UserLogin} );
    if ( !%User ) {
        $Self->{LogObject}->Log(
            Priority => 'error',
            Message  => "No such user '$Param{UserLogin}'!",
        );
        return "No such user '$Param{UserLogin}'!"; // RETURN SOMETHING
    }
    my $Result = $Self->{ $User{Source} }->CustomerUserUpdate(%Param);
    return if !$Result;

    # trigger event
    $Self->EventHandler(
        Event => 'CustomerUserUpdate',
        Data  => {
            UserLogin => $Param{ID} || $Param{UserLogin},
            NewData   => \%Param,
            OldData   => \%User,
        },
        UserID => $Param{UserID},
    );

    return $Result;

}
So what i am doing wrong ? The data I am sending is fine. I dont know what this is :

Code: Select all

 "Source"         , "CustomerUser", # CustomerUser source config
A little help please :)
OTRS 3.3.4 ,Centos 6.5
Lubomirsb
Znuny newbie
Posts: 83
Joined: 15 Nov 2013, 15:19
Znuny Version: 4.0.13
Real Name: Lubomir
Company: Expert-M

Re: Update customer with OTRS rpc.pl

Post by Lubomirsb »

I found the issue. It seems like I need to set CustomerUserID. The API does not mention that.

Code: Select all

  $CustomerUserObject->CustomerUserUpdate(
        Source        => 'CustomerUser', # CustomerUser source config
        ID            => 'mh'            # current user login
        UserLogin     => 'mhuber',       # new user login
        UserFirstname => 'Huber',
        UserLastname  => 'Manfred',
        UserPassword  => 'some-pass',    # not required
        UserEmail     => 'email@example.com',
        ValidID       => 1,
        UserID        => 123,
    );
OTRS 3.3.4 ,Centos 6.5
Post Reply