Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
PowerUser123
Helper II
Helper II

API Connection - Undefined Varaible: Json

I have the following query that generates a token to be used for an API call, but I'm getting an error message stating: Undefined Variable: json

 

I'm not sure if I'm missing anything or doing anything wrong?

let
    
    api_url = "https://someapi.com/api/",
    token_path = "getAccessToken", 
    Token_Response  = Json.Document(Web.Contents(api_url,
    [ 
      RelativePath = token_path,
      Headers = [#"Content-Type"="application/x-www-form-urlencoded"],
      Content=Text.ToBinary("username=clientid&password=password111")
    ]
    )
    ),
   
    token = Token_Response[token],

    path = "getList",  
    endDate = "2022-04-25 00:00:00",
    startDate= "2022-04-26 00:00:00",

    data1= Json.Document(Web.Contents(api_url,
   [ 
     Headers = [#"Accept"="application/json"],
     RelativePath = path,
     Query = [end_date=endDate, start_date=startDate, api_token=token]
     
   ]
   )
   )
in
     data1
2 REPLIES 2
v-chenwuz-msft
Community Support
Community Support

Hi @PowerUser123 ,

 

Please make sure the token or data1 reponse of web.connect is json type.

 

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amirabedhiafi
Impactful Individual
Impactful Individual

https://community.powerbi.com/t5/Desktop/Issue-with-getting-data-via-API-with-bearer-token/td-p/1262...

Amira Bedhiafi
Full Stack Business Intelligence Consultant @Capgemini

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.