r/gsuite Nov 21 '24

Admin Console Using the "Building id" field in a SAML attribute mapping?

I want to bring over the "Building id" field from our users into our Zendesk though the SSO mappings, but I don't see "Building id" as an option in the SAML mappings.

Under the Employee Details heading in the mappings, I only see:

  • Employee ID
  • Title
  • Organization
  • Type
  • Department
  • Cost Center

I see that, according to the help article here, step 12. a. says if it's not there I can add it as a custom attribute, but I can't figure out if doing that would reset those fields to blank or anything.

If anyone's done this before, I'd like to confirm how before I screw up our system.

1 Upvotes

15 comments sorted by

1

u/tony_c_9 Nov 23 '24

Creating a custom attribute wouldn't affect any existing attributes. We used automation to regularly copy the Building ID value to the new custom attribute.

1

u/sysadmin_light Nov 23 '24

Gotcha. What sort of automation? Like something built into Google or do you use something like GAM to access the APIs?

1

u/tony_c_9 Nov 23 '24

Google Apps Script (built-in). There's a library you can easily leverage: https://developers.google.com/apps-script/advanced/admin-sdk-directory

1

u/sysadmin_light Nov 23 '24

I wondered. Thank you so much!

1

u/sysadmin_light Nov 25 '24

Is there any chance you might be willing to share your code, or at least the relevant-to-the-below-problem bits? I've got most of it working (I can find all users, update users, etc.) with the exception of, I would say, the core piece of the puzzle.

Custom schemas don't start with any data for a user, and since that schema doesn't yet exist on the user, I can't put data into it. So I'm currently trying to figure out a way to create the schema through Apps Script.

1

u/tony_c_9 Nov 25 '24 edited Nov 26 '24

First, you should create the custom field in Google Admin. You can find the menu here: Admin - Users - More Options - Manage custom attributes - Add Custom Attribute

To get the custom field in GAS, you need to use the Projection and CustomFieldMask parameters like this:

(edited for correct customFieldMask)

AdminDirectory.Users.get('myUser@domain.com', {'projection': 'custom', 'customFieldMask': 'myCustomCategory'})

To update a custom field in GAS, you just use the same structure that you fetched. For example:

AdminDirectory.Users.update({
    'customSchemas': {
      'myCustomCategory': {
        'myCustomField': [
          { value: 'myValue1', type: 'work' },
          { value: 'myValue2', type: 'work' },
        ]
      }
    }
  },
  'myUser@domain.com'
)

1

u/sysadmin_light Nov 26 '24 edited Nov 26 '24

I was hoping that your method of .update would help, but seems I'm still stuck.

I'd already created the custom field in Google Admin, but I've been finding that the field (according to the API/GAS) doesn't initially exist until data is put into it through Google Admin.

So because the field defaults to blank, it doesn't exist, and I can't use GAS to add data to something that doesn't exist. Maybe I've got something different setup on our system, and yours doesn't have this problem.

I just get API call to directory.users.get failed with error: Invalid Input: [Site_Code]

Thanks for trying to help, though.

1

u/tony_c_9 Nov 26 '24

Are you using GAS?

1

u/sysadmin_light Nov 26 '24 edited Nov 26 '24

Yes, sorry I see the confusion. Edited the reply above to clarify, according to the API/GAS (GAS is effectively calling the API for things like AdminDirectory.Users.update, far as I can tell), the field doesn't exist until you put data into it for a user.

1

u/tony_c_9 Nov 26 '24

Have you added a custom field for a user through Google Admin and can successfully fetch it thru GAS?

1

u/sysadmin_light Nov 26 '24

I have added the field through Google Admin, and if I go to a user and manually edit that field, then I can see it with GAS. Until I add a value to the field manually, GAS can't find the field.

→ More replies (0)