Forum Discussion
Creating SQL DB via REST API
Hi folks - this documentation suggests that creating a SQL Database in Fabric should be possible using the items REST API: Deploy a SQL database via REST API - Microsoft Fabric | Microsoft Learn
When I try to use the suggested REST endpoint to create a database, I get the following error:
{
"requestId": "a1bd0f7b-045d-4e3b-a54a-d9682ad3fe66",
"errorCode": "UnknownError",
"message": "An unexpected error occurred while processing the request"
}
{
"requestId": "2700f348-ec09-495c-98c8-f21a2235463e",
"errorCode": "ItemDisplayNameAlreadyInUse",
"message": "Requested 'ApiSqlDb' is already in use"
}
Answers to the obvious questions:
1. Have I tried different workspaces: yes
2. Is the SQL Database feature enabled for me in the admin portal: yes
3. Can I create a SQL Database in the workspace through the UI: yes
Has anyone managed to get SQL Databases programatically created using this REST call?
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.
8 Replies
- dlevyMicrosoft Employee
Hi mikegoatly - Sorry to hear things aren't going smoothly. Either scope will work - we just haven't converted this script to use the Fabric scope yet.
Are you able to see your other databases in the workspace when you look in $databases?
- mikegoatlyFrequent Visitor
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?
- dlevyMicrosoft 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?
- mikegoatlyFrequent 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.
- dlevyMicrosoft Employee
Hi mikegoatly - We published an update to the REST API example this week. Please give it a shot and let me know how it works for you. Here is the link: https://learn.microsoft.com/en-us/fabric/database/sql/deploy-rest-api