Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedJoin us at the 2025 Microsoft Fabric Community Conference. March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for $400 discount. Register now
I am running a microsoft fabric notebook on demand from my c# code , via fabcric POST API call. My note book requires 3 parameters that I need to pass as a Json body to this POST API. Below is the sample request.
{
"FirstName":"John",
"LastName":"Smith",
"LoginDate":"2/7/2025"
}
Now in notebook cell, how can I get all these 3 fields and print it. Looking for something like below -
Hi @v-rajethakur,
Thank you for posting your quey in Microsoft fabric community forum.
I wanted to share a solution for reading parameters from the request body in a Microsoft Fabric notebook. I reproduced the scenario you described and used the following code to successfully extract and print the parameters:
Code:
import json
json_body = '''
{
"FirstName":"John",
"LastName":"Smith",
"LoginDate":"2/7/2025"
}
'''
params = json.loads(json_body)
fName = params.get('FirstName')
lName = params.get('LastName')
date = params.get('LoginDate')
print(f"First Name: {fName}")
print(f"Last Name: {lName}")
print(f"Login Date: {date}")
Could you please confirm if this matches your expected output? Kindly refer to the screenshot below:
This approach simulates receiving a JSON body from an API request. Remember to replace the simulated json_body with the actual method you use to read the request body in your notebook.
Please do not hesitate to reach out if you have any further questions. If this information is helpful, kindly accept it as a solution and consider giving a "Kudos" so other members can easily find it.
Thank you.
Hi @v-ssriganesh , many thanks for your response. I am unable to get desired output with this approach. Could you please provide more info on how to read the request body. Below is the screenshot - from my notebook. And I think the second cell of defining request_body is not correct. How should I read the actual input coming from request body.
My sample request body is -
{
"FirstName": "John",
"LastName": "Smith",
"LoginDate": "1/1/2021"
}
I can change my request body as well if it helps in getting the desired output.
Hi @v-rajethakur,
Thanks for your response and the screenshot! It looks like the issue might be related to how the request body is captured in your notebook. To read the actual request body in your Microsoft Fabric notebook, you should use the parameters feature instead of defining a variable manually.
Here’s a revised approach that demonstrates how to correctly capture and use the parameters passed from your C# API call:
Updated Code:
import json
params = parameters
fName = params.get('FirstName')
lName = params.get('LastName')
loginDate = params.get('LoginDate')
print(f"First Name: {fName}")
print(f"Last Name: {lName}")
print(f"Login Date: {loginDate}")
If this helps, then please Accept it as a solution and dropping a "Kudos" so other members can find it more easily.
Hope this works for you!
Thank you.
Hi @v-ssriganesh , thanks for your answer. Now I am getting below error. Its unable to identify that parameters keyword. Is this an inbuild keyword ? After making the API call when I go and see the run history, I found below error -
Hi @v-rajethakur,
Thanks for your response and for sharing the error details. I understand the issue with parameters is not a built-in keyword in Fabric Notebooks. Instead, to correctly retrieve parameters passed from an API call, you should use mssparkutils.env.get().
Please modify your notebook to retrieve parameters dynamically:
CopyEdit
import mssparkutils
fName = mssparkutils.env.get("FirstName")
lName = mssparkutils.env.get("LastName")
loginDate = mssparkutils.env.get("LoginDate")
print(f"First Name: {fName}")
print(f"Last Name: {lName}")
print(f"Login Date: {loginDate}")
Let me know if you need further clarification! If this solution works, please mark it as Accepted and consider giving a Kudos so other community members can find it easily.
Thank you.
Hi @v-rajethakur,
Thanks for your patience! I see that you are getting an AttributeError while trying to retrieve the parameters. This happens because mssparkutils.env.get() does not exist in Fabric Notebooks. My apologies for the confusion.
In Microsoft Fabric Notebooks, you should use mssparkutils.notebook.run() with widgets to pass and retrieve parameters. Here’s the correct way to do it:
Please ensure your API request sends parameters correctly using jobParameters:
json
CopyEdit
{
"jobParameters": [
{
"name": "FirstName",
"value": "John"
},
{
"name": "LastName",
"value": "Smith"
},
{
"name": "LoginDate",
"value": "1/1/2021"
}
]
}
Modify your notebook code as follows:
python
CopyEdit
import mssparkutils
fName = mssparkutils.notebook.getArgument("FirstName", "Default_FirstName")
lName = mssparkutils.notebook.getArgument("LastName", "Default_LastName")
loginDate = mssparkutils.notebook.getArgument("LoginDate", "Default_LoginDate")
print(f"First Name: {fName}")
print(f"Last Name: {lName}")
print(f"Login Date: {loginDate}")
If this helps, then please Accept it as a solution and dropping a "Kudos" so other members can find it more easily.
Hope this works for you!
Thank you.
Hi @v-rajethakur,
We regret the inconvenience caused and acknowledges your requirements. Please consider raising a Microsoft support ticket. You can create a Microsoft support ticket using the link below:
https://learn.microsoft.com/en-us/power-bi/support/create-support-ticket
If this helps, then please Accept it as a solution and dropping a "Kudos" so other members can find it more easily.
Thank you.
Hi @v-rajethakur,
Could you please confirm if the issue has been resolved after raising a support case? If a solution has been found, it would be greatly appreciated if you could share your insights with the community. This would be helpful for other members who may encounter similar issues.
Thank you for your understanding and assistance.
Thanks for the response @nilendraFabric , I Tried the same approach but got Default values in the reponse, not the actual one passed from API request.
This is my notebook code part -
{
"FirstName": "John",
"LastName": "Smith",
"LoginDate": "2/7/2025"
}
And here is the output I got after passing above mentioned request body through POST API -
For triggering notebook I am using Job Scheduler - Run On Demand Item Job through learn.microsoft.com.
Hello @v-rajethakur
At the very start of your notebook, add a cell that defines your parameters with default values. Then, mark this cell as a parameters cell so that Microsoft Fabric automatically replaces the defaults with the values passed via your API call
# Parameters cell (toggle this cell as a parameter cell)
FirstName = "DefaultFirstName"
LastName = "DefaultLastName"
LoginDate = "DefaultLoginDate"
When your API call sends a JSON payload like this:
{
"FirstName": "John",
"LastName": "Smith",
"LoginDate": "2/7/2025"
}
Fabric will override the default values with the ones provided.
In next cell
print(f"First Name: {FirstName}")
print(f"Last Name: {LastName}")
print(f"Login Date: {LoginDate}")
Hope this helps.
Please accept the answer if this is helpful and give kudos
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Fabric update to learn about new features.
User | Count |
---|---|
34 | |
17 | |
3 | |
3 | |
2 |
User | Count |
---|---|
49 | |
16 | |
14 | |
10 | |
7 |