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
chetanhiwale
Helper III
Helper III

Issue with definition for Fabric event-stream API

I am trying to create Eventstream with defination using API
Code : 

defination = {
  "sources": [
    {
      "name": "xvxcv",
      "type": "CustomEndpoint",
      "properties": {}
    }
  ],
  "destinations": [],
  "streams": [
    {
      "name": "duplicateCheck-stream",
      "type": "DefaultStream",
      "properties": {},
      "inputNodes": [
        {
          "name": "xvxcv"
        }
      ]
    }
  ],
  "operators": [],
  "compatibilityLevel": "1.0"
}
 
import base64
import json
json_str = json.dumps(defination)
json_to_base64 = base64.b64encode(json_str.encode('utf-8'))
dd = json_to_base64.decode('utf-8')
print(dd)
def deploy(self, defination = None😞
       
        payload = {
            "displayName" : "ABCD",
            "definition": {
                "parts": [
                    {
                        "path": "eventstream.json",
                        "payload" : defination,
                        "payloadType": "InlineBase64"
                    }
                ]
            }
        }
        response = requests.post(
            f"https://api.fabric.microsoft.com/v1/workspaces/{getWorkspaceId(workspace_name)}/eventstreams/176be14e-7829-4234-aaa0-efa7e6e90c31/updateDefinition",
            headers = {"Authorization" : f"Bearer {Connection.getSPNToken()}" , "Content-type" : "application/json"},
            data = payload
        )
        print(response.status_code, response.json())
import requests
deploy(dd)

 Error :
400 {'requestId': 'd5404614-5aa6-4b18-b441-5c3b39187686', 'errorCode': 'InvalidInput', 'moreDetails': [{'errorCode': 'InvalidParameter', 'message': "Unexpected character encountered while parsing value: d. Path '', line 0, position 0."}], 'message': 'The request has an invalid input'}

Any idea, why its failing. 
P.S : I have not added the ids in this code. But even with ids for source, it is giving same error. I have first created the eventstream , committed to git and then used the same defination to create another eventstream. 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @chetanhiwale 
Thank you for reaching out microsoft fabric community forum.

The issue looks like it’s coming from how the request is being sent. In your code, when you're calling the requests.post() method, you're passing the payload dictionary directly using data=payload. But the data parameter expects a JSON string, not a raw Python dictionary.

To fix this, try converting the payload to a JSON string before sending it. Just update this line:

data = payload

to:
data = json.dumps(payload)

That should resolve the “unexpected character” error ("d" is from the dict string). Also, make sure your base64-encoded definition is valid and the Eventstream/workspace IDs are correct.

If this solution helps, please consider giving us Kudos and accepting it as the solution so that it may assist other members in the community
Thank you.

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi @chetanhiwale 

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

Thank you.

Anonymous
Not applicable

Hi @chetanhiwale
I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.
Thank you.

 

Anonymous
Not applicable

Hi @chetanhiwale 
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you.

Anonymous
Not applicable

Hi @chetanhiwale 
Thank you for reaching out microsoft fabric community forum.

The issue looks like it’s coming from how the request is being sent. In your code, when you're calling the requests.post() method, you're passing the payload dictionary directly using data=payload. But the data parameter expects a JSON string, not a raw Python dictionary.

To fix this, try converting the payload to a JSON string before sending it. Just update this line:

data = payload

to:
data = json.dumps(payload)

That should resolve the “unexpected character” error ("d" is from the dict string). Also, make sure your base64-encoded definition is valid and the Eventstream/workspace IDs are correct.

If this solution helps, please consider giving us Kudos and accepting it as the solution so that it may assist other members in the community
Thank you.

datacoffee
Super User
Super User

I really don't know if this is the real error - but the word "definition" in the first line has a misspelling.

 

Else I would look for the error where it says "d" in the error message. It can uspbe a good hint, even though JSON parsing often just gives the first character from an arbitrary place during the parsing...

 

I hope you find the error - if it is not the misspelling in the beginning 😊


If you find this reply to help with your problem, please consider hitting the accept button...
----------------
Blog: https://dcode.bi
KQL ref guide: https://aka.bi/kql
LinkedIn: https://aka.bi/follow

Hi @datacoffee , thanks for pointing it out. As far as I can see, it is only variable , so it should affect it code execution. Even after correct the word, the error still persists. No sure exactly why I am getting this error. 

I agree - the code looks good to me - I can't seem to find any error.

And yes - it is only a variable used in the "payload" definition. 

I'm sorry for not being able to help more in this matter...


If you find this reply to help with your problem, please consider hitting the accept button...
----------------
Blog: https://dcode.bi
KQL ref guide: https://aka.bi/kql
LinkedIn: https://aka.bi/follow

Helpful resources

Announcements
Fabric July 2025 Monthly Update Carousel

Fabric Monthly Update - July 2025

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

July 2025 community update carousel

Fabric Community Update - July 2025

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

Top Solution Authors