Forum Discussion
Hi phoneboy
The only difference I can see between your example and the documentation is that the docs show the body parameters wrapped in data object. Maybe try this format?
{
"data" : {
"type": "membership_request",
"approve_request": true,
"user_id": uid
}
}
You might also try the restBuilder FreeMarker method.
Let me know if one of those options don't work and I'll keep digging.
- phoneboy5 years agoDirector
Tried that format, same result.
The error returned, if it's helpful:{ "status":"error", "message":"Membership Request not found.", "data": { "type":"error_data", "code":505, "developer_message":"", "more_info":"" }, "metadata":{} }
Making the same call using restBuilder:
<#assign approve = restBuilder() .method("PUT") .path("/nodes/grouphub:" + node + "/membership_requests") .body({ "data" : { "type": "membership_request", "approve_request": "true", "user_id": uid } }) .admin(true) /> <#assign resp = approve.call() />
I get the dreaded Freemarker error dump with this being the only potentially meaningful error:
Caused by: freemarker.template.TemplateModelException: unexpected exception during rest call: FreemarkerRestCall{version='2.0', restCall=RestCall{path=[nodes, grouphub:myCommunity, membership_requests], action=PUT}, adminCall=true, impersonationParameterSource=null}
On my page quilt, it says "Widget cannot be displayed."
- phoneboy5 years agoDirector
Well, I figured out what the issue was.
On a lark, I tried a raw API call with curl, which actually worked:phoneboy-cli:~ $ curl -u mystageuser:mystagepass -X PUT https://mystageurl/api/2.0/nodes/grouphub:myGroupHub/membership_requests -H 'Content-Type: application/json' -H 'li-api-session-key: mysessiontoken' -d '{ "data": { "type": "membership_request", "approve_request": true, "user_id": 226 } } '
That helped me figure out uid was being interpreted as a string versus a number, which is what the API expects.
Somehow, I thought putting ?c would resolve this, but instead I need to replace that with ?number.Note this still doesn't solve the issue with restBuilder, which crashes even with the above change.
That said, I at least have a working solution now.I really wish the Community API gave more meaningful error messages.
Most of the ones I've encountered have been...terribly unhelpful.