Forum Discussion

DrillDownBI's avatar
DrillDownBI
Icon for Helper I rankHelper I
3 years ago
Solved

Connect with Basic authentication and API key

Hi, I need help to get a connection to web with API key and basic authentication. I have both API key and username/password and need to build a query in m language to get this to work. My connecti...
  • Adamboer's avatar
    3 years ago

    Hi there,

    It sounds like you're having trouble connecting to a web API using Power Query in Excel. One thing to check is whether your API endpoint requires any additional parameters or headers that you might not be passing in your current code. Another thing to consider is whether your API key and authentication credentials are correct.

    One way to troubleshoot this issue is to use a tool like Postman to test your API endpoint and make sure you're able to retrieve data successfully. Once you're able to get data using Postman, you can use the same parameters and headers in your Power Query code.

    Here's an example of a similar Power Query code that connects to a web API using an API key and basic authentication:

    let apiKey = "your_api_key_here", username = "your_username_here", password = "your_password_here", auth = "Basic " & Binary.ToText(Text.ToBinary(username & ":" & password), BinaryEncoding.Base64), apiUrl = "your_api_url_here", query = "/your_api_endpoint_here", url = apiUrl & query, headers = [ #"Authorization" = auth, #"APIKey" = apiKey ], source = Json.Document(Web.Contents(url, [Headers=headers])) in source

    Hope this helps you get started. Let me know if you have any further questions.