Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Popopop
New Member

401 (Unauthorized) when calling UpsertGoalCurrentValueConnection() API

Hi,

I'm trying to make the following request:

 

    $api = "api.powerbi.com"
    $response = Invoke-WebRequest `
        -Method Post `
        -Uri "https://$api/v1.0/myOrg/internalScorecards($scorecardId)/goals($($currentGoal.id))/UpsertGoalCurrentValueConnection()" `
        -Body ($query) `
        -ContentType "application/json" `
        -Headers @{ "Authorization" = "Bearer $token" }
}

 

 

but I'm getting a 401 (Unauthorized) response.
I get my token like this:

 

$api = "api.powerbi.com"
Login-PowerBI
$bearer = (Get-PowerBIAccessToken)["Authorization"]
$token = $bearer.SubString(6, $bearer.Length - 6)

 

 

 

 

How can I get authorization to use this api?

2 REPLIES 2
Anonymous
Not applicable

Hi @Popopop ,

Please update the code as below when get the token and check if it can resolve the problem...

$api = "api.powerbi.com"
Login-PowerBI
$bearer = (Get-PowerBIAccessToken)["Authorization"]
$token = $bearer.SubString(7, $bearer.Length - 7)

In addition, please review the following blog. Hope it can help you.

Power BI Goals Pro Tip: Take over goal connections in a scorecard

yingyinr_0-1652688222426.png

Best Regards

Hi, this doesn't solve the problem.
For the record, in the same script I execute this with the token I get (both with the code written in my original post and both with the two methods you suggested me), and this works with no problem:

$response = Invoke-WebRequest -Uri "https://$api/v1.0/myorg/groups/{$groupId}/scorecards($scorecardId)/goals" -Headers @{ "Authorization" = "Bearer $token" }
$scorecard = $response.Content | ConvertFrom-Json

 

So it's that request in particular that doesn't work.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.