jasonnitta
9 years agoGuide
Custom Endpoint: Update user settings/profile data
Hello! I'm new to the Freemarker language and somewhat new to Lithium. I'm trying to create a custom endpoint that takes parameters from a call from a Java service and uses them to update a user's profile. So far I have tried to update the email address with no luck. I'm getting a 500 error when calling this endpoint. Here's what I have so far:
<#include "common-vars.ftl"/> <#attempt> <#assign username = http.request.parameters.name.get("username")/> <#recover><#assign username = ""/> </#attempt> <#attempt> <#assign firstName = http.request.parameters.name.get("firstName")/> <#recover><#assign firstName = ""/> </#attempt> <#attempt> <#assign lastName = http.request.parameters.name.get("lastName")/> <#recover><#assign lastName = ""/> </#attempt> <#attempt> <#assign email = http.request.parameters.name.get("email")/> <#recover><#assign email = ""/> </#attempt> <#attempt> <#assign aboutMe = http.request.parameters.name.get("aboutMe")/> <#recover><#assign aboutMe = ""/> </#attempt> <#attempt> <#assign avatar = http.request.parameters.name.get("avatar")/> <#recover><#assign avatar = ""/> </#attempt> <#attempt> <#assign userIdQry = "SELECT id from users where login = '${username}'"/> <#assign userId = executeLiQLQuery(userIdQry)/> <#recover><#assign userId = ""/> </#attempt> <#function updateEmail username email> <#return (rest("/restapi/vc/users/login/" + username + "/email/set/" + email))/> </#function> <#attempt> ${restadmin("/restapi/vc/users/login/" + ${username} + "/email/set/" + ${email}} <#recover>There was an error updating email. </#attempt>
As you can see from the code, there are a few other fields that we would like to update via this endpoint. Thank you for your help!
EDIT: If there is a way to use API v2 to update multiple fields with one call, that would be extremely helpful!