PowerBI to Solidworks PDM Web API Authentication Issue with Anonymous Authentication and Bearer Token

101 views Asked by At

I am getting the "We couldn't authenticate with the credentials provided. Please try again." error when attempting to get a thumbnail for an assembly. I have successfully completed all of these in Postman, but it fails in PowerBI on the last call to get the thumbnail. If I change the version to something that doesn't exist I get a "404 Not Found" error, indicating that the bearer token does still work. Here is my M code:

let
    rootURL = "http://pdm-web-server:65453/api/pdm-vault",

    //AUTHORIZATION
    authPath = "/authenticate",
    authHeaders = [#"Content-Type" = "application/json", #"Accept" = "application/json"],
    authPostData = "{'Username': 'user', 'Password': 'pass'}",
    authResponse = Web.Contents(
        rootURL,
        [
            RelativePath = authPath,
            Headers = authHeaders,
            Content = Text.ToBinary(authPostData)
        ]
    ),
    token = Text.Combine({"Bearer ", Json.Document(authResponse)[JwtString]}),

    //SEARCH
    searchPath = "/search",
    searchHeaders = [#"Content-Type" = "application/json", #"Accept" = "application/json", #"Authorization" = token],
    searchPostData = "'10000000.sldasm'",
    searchResponse = Web.Contents(
        rootURL,
        [
            RelativePath = searchPath,
            Headers = searchHeaders,
            Content = Text.ToBinary(searchPostData)
        ]
    ),
    searchResults = Json.Document(searchResponse),
    firstSearchResultId = Text.From(searchResults{0}[Id]),

    //PART INFO
    infoPath = Text.Combine({"/files/", firstSearchResultId}),
    infoHeaders = [#"Accept" = "application/json", #"Authorization" = token],
    infoResponse = Web.Contents(
        rootURL,
        [
            RelativePath = infoPath,
            Headers = infoHeaders
        ]
    ),
    infoResults = Json.Document(infoResponse),
    firstInfoVersion = Text.From(infoResults{0}[Version] - 1),

    //THUMBNAIL
    thumbnailPath = Text.Combine({"/files/", firstSearchResultId, "/", firstInfoVersion, "/thumbnails"}),
    thumbnailHeaders = [#"Authorization" = token],
    thumbnailResponse = Web.Contents(
        rootURL,
        [
            RelativePath = thumbnailPath,
            Headers = thumbnailHeaders
        ]
    ),
    thumbnailResults = Binary.ToText(thumbnailResponse)
in
    thumbnailResults

Link to the PDM Thumbnail Call

Any help is appreciated.

0

There are 0 answers