[SOLVED] Add an article using rest

Moderator: crythias

Post Reply
rodolfor
OTRS newbie
Posts: 35
Joined: 11 Jun 2020, 14:56
OTRS 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
Moderator
Posts: 2463
Joined: 18 Dec 2007, 12:23
OTRS Version?: 4/5/6 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 LTS and ((OTRS) Community Edition CentOS / RHEL / Debian / SLES / MySQL / PostgreSQL / Oracle / OpenLDAP / Active Directory / SSO

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

Do you want to contribute or want to know why ?

rodolfor
OTRS newbie
Posts: 35
Joined: 11 Jun 2020, 14:56
OTRS 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
Moderator
Posts: 2463
Joined: 18 Dec 2007, 12:23
OTRS Version?: 4/5/6 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 LTS and ((OTRS) Community Edition CentOS / RHEL / Debian / SLES / MySQL / PostgreSQL / Oracle / OpenLDAP / Active Directory / SSO

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

Do you want to contribute or want to know why ?

zzz
OTRS superhero
Posts: 677
Joined: 15 Dec 2016, 15:13
OTRS Version?: 3.x–6.0.x
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 & ((OTRS)) Community Edition services: efflux.de | efflux.de/en/

Free and premium OTRS add-ons: German | English

rodolfor
OTRS newbie
Posts: 35
Joined: 11 Jun 2020, 14:56
OTRS 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
OTRS newbie
Posts: 35
Joined: 11 Jun 2020, 14:56
OTRS 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