<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to change parameter using REST API? in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/How-to-change-parameter-using-REST-API/m-p/4028566#M53985</link>
    <description>&lt;P&gt;I wanted to change the parameter of a dataset using Python.&amp;nbsp;I created an app with permission &lt;STRONG&gt;Dataset.ReadWrite.ALL &lt;/STRONG&gt;from Azure AD.&lt;BR /&gt;I was able to get the Access token successfully but could not&amp;nbsp;change the parameter. My code is this-&lt;/P&gt;&lt;LI-CODE lang="python"&gt;access_token = 'MY_ACCESS_TOKEN'
workspace_id = "MY_Workspace_ID"
dataset_id = "MY_Dataset_ID"
header = {'Content-Type':'application/json',
          'Authorization':f'Bearer {access_token}'}

# Replace these with your details
parameter_name = 'NAME'
new_value = 'VALUE'

# Define the API endpoint
url = f'https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/datasets/{dataset_id}/Default.UpdateParameters'

# Create the headers
headers = {
    'Content-Type': 'application/json',
    'Authorization': f'Bearer {access_token}'
}

# Define the body with the parameter update details
body = {
    "updateDetails": [
        {
            "name": parameter_name,
            "newValue": new_value
        }
    ]
}

# Make the API request
response = requests.post(url, headers=headers, data=json.dumps(body))
print(response.status_code)
print(response.json())&lt;/LI-CODE&gt;&lt;P&gt;It gives output-&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;403&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN&gt;{'error': {'code': 'InvalidRequest', 'message': 'This operation is only supported for the dataset owner'}}&lt;/SPAN&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN&gt;NB:&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;I am the owner of the dataset.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Am I missing something here? Your help is needed.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 07 Jul 2024 09:36:43 GMT</pubDate>
    <dc:creator>Cortana</dc:creator>
    <dc:date>2024-07-07T09:36:43Z</dc:date>
    <item>
      <title>How to change parameter using REST API?</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/How-to-change-parameter-using-REST-API/m-p/4028566#M53985</link>
      <description>&lt;P&gt;I wanted to change the parameter of a dataset using Python.&amp;nbsp;I created an app with permission &lt;STRONG&gt;Dataset.ReadWrite.ALL &lt;/STRONG&gt;from Azure AD.&lt;BR /&gt;I was able to get the Access token successfully but could not&amp;nbsp;change the parameter. My code is this-&lt;/P&gt;&lt;LI-CODE lang="python"&gt;access_token = 'MY_ACCESS_TOKEN'
workspace_id = "MY_Workspace_ID"
dataset_id = "MY_Dataset_ID"
header = {'Content-Type':'application/json',
          'Authorization':f'Bearer {access_token}'}

# Replace these with your details
parameter_name = 'NAME'
new_value = 'VALUE'

# Define the API endpoint
url = f'https://api.powerbi.com/v1.0/myorg/groups/{workspace_id}/datasets/{dataset_id}/Default.UpdateParameters'

# Create the headers
headers = {
    'Content-Type': 'application/json',
    'Authorization': f'Bearer {access_token}'
}

# Define the body with the parameter update details
body = {
    "updateDetails": [
        {
            "name": parameter_name,
            "newValue": new_value
        }
    ]
}

# Make the API request
response = requests.post(url, headers=headers, data=json.dumps(body))
print(response.status_code)
print(response.json())&lt;/LI-CODE&gt;&lt;P&gt;It gives output-&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;403&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN&gt;{'error': {'code': 'InvalidRequest', 'message': 'This operation is only supported for the dataset owner'}}&lt;/SPAN&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN&gt;NB:&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN&gt;I am the owner of the dataset.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Am I missing something here? Your help is needed.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jul 2024 09:36:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/How-to-change-parameter-using-REST-API/m-p/4028566#M53985</guid>
      <dc:creator>Cortana</dc:creator>
      <dc:date>2024-07-07T09:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to change parameter using REST API?</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/How-to-change-parameter-using-REST-API/m-p/4028790#M53990</link>
      <description>&lt;P&gt;Hi Cortana&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error message says that your Service Principal (SPN) is not the Owner of the Semantic Model. I guess you created the report in Power BI Desktop and published it afterwards on behalf of your name. Now, that you wish to update the Parameter, you first need to take ownership by calling this REST API call with the SPN in your Python code:&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/take-over-in-group" target="_blank"&gt;https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/take-over-in-group &lt;/A&gt;Afterwards, once the SPN is owner, your call to update the parameter will work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope it helps.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jul 2024 16:12:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/How-to-change-parameter-using-REST-API/m-p/4028790#M53990</guid>
      <dc:creator>FabricGuy</dc:creator>
      <dc:date>2024-07-07T16:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to change parameter using REST API?</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/How-to-change-parameter-using-REST-API/m-p/4028825#M53991</link>
      <description>&lt;P&gt;Thank you so much&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/108615"&gt;@FabricGuy&lt;/a&gt;&amp;nbsp; It worked.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jul 2024 18:01:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/How-to-change-parameter-using-REST-API/m-p/4028825#M53991</guid>
      <dc:creator>Cortana</dc:creator>
      <dc:date>2024-07-07T18:01:54Z</dc:date>
    </item>
  </channel>
</rss>

