O7 Webservice Provider DynamicField Update via PowerShell

Moderator: crythias

Post Reply
Klicker
Znuny newbie
Posts: 8
Joined: 20 Oct 2020, 16:06
Znuny Version: 7.21
Real Name: Tim Otto

O7 Webservice Provider DynamicField Update via PowerShell

Post by Klicker »

Hello,
can someone tell me the right syntax for updating dynamic fields via the powershell.
This code works for me but there is no error message or updated dynamic filed.

Code: Select all


$uri = "https://mySite/otrs/nph-genericinterface.pl/Webservice/TestOne/TicketUpdate/1234?"

$user = 'Username'
$pass = 'Password'

$pair = "$($user):$($pass)"

$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair))

$basicAuthValue = "Basic $encodedCreds"


$headers = @{
    Authorization = $basicAuthValue
}

$TicketData = @{
        UserLogin = "test"
        Password = "testuser"
        
        Ticket = @{
                Title = 'TicketCreate via REST '
                QueueID = 5
                State = 'new'
                Priority = '3 normal'
                CustomerUser = 'E-Mail@Adresse'
                Type = 'Unclassified'
               DynamicField = {Name = "Hostname", Value = "1234567"}
        }
        Article = @{
                Subject = 'New Hostname Added'
                Body    = 'Hostname 1234567'
                ContentType = 'text/plain; charset=utf8'
                MimeType = 'text/plain'
                Charset = 'utf8'
        }
}

$json = $TicketData | ConvertTo-Json

Write-Host $headers
$Result = Invoke-RestMethod  -Method Post -Headers $headers -ContentType 'application/json' -Uri $uri -Body $json 

Write-Host Created ticket $Result.TicketNumber
alexus
Znuny wizard
Posts: 380
Joined: 20 Sep 2010, 16:54
Znuny Version: OTRS 6 CE
Real Name: Alexey Yusov
Company: Radiant System Group s.r.o
Location: Prague
Contact:

Re: O7 Webservice Provider DynamicField Update via PowerShell

Post by alexus »

Hello,

You should provide TicketID inside TicketData

Code: Select all

curl -X POST https://demo/otrs/nph-genericinterface.pl/Webservice/RemoteControl/TicketUpdate -d  '{
    "UserLogin": "agent",
    "Password": "blablabla",
    "TicketID" : "1464",
    "Ticket": {
        "StateID" : 15,
         "PendingTime" : {
             "Diff" : 10080 
              }
    },                
    "Article": {
        "ArticleType"  : "email-notification-ext",
        "Subject": "Уточнение запроса у клиента 001",
        "Body": "Тут тело сообщения",
        "ContentType": "text/plain; charset=utf8"
    }, 
        "Attachment": [{
        "Filename": "asdf.txt",
        "Content": "YXNkZgo=",
        "ContentType": "text/plain; charset=utf8"
    }]
}'
Alexey Yusov

Production: OTRS CE ITSM 6.0.28 on CentOS 7 + Apache 2.4 + MariaDB 10.4.13 + Radiant Customer Portal

Radiant System OTRS Intergrator
RS4OTRS marketplace
Stay tuned on our Facebook
((OTRS)) Community Edition - what next?
Klicker
Znuny newbie
Posts: 8
Joined: 20 Oct 2020, 16:06
Znuny Version: 7.21
Real Name: Tim Otto

Re: O7 Webservice Provider DynamicField Update via PowerShell

Post by Klicker »

It is not necessary to do that but better practice. My script is still working fine to add a new article to my Ticket but the Dynamic Field is not changing his value. On the other hand, the status can easily be changed from open to new.
If you want to try this script you only have to change $uri, $user and $pass.
skullz
Znuny superhero
Posts: 618
Joined: 24 Feb 2012, 03:58
Znuny Version: LTS and Features
Real Name: Mo Azfar
Location: Kuala Lumpur, MY
Contact:

Re: O7 Webservice Provider DynamicField Update via PowerShell

Post by skullz »

not sure with power shell, but with perl, dynamic field is outside Ticket..

try

Code: Select all

my $Params = {
    UserLogin => $User,       
    Password  => $Pass,  
    Ticket    => {
	Queue        => "Postmaster",
    },
    DynamicField => [
	{
		Name     => "Category",
		Value        => "A",
	},
	{
		Name     => "SubCategory",
		Value        => "AA",
	},
],
};
root
Administrator
Posts: 3934
Joined: 18 Dec 2007, 12:23
Znuny Version: Znuny and Znuny LTS
Real Name: Roy Kaldung
Company: Znuny
Contact:

Re: O7 Webservice Provider DynamicField Update via PowerShell

Post by root »

Hi,

In Powershell it's

$DynamicField = @(
{
Name => "Category",
Value => "A"
},
{
Name => "SubCategory",
Value => "AA"
}
)

- 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 ?
Klicker
Znuny newbie
Posts: 8
Joined: 20 Oct 2020, 16:06
Znuny Version: 7.21
Real Name: Tim Otto

Re: O7 Webservice Provider DynamicField Update via PowerShell

Post by Klicker »

The dynamic field outside the ticket works for me. Thank you guys.
Post Reply