Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Fabric RestAPi GetDefinition on Semantic model returns Unknown Error

Hi - running into an issue trying to get the defintion of a Semantic Model in a notebook.

Note that the parameters are correct as if i drop the /getDefinition from the end I get results back as expected for the Semantic Model.

Code in notebook below

 

import requests
import json

token_string = mssparkutils.credentials.getToken("https://api.fabric.microsoft.com/")
header = {'Content-Type':'application/json','Authorization': f'Bearer {token_string}'}

addbody = {}


add_Response = requests.get(addURL,headers=header, data=json.dumps(addbody))

from pyspark.sql import SparkSession
from pyspark.sql import Row, Column
from pyspark.sql.functions import col, year, regexp_replace

# Initialize Spark Session
spark = SparkSession.builder.appName("JsonToDelta").getOrCreate()

# Extract the list of results
sourceData =add_Response.json()
print(sourceData)

4 Replies

  • Hello Anonymous 

     

    The error occurs because the Fabric REST API’s `getDefinition` endpoint for semantic models requires a POST request instead of GET. 


    try this 



    add_Response = requests.post(addURL, headers=header)

     

    if this is helpful please accept the answer 

    • Anonymous's avatar
      Anonymous
      Not applicable

      nilendraFabric - thanks for that - now I feel really stupid for not spotting it was a POST rather than a GET method 🙂