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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Deep_REU
Regular Visitor

How to access Web API data, post generation Token

I need to access Web API data, I have generated a function to access the token (it will refresh every time I invoke the function)

 

Now I have User email  & password specifially fo the API (not my own org credentials), how to use all three (token, user email, password) to access the web api data.

 

I tried solutions but it says anonymously method you can not provide credentials, any help would be really appreciated.

4 REPLIES 4
Anonymous
Not applicable

Hi @Deep_REU 

Has your problem been resolved? If so, could you mark the corresponding reply as the solution so that others with similar issues can benefit from it?

 


Best Regards,

Jayleny

Not yet. Checking internally if it's causing issues by any firewall blockage internally.
FarhanJeelani
Super User
Super User

To access data from a Web API using your token, user email, and password, it usually depends on how the API is set up for authentication. Here's a general way you can approach it, but remember to check the API’s documentation for any specifics.

 

Steps:

1. Token Authentication: It seems like you already have a function that refreshes the token, which is great! You'll include this token in the request headers as a `Bearer` token, which is standard for many APIs.

 

2. Headers Setup: In many cases, you'll pass the token in the `Authorization` header. If the API also requires the email and password (like for some custom authentication), they might be passed either as parameters in the body of the request or in the URL.

Here’s an example in Python (using the `requests` library):

python

import requests

# API URL you are trying to access
api_url = "https://api.example.com/data"

# Set up headers with your token (Bearer token)
headers = {
"Authorization": f"Bearer {your_token}",
"Content-Type": "application/json"
}

# If you need to send email and password in the request body, you can add them here
data = {
"email": "user@example.com", # Email of the user
"password": "user_password" # Password of the user
}

# Send a GET request (or POST if needed) to the API
response = requests.get(api_url, headers=headers, params=data) # Use .post() if it's a POST request

# Check the API response
if response.status_code == 200:
print("Data fetched successfully:", response.json())
else:
print("Error fetching data:", response.status_code, response.text)

 Additional Tips:

- Basic Authentication: If the API needs email and password as basic authentication, you might need to use the `HTTPBasicAuth` class from the `requests` library alongside your token.

python

from requests.auth import HTTPBasicAuth
import requests

api_url = "https://api.example.com/data"

# Use Basic Authentication for email and password, and include the token as well
response = requests.get(api_url,
auth=HTTPBasicAuth('user@example.com', 'user_password'),
headers={"Authorization": f"Bearer {your_token}"})

if response.status_code == 200:
print("Success:", response.json())
else:
print("Error:", response.status_code, response.text)



- Check API Documentation: Some APIs might not support using email/password alongside a token, and they might prefer one type of authentication at a time. If you’re getting errors like "anonymous method cannot provide credentials," this could mean the API expects only one method of authentication.

- Token Expiry: Make sure your token is refreshed properly and is still valid when you're making requests. If the token has expired, you’ll need to refresh it and get a new one.

If you're still having issues, I can try to help with more specific suggestions if you provide more details about the API you're using.

The token I am generating is incorrect because I need to generate a token using the user's email and password. I have the client ID, tenant ID, and client secret. Now, I need to generate a token that incorporates all five elements (client ID, tenant ID, client secret, user email, and user password) so that the token can be used to access the API. I tried the code but its not working.

 

let
// Define the necessary parameters
tenantId = "your-tenant-id", // Replace with your tenant ID
clientId = "your-client-id", // Replace with your client ID
clientSecret = "your-client-secret", // Replace with your client secret
userEmail = "user@example.com", // Replace with the user's email
userPassword = "userpassword", // Replace with the user's password

// Define the OAuth2 token URL for Azure AD (use "common" if multi-tenant)
tokenUrl = "https://login.microsoftonline.com/" & tenantId & "/oauth2/v2.0/token",

// Define the request body (using x-www-form-urlencoded format)
requestBody = [
client_id = clientId,
client_secret = clientSecret,
scope = "https://graph.microsoft.com/.default", // Adjust scope as necessary
grant_type = "password", // Grant type for Resource Owner Password Credentials flow
username = userEmail,
password = userPassword
],

// Convert the request body to a URL-encoded string (x-www-form-urlencoded)
bodyContent = Uri.BuildQueryString(requestBody),

// Define the headers (Content-Type should be application/x-www-form-urlencoded)
headers = [
#"Content-Type" = "application/x-www-form-urlencoded"
],

// Send the POST request to get the token
response = Web.Contents(tokenUrl, [
Headers = headers,
Content = Text.ToBinary(bodyContent)
]),

// Parse the response as JSON
responseJson = Json.Document(response),

// Extract the access token from the response
accessToken = try responseJson[access_token] otherwise null
in
accessToken

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.

Top Solution Authors
Top Kudoed Authors