Hi,
I have a report that works fine in Power BI desktop (retrieving JSON data from a public web API using Json.Document(Web.Contents()) ). However, when I publish I get the error that "Your data source can't be refreshed because the credentials are invalid". Full query below. URLs changed for privacy:
let AuthKey = GetSessionId(), url = "https://publicapi.com", body = "{typeName: 'Project', fields: ['name', 'TrackStatus.name', 'BudgetStatus.name'], where: { _type: 'Compare', leftExpression: {fieldName: 'State'}, operator: 'Equal', rightExpression: {value: 'Active'} }, }", Source = Json.Document(Web.Contents(url,[ Headers = [#"Authorization"= AuthKey , #"Content-Type"="application/json"], Content = Text.ToBinary(body) ] )), entities = Source[entities], in entities
The GetSessionId() method refers to another query to another web api to receive the session id
let Source = Json.Document(Web.Contents("https://publicapi.com",[ Headers = [#"Content-Type"="application/json"], Content = Text.ToBinary("{userName:'<user>',password:'<pass>'}") ] )), sessionId = "Session " & Source[sessionId] in sessionId