Forum Discussion
Creating SQL DB via REST API
- 1 year ago
Yeah, if you're able to list the databases in the workspace then the token is good. Assuming you are using the token here is for the same ID that works fine to create databases in the portal then it should work. If the api call runs successfully and the database is not visible in the workspace within 5 minutes then something is wrong - 5 minutes is an enternity and then some here.
Here is the link that shows How to create a Fabric and Power BI Support ticket - Power BI | Microsoft Learn.
Heh, that was an obvious question I didn't check 😊
The call to https://api.fabric.microsoft.com/v1/workspaces/<workspaceid>/items?type=SQLDatabase does return databases created in the workspace:
{
"value": [
{
"id": "REMOVED",
"type": "SQLDatabase",
"displayName": "TestDb",
"description": "",
"workspaceId": "REMOVED"
}
]
}I assume that's what you mean by $databases?
- dlevy1 year agoMicrosoft Employee
That works too! I usually just drop $databases from line 26 into the immediate window in ISE to see what I've got in the workspace - usually to make sure I'm in the right one. 🤣
Is TestDb the one you are creating via API or the one you did via the GUI? Removed means redacted, right...or is that API returning that?
- mikegoatly1 year agoFrequent Visitor
Got it - I'm using Postman to exercise the APIs. I did try the script at one point to see if there was something I was doing wrong, but got the same error from that.
Yes, REMOVED is REDACTED in this instance and the database returned there is one that I manually created in the Fabric UI.
If I check the GET API after using the POST to try to create a new database, it doesn't show up there.
- dlevy1 year agoMicrosoft Employee
For Postman you have to be careful with the bearer token. You can use the F12 developer tools in Edge to find the bearer token while logged into the Fabric portal or just grab it using that powershell snippet.
The powershell script was actually written because people were struggling to get all the tumblers to align with Postman. If the powershell script is not working then we are probably going to need to get a support case opened to have someone dig into the logs and see where it is short circuiting.