Forum Discussion

dchou's avatar
7 years ago

Read and write custom field

We have added custom fields on application level and message level by contacting Lithium support team.

 

I don't able to find a way to access it using and API.


Is there any specific API  call to get custom fields and Is it possible to set application-level custom setting using setting editor?

 

 

 

  • dchou

    We created custom fields for users profile at backend only so we do not have any option to update it using GUI and we used the API call to update those fields like below

    <#assign update_json= restadmin("/users/id/${user.id}/profiles/name/field_1/set?value="+updated_json?url) />

    But in your case, custom fields are not for user's profile. So can you confirm what are those fields for? I assumed fields are created on the post page. 

5 Replies

  • dchou

    If you enabled the custom field on message create page then it should return that field in Message API. 

    select * from messages

     Similarly, we created some custom fields for users and able to get those fields in the same API. See here https://prnt.sc/iqg425

    It would not return those fields if custom fields are blank for any user. As here it returns less number of custom fields compare to another user. See here https://prnt.sc/iqg4gz

    LMK if I am getting something out of line. 

  • dchou's avatar
    dchou
    Ace
    7 years ago

    VikasBThanks for your answer.

    Can you provide sample API call for set those fields?Because for now, I have all fields blank so not able to retrieve it.

  • VikasB's avatar
    VikasB
    Boss
    7 years ago

    dchou

    We created custom fields for users profile at backend only so we do not have any option to update it using GUI and we used the API call to update those fields like below

    <#assign update_json= restadmin("/users/id/${user.id}/profiles/name/field_1/set?value="+updated_json?url) />

    But in your case, custom fields are not for user's profile. So can you confirm what are those fields for? I assumed fields are created on the post page. 

  • nehaSharma's avatar
    nehaSharma
    Expert
    7 years ago

    dchou

    To set the value of the custom field for a message you can use the following API  :

    <#assign restapi = restadmin("/messages/id/<messageID>/metadata/key/<custom_field_name>/set?value=<custom_field_value>") />

    The following query can be used to view the value :

    select <custom_template_name> from messages where id = '<messageID>'

    P.S. Do confirm the Name of your Custom Field to be set from Lithium.

     

  • mbiel's avatar
    mbiel
    Expert
    5 years ago

    Hi, is it somehow possible to do sent new customfield data via post inside the body?

    We also have custom user profile field here, so this would be the "normal" way to set it:

    <#assign update_json= restadmin("/users/id/${user.id}/profiles/name/field_1/set?value="+updated_json?url) />

    But our data is from a textfield with 3000 characters and lots of special characters. I'm not sure if its a good way to send it this way...
    Also sending the textfield data this way seems to remove whitespaces.

    Sending something like this:

    Test1
    Test2
      Test3

    Results in the following when returned via the endpoint: 

     

    Test1
    Test2
    Test3