[SOLVED] Add an article using rest

Moderator: crythias

Post Reply
rodolfor
Znuny newbie
Posts: 89
Joined: 11 Jun 2020, 14:56
Znuny Version: 6.0.27
Real Name: Rodolfo Rughi
Company: none

[SOLVED] Add an article using rest

Post by rodolfor »

I cannot find the correct way to add an article to an existing ticket using a rest call.
The ticket itself must remain unchanged but I want only add a note.
How can I do?

Thanks
Last edited by rodolfor on 02 Dec 2020, 15:41, edited 1 time in total.
root
Administrator
Posts: 3960
Joined: 18 Dec 2007, 12:23
Znuny Version: Znuny and Znuny LTS
Real Name: Roy Kaldung
Company: Znuny
Contact:

Re: Add an article using rest

Post by root »

Hi,

What have you tried so far?

- 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 ?
rodolfor
Znuny newbie
Posts: 89
Joined: 11 Jun 2020, 14:56
Znuny Version: 6.0.27
Real Name: Rodolfo Rughi
Company: none

Re: Add an article using rest

Post by rodolfor »

#1

Code: Select all

curl -X "PATCH" "http://<your-domain>/otrs/nph-genericinterface.pl/Webservice/WebServiceAPI001/TicketUpdate/[ticketid]?UserLogin=otrsadmin&Password=password" \
     -H "Content-Type: application/json" \
     -d $'{
  "Ticket": {
    "Article": {
      "Subject": "mysubject",
      "Body": "mybody",
      "ContentType": "text/plain; charset=utf8"
      }
    }
  }
#2 (changing only the ticketID in the url)

Code: Select all

curl -X "PATCH" "http://<your-domain>/otrs/nph-genericinterface.pl/Webservice/WebServiceAPI001/TicketUpdate?UserLogin=otrsadmin&Password=password&&TicketID=123"
Thanks
root
Administrator
Posts: 3960
Joined: 18 Dec 2007, 12:23
Znuny Version: Znuny and Znuny LTS
Real Name: Roy Kaldung
Company: Znuny
Contact:

Re: Add an article using rest

Post by root »

Hi,

You used the wrong structure in the body. Article is not a sub eelement of ticket, see https://github.com/OTRS/otrs/blob/rel-6 ... te.pm#L113 for the proper structure.

- 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 ?
zzz
Znuny superhero
Posts: 889
Joined: 15 Dec 2016, 15:13
Znuny Version: All
Real Name: Emin
Company: Efflux GmbH
Contact:

Re: Add an article using rest

Post by zzz »

And you are also missing some mandatory fields.

— Emin
Professional OTRS, Znuny & OTOBO services: efflux.de | efflux.de/en/

Free and premium add-ons: German | English
rodolfor
Znuny newbie
Posts: 89
Joined: 11 Jun 2020, 14:56
Znuny Version: 6.0.27
Real Name: Rodolfo Rughi
Company: none

Re: Add an article using rest

Post by rodolfor »

Thanks , the link show me a lot of new things!

I tried these url:

Code: Select all

curl -X POST ".../TicketUpdate?UserLogin=usg&Password=pwg&TicketNumber=2020120173000001"
and the error is:
HTTP::REST Error while determine Operation for request URI '/TicketUpdate'[/code]

Then I tried:

Code: Select all

curl -X POST ".../TicketUpdate/2020120173000001?UserLogin=usg&Password=pwg"
and the error is:
HTTP::REST Error while determine Operation for request URI '/TicketUpdate/2020120173000001'

Either with POST and PATCH and to map the method in REST using:
/Ticket/:TicketNumber or /Ticket

With this data:

Code: Select all

-H "Content-Type:application/json" 
-d "{\"Article\": 
           {\"CommunicationChannelID\": \"1\"
           , \"IsVisibleForCustomer\": \"0\"
           , \"SenderType\": \"Portal\"
           , \"From\": \"UserPortal\"
           , \"Subject\": \"UpdatePortal\"
           , \"Body\": \"bodyportal\"
           , \"ContentType\": \"text/plain; charset=utf8\"
           }
     }" 
In webservice log I cannot see other informations.

Thanks if you can see my error.
Last edited by rodolfor on 02 Dec 2020, 11:31, edited 3 times in total.
rodolfor
Znuny newbie
Posts: 89
Joined: 11 Jun 2020, 14:56
Znuny Version: 6.0.27
Real Name: Rodolfo Rughi
Company: none

Re: Add an article using rest

Post by rodolfor »

SOLUTION:

1. read the link https://github.com/OTRS/otrs/blob/rel-6 ... te.pm#L113
to know correct structure and mandatory values

2. you must use Ticket routing, with PATCH

3. the correct curl is

Code: Select all

curl -X PATCH ".../Ticket/2020120173000001?UserLogin=usg&Password=pwg"
-H "Content-Type:application/json" 
-d "{\"Article\": 
           {\"CommunicationChannelID\": \"1\"
           , \"IsVisibleForCustomer\": \"0\"
           , \"SenderType\": \"Portal\"
           , \"From\": \"UserPortal\"
           , \"Subject\": \"UpdatePortal\"
           , \"Body\": \"bodyportal\"
           , \"ContentType\": \"text/plain; charset=utf8\"
           }
     }" 
Be shure to modify the call to this rest api in otrs webservice, and modify from /Ticket/:TicketID to /Ticket/:TicketNumber

Thanks all.

Rodolfo
Post Reply