Forum Discussion

micha80's avatar
micha80
Expert
10 years ago

Save user setting return error 100

Hi,

 

I want to save the user first_name value using the rest api but when I make the ajax call I got error 100 (Unknown error occured). So I can not save the value. I read the documentation but could not find a solution for this. I am doing the following:

 

Call the rest api the following way:

 

var apiURL = '/restapi/vc/authentication/sessions/current/user/profiles/name/first_name/set?restapi.response_format=json';
$.ajax({
  method: "POST",
  url: apiURL,
  data: { value: val }
})
.done(function(response) {
  apiCallHandleResponse(response.response);
});

 Then I got the following response:

 

{"response":{"status":"error","error":{"code":100,"message":"Ein unerwarteter Fehler ist aufgetreten."}}}

 

I am logged in as a user. I am not doing any authentication cause I am logged in a user already. But when I am doing an AjaxCall I need to authenticate, or am I wrong? Is there any full documentation or an example about saving user settings with ajax?

 

Regards,

Michael

 

 

  • PaoloT good point ;)

     

    In that case, the error 100 might come from the settings name (name_first and not first_name)

     

    micha80 

     

    Instead of 

     

    var apiURL = '/restapi/vc/authentication/sessions/current/user/profiles/name/first_name/set?restapi.response_format=json';

    Use

     

    var apiURL = '/restapi/vc/authentication/sessions/current/user/profiles/name/name_first/set?restapi.response_format=json';

     

    Also, I believe it's worth checking if the following call:

     

    https://<your_community_url>/restapi/vc/users/self/profiles

     return a value for name_first as this example: 

     

    <profile name="name_first" type="string">Olivier</profile>

     

     Which I don't think it does on your community micha80 (I will reach out to you by email)

7 Replies

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)
    10 years ago

    Hi micha80 

     

    can you share the actual REST call generated by that code? (Should be available in Chrome developer tools or equivalent)

    Maybe val is not in the right format?

     

    Thanks,

  • micha80's avatar
    micha80
    Expert
    10 years ago

    HI Paolo,

     

    I added a screen with all header informations.

     

    Thanks for your help!

    Michael


    header.png
  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)
    10 years ago

    Hi micha80 

     

    I cannot see any obvious reason for an error. I suggest to raise this as a support case to get it investigated.

     

    Kind Regards,

  • OlivierS's avatar
    OlivierS
    Lithium Alumni (Retired)
    10 years ago

    micha80 in order to set a value, you need to use the 'value' parameter:

     

    https://<your_community_url>/restapi/vc/users/self/profiles/name/name_first/set?value=oli

    And just in case, please HTML encode your URL. 

     

    We will get our documentation updated as soon as we can.

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)
    10 years ago
    Olivier, I think the parameter is being already passed via jQuery 's data element in the $.ajax call.
  • OlivierS's avatar
    OlivierS
    Lithium Alumni (Retired)
    10 years ago

    PaoloT good point ;)

     

    In that case, the error 100 might come from the settings name (name_first and not first_name)

     

    micha80 

     

    Instead of 

     

    var apiURL = '/restapi/vc/authentication/sessions/current/user/profiles/name/first_name/set?restapi.response_format=json';

    Use

     

    var apiURL = '/restapi/vc/authentication/sessions/current/user/profiles/name/name_first/set?restapi.response_format=json';

     

    Also, I believe it's worth checking if the following call:

     

    https://<your_community_url>/restapi/vc/users/self/profiles

     return a value for name_first as this example: 

     

    <profile name="name_first" type="string">Olivier</profile>

     

     Which I don't think it does on your community micha80 (I will reach out to you by email)

  • micha80's avatar
    micha80
    Expert
    10 years ago

    Hi,

     

    with the Help of Paolo and Olivier I could solve the problem. The issue was the wrong spelled profile attribute: first_name instead of name_first. It is also good to know how to set a profile value with just an API or URL call.

     

    Many thanks!

    Michael