Issue with encoding when updating metadata
# support-questions-legacy
k
It seems it's not happy about special characters, like the danish Æ Ø Å. This is when updating through this endpoint: "http://localhost:3567/recipe/user/metadata"

https://cdn.discordapp.com/attachments/1112315271110209616/1112315273928785940/image.png

it looks fine in our raw data:
"name": "Mark Bøg Lønquist",
and also when logging the value before sending it to supertokens

https://cdn.discordapp.com/attachments/1112315271110209616/1112315848036732980/image.png

r
I see. Can you show us what you get when you retrieve the metadata?
Just want to know if it’s an issue with the dashboard UI or actual storage / retrieval of the info in the core
which backend SDK are you using? Cause if i try and add this name to a user, it works.

https://cdn.discordapp.com/attachments/1112315271110209616/1112339884431130675/Screenshot_2023-05-28_at_16.51.23.png

Finally, how are you calling the user metadata API? Via CURL / postman? Or using the usermetadata functions on the backend SDK? Or via the dashboard? If via curl / postman, can i see the request body, path, method and headers?
k
i'm doing it through Go using a standard http client and the data looks the same in the db

https://cdn.discordapp.com/attachments/1112315271110209616/1112411657013043221/image.png

Copy code
go
metaData := user.UserMetadata

    if user.Name != "" && !strings.ContainsRune(user.Name, '@') {
        index := strings.Index(user.Name, " ")
        if index > 0 {
            log.Println(user.Name[index+1:])
            metaData["first_name"] = user.Name[:index]
            metaData["last_name"] = user.Name[index+1:]
        } else {
            metaData["first_name"] = user.Name
        }
    }

    update := SuperTokensUserMetadataUpdateData{
        UserId:       userId,
        UserMetaData: metaData,
    }

    marshalled, _ := json.Marshal(update)

    req, err := http.NewRequest(http.MethodPut, metaDataPath, bytes.NewReader(marshalled))
    if err != nil {
        log.Fatalf("impossible to build request: %s", err)
    }
    req.Header.Set("Content-Type", "application/json")

    _, err = client.Do(req)
    if err != nil {
        log.Fatalf("impossible to send request: %s", err)
}
and it looks fine when I log the data out to console, so the httpclient might be doing something with it
seems to be fine when printing the marshalled data:
2023/05/28 18:10:27 {"userId":"38e63726-ea9b-42e7-9b9d-f836fe8cbfba","metadataUpdate":{"accountId":"8f04743a5afe4e1eb7de5545355d238f","first_name":"Mark","isEnrolledInCustomerClub":false,"last_name":"Bøg Lønquist","market":"en-nl"}}
r
Hmm. Okay. We shall investigate in go SDK.
Thanks for the info
I think what's missing in your request is that the content-type should be
application/json; charset=utf-8
. And not just
application/json
. You could also just use the
usermetadata.UpdateUserMetadata
function from our golang sdk instead of querying the core directly.
k
I was following your docs, and it shows "curl" commands 😛
r
Ah right. We shall update the docs. Thanks!
k
using charset=utf-8 fixed the issue, thank you
r
Your welcome. Also, the docs should have code snippets for golang. Maybe see that code tab instead of the curl one
k
not showing a code tab:

https://cdn.discordapp.com/attachments/1112315271110209616/1112439253880803549/image.png

r
ah right. So in that section it's just curl commands. But in the usermetadata section, it has golang code tabs
k

https://cdn.discordapp.com/attachments/1112315271110209616/1112439470600503387/image.png

the entire "MIGRATION" area has no code tabs
r
k
ah, yes, in other parts of the docs it does have code tabs
r
yea
k
is it not possible to call passwordhash/import through the go-sdk?
r
Not at the moment. We haven’t created a function wrapper for that in go yet. But a curl command should work just fine
22 Views