Forum Discussion

spencer_sa's avatar
spencer_sa
Impactful Individual
8 months ago
Solved

API create-semantic-model error ""Parts: Must be a non-empty collection with no null elements""

End goal:  copy a direct lake sementic model across tenants. Specific problem:  As a first step, I'm trying to use the Fabric REST API to create a new semantic model based on the definition of an ...
  • spencer_sa's avatar
    spencer_sa
    8 months ago

    I think I've figured it out - it's annoying.
    The python requests.post() has two possible inputs (well, three if you include params). The usual one is 'data' and it expects a dict. The other is 'json', which also expects a dict-like structure, but coerces it into application/json.
    (note I tried data = json.dumps(payload) and got an invalid media error)

  • Ahmed-Elfeel's avatar
    Ahmed-Elfeel
    8 months ago

    spencer_sa So the issue was in the Content-Type Header,Right?

    It should be 

    Content-Type: application/json

     and the correct usage should be like that:

    response = requests.post(
        url,
        json=payload_dict,      # <-- correct
        headers={
            "Authorization": f"Bearer {token}",
            "Content-Type": "application/json"
        }
    )