API PUT Error: Full authentication is required to access this resource

Hello,

I am trying to execute a PUT API call to update a DOMO variable in a workflow. I have the variable's URL and I have the secret token needed to authorize the call (per DOMO's documentation), however I am still getting the following error:

{"status":401,"statusReason":"Unauthorized","path":"/api/query/v1/functions/template/146","message":"Full authentication is required to access this resource"

Below is the URL format and the bit of code I am using for the PUT function

URL: https://mycompany.domo.com/api/query/v1/functions/template/XXX

CODE:

def update_date():    
  url = 'https://mycompany.domo.com/api/query/v1/functions/template/XXX'   
  auth_token = "XXX" 
  headers = {        
            "Authorization": f"Bearer {auth_token}",        
            "Content-Type": "application/json"    
            }    
  data = {        
          "id": ###,        
          "name": "Booked as of",        
          "owner": ###,        
          "locked": "false",        
          "global": "true",        
          "certificationStatus": "EXPIRED",        
          "expression": "DATE('2025-05-15')", # Field I am trying to update  
          "checkSum": "XXX",        
          "links": [],        
          "legacyId": "calculation_XXX",        
          "lastModified": ###,        
          "created": ###,        
          "aggregated": "false",        
          "analytic": "false",        
          "nonAggregatedColumns": [],        
          "dataType": "DATE",        
          "status": "VALID",        
          "cacheWindow": "non_dynamic",        
          "columnPositions": [],        
          "functions": []           
          "DATE" [],        
          "functionTemplateDependencies": [],       
          "archived": "false",        
          "hidden": "false",        
          "variable": "true"   
         }    

  response = requests.put(url, json=data, headers=headers)    
  
  if response.status_code == 200:        
    return print(response.text)    
  else:        
    print(response.text)

Does anyone have any clue on what I am missing here?

Tagged:

Answers

  • Domo has different types of tokens and they are easy to confuse. Make sure you are using the correct type of token. It looks like you are trying to use a client secret directly in the header. You use a client ID and secret to generate a token from Domo's token endpoint and then use the token.

    # Define Domo API credentials
    domo_client_id = 'XXXXX' # Domo client ID
    domo_client_secret = 'XXXXX' # Domo client secret
    domo_dataset_id = "XXXXX"


    # Initialize Domo SDK
    domo = Domo(domo_client_id, domo_client_secret, api_host='api.domo.com')


    # Get authentication token from the Domo API
    def get_auth_token():
    payload = {
    "client_id": client_id,
    "client_secret": client_secret,
    "grant_type": "password",
    "username": username,
    "password": password
    }
    headers = {"Content-Type": "application/json"}
    response = requests.post(token_url, json=payload, headers=headers)

    if response.status_code == 200:
    print("Auth token successfully retrieved.")
    return response.json().get("access_token")
    else:
    print(f"Failed to retrieve token: {response.status_code}, {response.text}")
    return None

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **

  • swadds
    swadds Member

    Hey there, thank you for the response! You are right in saying that DOMO's tokens can be hard to understand. I ended up deducing that the root of the issue was related to having SSO enabled for my account. Thus, I simply needed to simply create a access token for the user I wanted to access the API through and leverage the below bit of code in the headers:

    headers = {'x-domo-developer-token': developer_token}

    where 'developer_token' is the alias given to the access token I created in my DOMO instance.

  • I don't think it's related to SSO. So you went to Admin > Authentication > Access Tokens, created a token and used it in the statement as an 'x-domo-developer-token' and its now working?

    ** Was this post helpful? Click Agree or Like below. **
    ** Did this solve your problem? Accept it as a solution! **

  • swadds
    swadds Member

    Correct.