Forum Discussion

Markzolotoy's avatar
Markzolotoy
Icon for Impactful Individual rankImpactful Individual
3 years ago

Nee help with M

I have the following M code:

url = "https://computername.domain.com:446/api/identity",
    ClientID = "domain\username",   // Username
    Secret = "password",  //Password   
    EncodedCredentials = "Basic " & Binary.ToText(Text.ToBinary(ClientID & ":" & Secret), BinaryEncoding.Base64),
    Identity = Json.Document(Web.Contents(url, 
            [
                Headers = [#"Content-Type"="application/x-www-form-urlencoded",#"Authorization"=EncodedCredentials],
                Content=Text.ToBinary("") // That makes this call a POST
            ]
        )
    )

It used to work fine. Now I am getting this:

DataSource.Error: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
Details:
https://computername.domain.com:446/api/identity

 

Any idea?

 

Thanks

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Markzolotoy,

    Have you check the api document to confirm they require you to directly send the secret and client id in header instead of contents?

    AFIAK, this type of API normally required you to post these string in contents to get the token for following operations and use in Authorization options.

    For example:

    let
        ClientID = "domain\username",
        Secret = "password",
        body = "Basic " & "client_id=" & ClientID & "&client_secret=" & Secret,
        url = "https://computername.domain.com:446",
        GetJson = Web.Contents(
            url,
            [
                Headers = [
                    #"Content-Type" = "application/x-www-form-urlencoded"
                ],
                RelativePath = "/api/identity",
                Content = Text.ToBinary(body)
            ]
        ),
        token = Json.Document(GetJson)[access_token],
        //get data
        Result = Web.Contents(
            url,
            [
                Headers = [
                    #"Content-Type" = "application/x-www-form-urlencoded",
                    Authorization = "Bearer " + token
                ],
                RelativePath = "/xxxxx/xxxxx"
            ]
        )
    in
        Result

    In addition, you can also take a look at the following link with similar error message if helps:

    Solved: Could not establish trust relationship for the ssl... - Microsoft Power BI Community
    Regards,

    Xiaoxin Sheng

  • Markzolotoy's avatar
    Markzolotoy
    Icon for Impactful Individual rankImpactful Individual

    My problem was that I was using a full computer name which worked in the past. After changing it to localhost it started working. However, running api to get actual data is not working, Here is my code:

     

        url_system = "https://localhost:446/api/home/system",
        Credentials = "Bearer " & Token[access_token],
        System = Json.Document(Web.Contents(url_system, 
                [
                    Headers = [#"Content-Type"="application/json",#"Authorization"=Credentials]
                ]
            )
        ),
        #"Converted to Table" = Record.ToTable(System),
        #"Added Index" = Table.AddIndexColumn(#"Converted to Table", "Index", 0, 1, Int64.Type),
        #"Filtered Rows" = Table.SelectRows(#"Added Index", each ([Value] <> 3288)),
        #"Expanded Value" = Table.ExpandRecordColumn(#"Filtered Rows", "Value", {"OkCount", "AlertCount", "Details"}, {"Value.OkCount", "Value.AlertCount", "Value.Details"}),
        #"Expanded Value.Details" = Table.ExpandListColumn(#"Expanded Value", "Value.Details"),
        #"Expanded Value.Details1" = Table.ExpandRecordColumn(#"Expanded Value.Details", "Value.Details", {"Id", "Name", "LastUpdated", "Status", "StatusColor", "WarningInfo", "AlarmInfo"}, {"Value.Details.Id", "Value.Details.Name", "Value.Details.LastUpdated", "Value.Details.Status", "Value.Details.StatusColor", "Value.Details.WarningInfo", "Value.Details.AlarmInfo"}),
        #"Changed Type" = Table.TransformColumnTypes(#"Expanded Value.Details1",{{"Value.Details.LastUpdated", type datetime}})

     

     

    I also tried a hard coded token that worked in Postman, still did not work. Here is the error I am getting:

    API foder is set like this:

     

    • Markzolotoy's avatar
      Markzolotoy
      Icon for Impactful Individual rankImpactful Individual

      For a moment it worked I think, but then started giving the same error.