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!

  • 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)

    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)

        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?