Sending nil as Users attribute on Update doesnt removes attribute

Hi guys, I am using first time this forum so if I missed correct place to write about my problem please advise.

About the problem. I am working on ruby on rails app and auth0 those are gems I am using:

gem 'auth0', '~> 4.11'
gem 'omniauth-auth0', '2.4.1'
gem 'omniauth-rails_csrf_protection', '~> 0.1'

App is built with ruby '2.3.4' rails 4.1.8

My problem is when I send nil as value in some of users attributes it doesnt remove that attribute on auth0 side. On the auth menagement api if I use null as value in User update jason it removes that user field.

 def self.auth0_update_user user, user_id
   Auth0M2MClient.instance.with_client do |client|
    auth0_user = client.user(user_id)
    content = user_update_details(user, auth0_user)
      client.update_user(user_id, content)
    end
   end

this is my json and if I put any string there it update user attribute on auth0
(byebug) content
{“family_name”=>nil, “given_name”=>nil, “email”=>“user328@user.com”}

Do I missing here anything obvious?

Hi @nezir.zahirovic,

Welcome to the Auth0 Community!

I can confirm, passing a null value to the API should remove the existing value for the field.

This leads me to believe this is either a bug in the SDK, or an issue with the request. What is the response if you were to pass {“family_name”=>nil} to the update user function?

Hey Dan, thank you for quick replay. Here is a sample in ruby console for you question, its responds with ‘fields required, and it also mentioning that family_name her so it looks like it doesnt reach the API, neither’:

On a first screen shoot I used patch_user here is user_update method which is just alias of it:

Can you post a code snippet (not a screenshot) so I can test it on my end?

Hey Dan, thank you for your replay. Here is my code:

      def self.auth0_update_user user, user_id
        Auth0M2MClient.instance.with_client do |client|
          content = user_update_details(user)
          client.update_user(user_id, content)
          
          # user_update_details method above generating hash or you can use this below:
          # in example I am setting given_name as nil and that should remove users attributes on auth0

          # client.update_user(user_id, {
          #   "email": user.email,
          #   "given_name": nil, 
          #   "family_name": user.family_name
          # })
        end
      end
def self.user_update_details user
    ['family_name', 'given_name', 'email'].inject({}) do |res, field|
        case field
          when 'email'
            res.merge!({ field => set_email(user) })
          else
            if user.send(field).present?
              res.merge!({ field => user.send(field) })
            else
              #here I am adding nil to keys/attributes who doesnt have a value
              res.merge!({ field => nil })
            end
          end
        end
      end

As I mention this is on update user. I hope this is enough for testing if not please ping me.

It looks like you created an issue in GitHub for this. I am going to let that team investigate. I’ll update here when there is a resolution.

Here is the issue for reference:

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.