Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
udione
Helper I
Helper I

Fabric rest Api trying to connect workspace with git repository

Hi,

 

I'm trying to connect my workspaces to git repository through fabric rest api in c#. I'm getting 400 BadRequest without any clue what is wrong with the request.

 

Here is my code:

HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
string baseUrl = "https://api.fabric.microsoft.com/v1/";
client.BaseAddress = new Uri(baseUrl);

var requestBody = new
{
gitProviderDetails = new
{
organizationName = "xxx",
projectName = "xxx",
gitProviderType = "AzureDevOps",
repositoryName = "xxx",
branchName = "main",
directoryName = "ProdPrimary"
}
};

// Convert the requestBody object to JSON
var json = JsonConvert.SerializeObject(requestBody);


var content = new StringContent(json, Encoding.UTF8, "application/json");

//json produced looks like this: {"gitProviderDetails":{"organizationName":"xxx","projectName":"xxx","gitProviderType":"AzureDevOps","repositoryName":"xxx","branchName":"main","directoryName":"ProdPrimary"}}

 

var gitResult = await client.PostAsync($"workspaces/{workspaceId}/git/connect", content);

 

Any idea what is wrong or where can I find any logs that would tell me what is wrong?

 

Thank you

8 REPLIES 8
lbendlin
Super User
Super User

what type of git repository is that?  Public, Private cloud, private on-prem ?

This is a private repository in our Azure DevOps Subscription. I can manually assigned it in the portal, but we will have multiple workspace per each client so need to automate that.

This may not be supported yet. Talk to your CSAM.

Do you know which configuration is supported then? This is most basic there can be.

public github.com seems to be the only reliable one at the moment.

I'd like to test my call against that to rule out any errors in my request. Do you know what would be the code for github in gitProviderType.

No, and it looks like that you are already using the default provider (AzureDevOps).  i have no experience with that.  Maybe raise a Pro ticket?

For anyone else having this issue, problem was with accesstoken, this needs to be a user token and not a service token so when fetching the token you need to use GetAccessTokenForUserAsync instead of GetAccessTokenForAppAsync 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Kudoed Authors