Forum Discussion
Get data from API with token that expires
- 3 years ago
I just solved it.
Funciton GetAcessToken
() => let Url = "https://api.prismart.pt/api/Auth/login", Body ="{ ""username"": ""xxxx"", ""password"": ""xxxx""}", // Define the POST Request. Source = Json.Document( Web.Contents( Url, [ Headers=[#"Content-Type"="application/json"], Content= Text.ToBinary(Body) ] ) ), JsonOutput = Json.FromValue(Source), Text = Text.FromBinary(JsonOutput) in TextAnd
let Source = Json.Document(Web.Contents("https://api.prismart.pt/api/1040/InferenceDocuments/filter?taxonomy=Fatura&start=2022-08-01&end="&end, [Headers=[Authorization="Bearer "& GetAcessToken() ]])), #"Convertido em Tabela1" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error), #"Column1 Expandida" = Table.ExpandRecordColumn(#"Convertido em Tabela1", "Column1", {"id", "document", "type", "name", "state", "date", "documentId", "resultJson", "successPercentage", "taxonomy", "createdBy", "createdByName", "createdOn", "companyId", "errorMessage"}) in #"Column1 Expandida"Thanks for the help v-kkf-msft
I hope this page can help someone in the future.
Thank you for your reply.
I followed the first two steps. but I cant invoke the function.
I used the the application cliend if from the app registragions to cliend_id
The secret value from the app registragions to client_secret
And the Username and password from the API credentials
Changed the
https://login.microsoftonline.com/common/oauth2/token/
to the api url https://api.prismart.pt/api/Auth/login
When i invoke the fuction appears and error:
Ocorreu um erro na consulta ‘’. DataSource.Error: Não foi possível Web.Contents obter conteúdo de 'https://api.prismart.pt/api/Auth/login/' (415): Unsupported Media Type
Detalhes:
DataSourceKind=Web
DataSourcePath=https://api.prismart.pt/api/Auth/login
Url=https://api.prismart.pt/api/Auth/login/
Translated means something like
An error occurred in query ''. DataSource.Error: Web.Contents could not get content from 'https://api.prismart.pt/api/Auth/login/' (415): Unsupported Media Type
Details: (...)
I just solved it.
Funciton GetAcessToken
() =>
let
Url = "https://api.prismart.pt/api/Auth/login",
Body ="{ ""username"": ""xxxx"", ""password"": ""xxxx""}",
// Define the POST Request.
Source = Json.Document(
Web.Contents(
Url,
[
Headers=[#"Content-Type"="application/json"],
Content= Text.ToBinary(Body)
]
)
),
JsonOutput = Json.FromValue(Source),
Text = Text.FromBinary(JsonOutput)
in
TextAnd
let
Source = Json.Document(Web.Contents("https://api.prismart.pt/api/1040/InferenceDocuments/filter?taxonomy=Fatura&start=2022-08-01&end="&end, [Headers=[Authorization="Bearer "& GetAcessToken() ]])),
#"Convertido em Tabela1" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Column1 Expandida" = Table.ExpandRecordColumn(#"Convertido em Tabela1", "Column1", {"id", "document", "type", "name", "state", "date", "documentId", "resultJson", "successPercentage", "taxonomy", "createdBy", "createdByName", "createdOn", "companyId", "errorMessage"})
in
#"Column1 Expandida"
Thanks for the help v-kkf-msft
I hope this page can help someone in the future.