0

I'm following the API referenced here but nothing I am doing seems to be working. Below is my code and the error message I am getting

import requests
access_token = 'MY_ACCESS_TOKEN'

headers = {
    "content-type": "application/x-www-form-urlencoded",
    "Authorization": f"Bearer {access_token}",
}
url = "https://youtubereporting.googleapis.com/v1/jobs"
data = {
    "reportTypeId": "channel_basic_a2",
    "name": "my_job",
}
response = requests.post(url, headers=headers, data=data)
# Also tried
# response = requests.post(url, headers=headers, params=data)
assert response.status_code == 200, f"{response.status_code} {response.text}"
print(response.text)

Below is the error message I am getting

"error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"reportTypeId\": Cannot bind query parameter. Field 'reportTypeId' could not be found in request message.\nInvalid JSON payload received. Unknown name \"name\": Cannot bind query parameter. Field 'name' could not be found in request message.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "description": "Invalid JSON payload received. Unknown name \"reportTypeId\": Cannot bind query parameter. Field 'reportTypeId' could not be found in request message."
          },
          {
            "description": "Invalid JSON payload received. Unknown name \"name\": Cannot bind query parameter. Field 'name' could not be found in request message."
          }
        ]
      }
    ]
  }
3
  • Did you try to retrieve the reportTypeId in your report types list? Try to get request in your reportTypes to get the valid reportTypeId developers.google.com/youtube/reporting/v1/reference/rest/v1/… Commented Mar 21 at 18:48
  • @JasonV.Castellano yes I tried that and it worked. channel_basic_a2 is one of the reportTypeIds returned Commented Mar 21 at 20:17
  • There is somthing wrong in sending your request, Just check your content-type": "application/x-www-form-urlencoded" just try application/json because you are sending a json object in your server. There is an error: Field 'name' could not be found in request message. it means the name in your attributes cannot be found. Commented Mar 21 at 20:30

1 Answer 1

0

I think, there's something wrong with your request. Check your header "content-type" is set to "application/x-www-form-urlencoded" , but since you're sending a JSON object, try to switch it to application/json. As you can see , the error Cannot bind query parameter. Field 'name' could not be found in request message.", attribute is missing , it means there something wrong in sending request in your server.

Sign up to request clarification or add additional context in comments.

Comments

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.