The function updateUserAttribute throws ApiException

  • 10 April 2018
  • 6 replies

I want to use Looker JavaSDK to update userAttribute. The code used UserAttributeApi to get one userAttribute. Then, I used setLabel() function to change label and called the function updateUserAttribute() to update the object. However, I got the Api Exception

"com.looker.api3client.ApiException: {“message”:“Not found”,“documentation_url”:""}"

See the source code as below

           Long userAttributeId = new Long(17);
UserAttributeApi userAttributeApi = new UserAttributeApi(lookerApiClient);
UserAttribute userAttribute = userAttributeApi.userAttribute(userAttributeId,null);
userAttribute.setLabel("Test Label");

6 replies

Userlevel 3

Hey @lumiaowpi, a 404 could mean that the User Attribute ID specified does not exist or you don’t have the correct permissions to modify it. I would suggest navigating to the User Attributes page in the Looker UI after creating it via the API to confirm that it exists. You could also use the Get User Attribute endpoint to confirm it exists before updating it. Hope this helps!

Hi @paola Thanks for responding to my question. I tested the same userAttributeID in Looker UI. It worked well and updated the value. I was testing the same API credentials and same user in the Java code and the API interactive doc.

In the java code, I got userattribute object, but could not update it. Could you find anything wrong with my code? Thanks

I attached the whole java code. I can get the userAttribute object from API, but can’t update it

import io.swagger.client.ApiClient;

import io.swagger.client.ApiException;

import io.swagger.client.Configuration;

import io.swagger.client.api.ApiAuthApi;

import io.swagger.client.api.UserAttributeApi;

import io.swagger.client.model.AccessToken;

import io.swagger.client.model.UserAttribute;

import java.util.List;

public class TestLookerApi {

public static void main(String[] values) throws Exception {
ApiClient lookerApiClient = new ApiClient();
ApiAuthApi authAPI = new ApiAuthApi(lookerApiClient);
AccessToken authenticatingToken = authAPI.login("yyyyyyyyyyyyyyyyy", "zzzzzzzzzzzzzzzzzzzz");
lookerApiClient.addDefaultHeader("Authorization", "token " + authenticatingToken.getAccessToken());
UserAttributeApi userAttributeApi = new UserAttributeApi(lookerApiClient);

Long id = new Long(11);
UserAttribute userAttribute = userAttributeApi.userAttribute(id,null);




Userlevel 3

No problem @lumiaowpi! Thanks for attaching your code. To clarify, are you creating a new user attribute and then updating the user attribute? Or are you updating an existing user attribute that already exists and was created via the UI?

I’d also like to mention that the ID parameter in the User Attribute endpoints is read-only. Which means Looker will generate that ID value for you. You can grab the ID from the response from the Create User Attribute endpoint or through the Looker UI.

@paola , I’m updating an existing user attribute that already exists and was created via the UI.

From the Looker UI, I got the userattributeID and hardcoded it in the source file " Long id = new Long(11);"

If you have an chance, could you or someone test the same code in your local environment to see if it works or not.


Userlevel 3

Hey @lumiaowpi, thanks for clarifying! Looker support is unable to test custom code. If you are seeing issues when testing the Update User Attribute endpoint via our interactive API documentation, feel free to visit and we can investigate further.