Forum Discussion
API create-semantic-model error ""Parts: Must be a non-empty collection with no null elements""
- 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) - 8 months ago
spencer_sa So the issue was in the Content-Type Header,Right?
It should be
Content-Type: application/jsonand the correct usage should be like that:
response = requests.post( url, json=payload_dict, # <-- correct headers={ "Authorization": f"Bearer {token}", "Content-Type": "application/json" } )
Hi spencer_sa,
Before Telling you the solution you should Look at this documentation (Microsoft Learn)
So based on the official documentation and the snippet you provided the most likely issue is a formatting mismatch between your request and what the API expects
So To solve this (Based on the official Documentation)
- Remove the format field; The official request body schema does not include a format property for this specific endpoint
- Your current snippet looks like a Python dictionary So before sending the request you must serialize it into a valid JSON string
- While your payloads are snipped make sure that the payload strings are valid Base64 and that no special characters are being incorrectly escaped during your code string construction
- Here is the structure you should aim for based on the documentation:
{
"definition": {
"parts": [
{
"path": "definition.pbism",
"payload": "ew snip",
"payloadType": "InlineBase64"
},
{
"path": "model.bim",
"payload": "ew snip",
"payloadType": "InlineBase64"
},
{
"path": ".platform",
"payload": "ew snip",
"payloadType": "InlineBase64"
}
]
},
"displayName": "Your New Semantic Model Name"
}
I hope this is helpful ☺️❤️
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-Elfeel8 months agoSuper User
spencer_sa So the issue was in the Content-Type Header,Right?
It should be
Content-Type: application/jsonand the correct usage should be like that:
response = requests.post( url, json=payload_dict, # <-- correct headers={ "Authorization": f"Bearer {token}", "Content-Type": "application/json" } )- spencer_sa8 months agoImpactful Individual
As long as you use the following
json=payload_dictyou don't need the Content-Type as it coerces that by using the 'json' input, but yes.
This is what helped me - about half way down.
https://requests.readthedocs.io/en/latest/user/quickstart/It's annoying as the error message is a complete red herring.
- Ahmed-Elfeel8 months agoSuper User
Ok mark your answer/replys as a solution to help other
This was usfel thanks for sharing☺️❤️