Forum Discussion

aditya's avatar
aditya
Data Storage
01-16-2025

Use dashboard API to get data in python dataframe

I have a widget which displays users with points and I want to fetch top 10 users from that widget.Also I need to select current month "01/2025" from the filter.Let me know how this can be done

But I'm getting weired error.Please help!

I'm an admin so I have a token from my profile section.

 

 

import requests

url = "https://bp.sisense.com/api/v1/dashboards/4577fc4415dd7d003339bfdc/widgets/4577c7716dd7d554441bjae"


# authentication
headers = {
"Content-Type": "application/json",
"Authorization": "" }

# Send the request
response = requests.get(url, headers=headers)
response

# Check if the request was successful
data = response.json()
data

 

Error:

{'error': {'code': 5002,
  'message': 'Invalid token.',
  'status': 401,
  'httpMessage': 'unauthorized'}}

 

10 Replies

  • HamzaJ's avatar
    HamzaJ
    Data Integration

    The token has been removed, however do you use Bearer before the token? So "Authorization": "Bearer TOKEN"

  • AssafHanina's avatar
    AssafHanina
    Sisense Employee

    Hey aditya ,

    As mentioned by HamzaJ , it's seems that the Bearer is missing from the Authorization. 
    therefore, the error message is Unauthorized.

    Please find an updated Sample script including the Bearer token 

     

    import requests
    
    # define Variables
    server = '' #format of https://my-sisense.sisense.com
    token = ''
    dashboard_oid = ''
    widget_oid = ''
    
    ### 
    headers = {
        "Authorization": f"Bearer {token}",
        "Content-Type": "application/json"
    }
    url = f'{server}/api/v1/dashboards/{dashboard_oid}/widgets/{widget_oid}'
    
    # Send the request
    response = requests.get(url=url, headers=headers)
    print(response.status_code)
    
    data = response.json()
    print(data)
    

     

    Best Regards

  • Hi aditya,

    Thank you for reaching out. I edited your post to remove potentially sensitive information.

    It looks like the authorization token is to short. Can you make sure that it is copied correctly and let us know how it goes?

    Thank you.

  • aditya's avatar
    aditya
    Data Storage

    DRay , I have intentionally not provided the token,it is usually Bearer 'token' format

    Thanks!

  • aditya's avatar
    aditya
    Data Storage

    AssafHanina ,

    I also tried in the format which you shared but I'm getting same error "Unauthorised".

    Thanks!

    • AssafHanina's avatar
      AssafHanina
      Sisense Employee

      hey aditya ,

      Thanks for letting me know. 

      DRay - Please arrange for internal technical resources to provide assistance in this case.

      Best regards

    • DRay's avatar
      DRay
      Admin

      Good to hear! How did you get it done?