We’ve developed some resources to help you work effectively from home during COVID-19 Click to learn more

GET /api/v1/TicketMessage/{NN}/Attachme­nt returns 500 error

Hi,

I'm trying to GET /api/v1/TicketMessage/[ticketID]/Attachment, but I get a 500 error. Anyone experienced this or know what's going on?

Here's a curl output snippet:

[...]
* SSL certificate verify ok.
* Server auth using Basic with user REDACTED
> GET /api/v1/TicketMessage/462721/Attachment HTTP/1.1
Host: REDACTED
Authorization: REDACTED
Accept: application/json
Accept-Language: *

< HTTP/1.1 500 Internal Server Error
< Cache-Control: private
< Content-Length: 0
< Server: Microsoft-IIS/8.0
< X-AspNet-Version: 4.0.30319
< X-Powered-By: ASP.NET
< X-Powered-By: ARR/3.0
< X-Powered-By: ASP.NET
< Date: Tue, 23 Jun 2020 10:28:39 GMT
<


Here's the PHP code I use for GETting:

$host = 'https://REDACTED/api/v1/TicketMessage/462721/Attachment';
$ch = curl_init($host);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept: application/json',
'Accept-Language: *'
));
$result = curl_exec($ch);
curl_close($ch);

Other rest api requests seem to be working fine. Anyone?

Andreas

RE: GET /api/v1/TicketMessage/{NN}/Attachme­nt returns 500 error

I believe this is a known bug. Until it is fixed, you must use the RESTful Agent API to work with TicketMessage attachments. 

We apologize for any inconvenience. 

Av: Tony Yates 23. jun 2020

RE: GET /api/v1/TicketMessage/{NN}/Attachme­nt returns 500 error

OK, thank you.

Av: Andreas Sagen 23. jun 2020

RE: GET /api/v1/TicketMessage/{NN}/Attachme­nt returns 500 error

Hi Andreas,

I just want to follow up with one last thing. You didn't mention which version you were using. I see that this issue was fixed in SuperOffice 8.5 R09. So if your installation is that or later, you should be OK.

Best regards.

Av: Tony Yates 23. jun 2020

RE: GET /api/v1/TicketMessage/{NN}/Attachme­nt returns 500 error

Hi again,

my client is on 8.4, so the bug would be present. So I followed your advice and called the Agent api, but i still get a 500 error.

Here is the code:

                $json = json_encode(['TicketMessageEntityId' => 462721]);

                $host = 'https://customerservice.norkart.no/api/v1/Agents/Ticket/GetAttachmentInfo';
                $ch = curl_init($host);

                curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_VERBOSE, true);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
                curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
                curl_setopt($ch, CURLOPT_HTTPHEADER, array(
                        'Accept: application/json',
                        'Content-Type: application/json; charset=utf-8'
                ));

                $result = curl_exec($ch);
                curl_close($ch);
                $attachment = json_decode($result);
                print_r($attachment);

Which outputs:

* upload completely sent off: 32 out of 32 bytes
< HTTP/1.1 500 Internal Server Error
< Cache-Control: private
< Content-Length: 0
< Server: Microsoft-IIS/8.0
< X-AspNet-Version: 4.0.30319
< X-Powered-By: ASP.NET
< X-Powered-By: ARR/3.0
< X-Powered-By: ASP.NET
< Date: Wed, 24 Jun 2020 11:24:51 GMT
Also, I noticed that examples in your docs fail as well. There's a "Send Request" button on this page:

https://community.superoffice.com/documentation/sdk/SO.NetServer.Web.Services/html/v1TicketAgent_GetAttachmentInfo.htm

I assume it's supposed to work, but it gives a "Network Error".

Av: Andreas Sagen 24. jun 2020

RE: GET /api/v1/TicketMessage/{NN}/Attachme­nt returns 500 error

Support for attachments on the TicketMessage class was added in 8.5 R11, so seems like your installation is too old.

Av: Stian Andre Olsen 24. jun 2020

RE: GET /api/v1/TicketMessage/{NN}/Attachme­nt returns 500 error

>Support for attachments on the TicketMessage class was added in 8.5 R11, so seems like your installation is too old.

Hm. Is there any other way of fetching attachments from tickets/ticket messages?

Av: Andreas Sagen 24. jun 2020

RE: GET /api/v1/TicketMessage/{NN}/Attachme­nt returns 500 error

You could make a CRMScript which gets the attachment, and then call upon this using the CRMScriptAgent.

A CRMScript like this, which base64 encodes the attachment:

#setLanguageLevel 3;

Attachment a;
a.load(1714);
print(a.getBase64());

And then you can call upon it like this:
https://mysite123.no/superoffice/api/v1/Agents/CRMScript/ExecuteScriptByIncludeId

The body should contain a json struct:
{"CRMScriptIncludeId":"insert-includeIdOfScript"}

Note that this will return the base64 as a string, so there will be quotes around it.

You could call directly on the script above, using ../customer.fcgi?action=printBin&includeId=insert-includeIdOfScript&key=somethingverysecret


And change the last line in the script to:
a.dump();

Then you will get the attachment with the correct content type headers as well. 
But this is a more insecure method, since if anyone gets hold of that URL, they will be able to dump attachments through it. So additional protection should be used in that case.

Av: Stian Andre Olsen 24. jun 2020