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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jaskiea
Frequent Visitor

Fabric API - Spark Library Upload Staging Library

Hi,

 

I am having trouble with this endpoint. I am able to authenticate but having no luck with sending up a .whl file.

 

I keep getting this error: 

 

"EnvironmentValidationFailed","message":"Invalid request. Provide a library with a valid format such as .jar, .py, .whl, .tar.gz, or environment.yml."

 

I am using python w/requests, I feel like it could be something simple with how I am sending the file or maybe with my headers?

 

Any help appreciated.

1 ACCEPTED SOLUTION

Hi Yang,

 

I was able to get it working using this:

headers = {
    'Authorization': f"Bearer {token}"
    #It worked with no other headers

}


url = 'https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/environments/{environment_id}/staging/libraries'
file_path = "file_path"

with open(file_path,'rb') as file:
        
    files = {'file':(os.path.basename(file_path),file)}
    response = requests.post(url,files=files,
                             headers = headers)
    
if response.status_code == 200:
    print(f'Success: {response.json}')
else:
    print(f'Failure: {response.status_code} {response.text}')

Thanks for your help!

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @jaskiea ,

 

Try this:

import requests

headers = {
'Authorization': f"Bearer {token}",
'Content-Type': 'multipart/form-data',
'Content-Length': str(os.path.getsize(file_path)) # Add Content-Length header
}

url = 'https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/environments/{environment_id}/staging/libraries'
file_path = "file_path"

with open(file_path, 'rb') as file:
files = {'file': (os.path.basename(file_path), file)} # Add filename
response = requests.post(url, files=files, headers=headers)

if response.status_code == 200:
print(f'Success: {response.json()}')
else:
print(f'Failure: {response.status_code} {response.text}')

 

Add Content-Length to the original code to specify the file size, added filename.

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Hi Yang,

 

I was able to get it working using this:

headers = {
    'Authorization': f"Bearer {token}"
    #It worked with no other headers

}


url = 'https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/environments/{environment_id}/staging/libraries'
file_path = "file_path"

with open(file_path,'rb') as file:
        
    files = {'file':(os.path.basename(file_path),file)}
    response = requests.post(url,files=files,
                             headers = headers)
    
if response.status_code == 200:
    print(f'Success: {response.json}')
else:
    print(f'Failure: {response.status_code} {response.text}')

Thanks for your help!

Anonymous
Not applicable

Hi @jaskiea ,

 

I am glad to hear that your problem has been resolved.

 

I am very thankful to you for sharing your solution which will be of great help to other users who are experiencing similar issues.

 

Could you please mark this helpful post as “Answered”?

 

Thank you for your cooperation!

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

jaskiea
Frequent Visitor

Hi

 

Thank you for your response.

 

Yes I made sure it was a legitamate whl file, I also tried a simple .py file and that failed the validation as well.

 

I am still wondering if there could be a simple issue with how I am sending the request. 

 

headers = {
    'Authorization': f"Bearer {token}"
    ,'Content-Type':'multipart/form-data'

}


url = 'https://api.fabric.microsoft.com/v1/workspaces/{workspace_id}/environments/{environment_id}/staging/libraries'
file_path = "file_path"

with open(file_path,'rb') as file:
        
    files = {'file':file}
    response = requests.post(url,files=files,
                             headers = headers)
    
if response.status_code == 200:
    print(f'Success: {response.json}')
else:
    print(f'Failure: {response.status_code} {response.text}')

Here's my code. I have tested other environment call and authentication works.

 

Thanks,

 

Adam 

Anonymous
Not applicable

Hi @jaskiea ,

 

The error message indicates that the request is invalid, please provide the file in the correct format.

 

I have the following suggestions:

  • Make sure that the uploaded file is indeed a .whl file and that it is not corrupted. The API supports .jar, .py, .whl, .tar.gz, or environment.yml formats.
  • The maximum allowed request size is 100MB. make sure your files do not exceed this limit.
  • Sometimes network problems can affect this, so please make sure you have a stable internet connection.

 

Here is an official document you can refer to that may help:

Spark Libraries - Upload Staging Library - REST API (Environment) | Microsoft Learn

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June FBC25 Carousel

Fabric Monthly Update - June 2025

Check out the June 2025 Fabric update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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