Forum Discussion

jeffshurtliff's avatar
4 years ago

Cannot successfully archive message via API v2

Has anyone been able to successfully archive a message using the Community API v2 POST call documented in the Developer Docs?  I've tried several ways and can't seem to get it to work.  For example:

Using the restadmin directive

 

<#assign response = restadmin("2.0", "/archives/archive", "POST", {"messageId": "32815"}) />
Status: ${response.status}<br />
Message: ${response.message}<br />
Data Keys:<br />
<#list response.data?keys as dataKey>
  - ${dataKey}<br />
</#list>

 

 

Using the restBuilder directive

 

<#assign archivePostCall = restBuilder()
  .method("POST")
  .path("/archives/archive")
  .body({"messageId": "32815"})
  .admin(true) />
<#assign response = archivePostCall.call() />
Status: ${response.status}<br />
Message: ${response.message}<br />
Data Keys:<br />
<#list response.data?keys as dataKey>
  - ${dataKey}<br />
</#list>

 

 

Both attempts above returned the following response:

 

Status: error
Message: Error generating JSON response.
Data Keys:
- getClass
- validTemplateModelObject
- toSerializedString
- isValidTemplateModelObject
- hashCode
- equals
- get
- toString
- class

 

 

I tried performing the same operation via Python (as shown below) but the response is either a 400 or 500 error depending on whether or not I explicitly define the "content-type" header as "application/json" in my request.

Attempt #1:

 

Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 00:42:30) [MSC v.1916 64 bit (AMD64)] on win32
>>> from khoros import Khoros
>>> khoros = Khoros()
>>> response = khoros.post('/api/2.0/archives/archive', {'messageId': '32815'}, return_json=False)
>>> response
<Response [400]>
>>> response.text
'{"status":"error","message":"A possible invalid request has been made.  Make sure you are following the API spec and have used the correct URL, are included all required parameters and if a request payload is required you have included one.","data":{"type":"error_data","code":309,"developer_message":"","more_info":""},"metadata":{}}'
>>> response.request.url
'https://REDACTED.com/api/2.0/archives/archive'
>>> response.request.body
'{"messageId": "32815"}'
>>> response.request.headers
{'User-Agent': 'python-requests/2.23.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'li-api-session-key': 'REDACTED', 'Content-Length': '22'}

 

 

Attempt #2:

 

>>> response = khoros.post('/api/2.0/archives/archive', {'messageId': '32815'}, headers={'content-type': 'application/json'}, return_json=False)
>>> response
<Response [500]>
>>> response.text
'{"status":"error","message":"An unexpected error occurred.","data":{"type":"error_data","code":301,"developer_message":"Can not deserialize instance of java.util.ArrayList out of START_OBJECT token\\n at [Source: org.apache.catalina.connector.CoyoteInputStream@34f637da; line: 1, column: 1]","more_info":""},"metadata":{}}'
>>> response.request.headers
{'User-Agent': 'python-requests/2.23.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'li-api-session-key': 'REDACTED', 'content-type': 'application/json', 'Content-Length': '22'}

 

 

I was hoping I could do a network trace of the archival process in the web UI to see what the syntax should be, but it looks like a different UI-specific endpoint and form is used to perform the operation so I couldn't learn anything from it.

Any help with this would be greatly appreciated.

Thanks!

7 Replies

  • you might need to try with the type message parameter so body changes to body({"messageId":"32815","type":"message"}).

  • SuzieH's avatar
    SuzieH
    Khoros Alumni (Retired)
    4 years ago

    HI jeffshurtliff This definitely worked for me when I tested the calls originally. I'll see if I can get some devs or a PM to comment here.

  • SuzieH's avatar
    SuzieH
    Khoros Alumni (Retired)
    4 years ago

    jeffshurtliff I haven't heard anything, but I had thought there was an active ticket already looking on this. AshishKe can you give an update on on the issues with archiving a message via the API? 

  • NarendraG's avatar
    NarendraG
    Khoros Alumni (Retired)
    4 years ago

    jeffshurtliff The issue is in the request made.

    Body should be a json array, for example - 

    [{
    "messageId" : "174"
    }]

    and an optional "suggestedUrl" can be passed like -

    [{
    "messageId" : "271",
    "suggestedUrl" : "https://test.com"
    }]

    Although it is a JSON array, it can only take one element for now, it was designed keeping the future bulk archive in the mind. For now only one thread id can be sent for archiving in one POST request.

  • jeffshurtliff's avatar
    jeffshurtliff
    Boss
    4 years ago

    Hi NarendraG,

    Thanks for the suggestion. Unfortunately it looks like I couldn't get that to work either.  I tried passing both a JSON array and a string but both returned the response "An unexpected error occurred." as the message.

    Here is the syntax from my attempts:

    <#-- Attempt 1 -->
    <#assign archivePostCall = restBuilder()
      .method("POST")
      .path("/archives/archive")
      .body([{"messageId": "30042"}])
      .admin(true) />
    <#assign response = archivePostCall.call() />
    Status: ${response.status}<br />
    Message: ${response.message}<br />
    
    <#-- Attempt 2 -->
    <#assign archivePostCall = restBuilder()
      .method("POST")
      .path("/archives/archive")
      .body('[{"messageId": "30042"}]')
      .admin(true) />
    <#assign response = archivePostCall.call() />
    Status: ${response.status}<br />
    Message: ${response.message}<br />

    Below are screenshots of the attempts in Studio: