2

I need to write this HTTP request. I was able to get the token (from another HTTP request) and I saved on in a variable name "Token"

Can you please help me write this HTTP request in python? I am getting 404 and I am pretty sure the syntax is wrong.

Attaching a screenshot from Microsoft documentation.

enter image description here

the new error message:

Traceback (most recent call last):
  File "/Users/talcohen/opt/anaconda3/lib/python3.9/site-packages/requests/models.py", line 972, in json
    return complexjson.loads(self.text, **kwargs)
  File "/Users/talcohen/opt/anaconda3/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/Users/talcohen/opt/anaconda3/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Users/talcohen/opt/anaconda3/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/talcohen/Documents/ddd/PowerBI_REST_API/CreateProfile.py", line 15, in <module>
    data = requests.post(api_url, json=payload, headers=headers).json()
  File "/Users/talcohen/opt/anaconda3/lib/python3.9/site-packages/requests/models.py", line 976, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
(base) talcohen@Tals-Mac-mini PowerBI_REST_API % 

1 Answer 1

2

Looking at the API you should probably do:

import requests

token = "<YOUR TOKEN>"
api_url = "https://api.powerbi.com/v1.0/myorg/profiles"
headers = {"Authorization": f"Bearer {token}"}

payload = {"displayName": "My First Profile"}

data = requests.post(api_url, json=payload, headers=headers).json()
print(data)
Sign up to request clarification or add additional context in comments.

5 Comments

Hi! I tried it and got an error. I attached it on the original post
@Tal_87_il That means you haven't received Json response from the server (probable it is error message). Try print(requests.post(api_url, json=payload, headers=headers).text) and see where the error is.
No I am getting: raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
@Tal_87_il Don't use .json() method on response. Use print(requests.post(api_url, json=payload, headers=headers).text) instead.
I got the wrong token. after changing the token everything works :) thanks all!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.