I am trying to extract data from an api using power query for further analysis but unfortunately its throwing an error saying we couldnt authenticate with credentials provided, please try again. The api uses basic authentication and there are seperate end points for log in (authentication) and other structured data. Please see below below code I have used in my power query ( entire code in same query)
`Step 1
Mainurl = "url"
path = " api/v1/auth/login"
login = Json.Document( Web.Content ( Mainurl,
RelativePath = path,
[
Header = [#"Content Type" = "application/json", #"Authorisation" = Basic < base 64 encoded username : password > ]
]
))
Token =Text.From(Record.Field(login,"antiCsrfToken") -- capture token in a variable
Step 2
datarequestAPI = "api/vendor/transaction"
Datarequest =Json.Document( Web.Content ( Mainurl,
RelativePath = datarequestAPI ,
[
Headers = [#"Content Type" = "application/json", #"Authorisation" = "Bearer "& Token ]
]
))`
While debugging the code everything works well for step 1 block ie the login works well and it returns an antiCsrfToken which I then pass into a variable to use in step 2. But unfortunately its erroring out in step 2 saying we couldnt authenticate with credentials provided
tried api/vendor/transaction method without providing token in the header as I didnt see an authorisation part in parameters as per API documentation. the cURL contained only mainurl- path - query parameters. The header consisted of only Accept : application/json. Naturally I thought this method doesnt require a token as parameter. But it didnt work
Provided the token as an APIKey in the header in step 2. This also failed
Provided Bearer token authorisation in header ( above code ) - with and without space after 'Bearer'
With and without text convertion step for token variable.
tried to construct the authentication using UI
All the above steps were followed by clicking data source setting and making sure the connection type = anonymous and privacy = none ( tried privacy = none, public, organisation )
All my attempts failed with same error "we couldnt authenticate with credentials provided, please try again". The fact that the login method is working fine and but the next step failing is baffling me. Must be something to do with how I am passing the token in the next step "api/vendor/transaction" method or if at all token is required to extract the data. I am not sure how else I can let the server know that I have done the login and please trust me and give me my data!!.