0

I am working on a Python script to automate file uploads and field updates to a Podio application. I am using the requests library to send HTTP requests to the Podio API.

I am able to authenticate successfully using client credentials and I can retrieve information and download files from Podio without any issues. However, when I try to upload a file or update a field in an item, I receive a 403 error stating:

"Authentication as None is not allowed for this method."

Here's the relevant part of my code for uploading a file:

import requests

def upload_file(file_path):
    url = "https://api.podio.com/file"
    headers = {"Authorization": f"Bearer {access_token}"}

    with open(file_path, 'rb') as f:
        files = {'source': f}
        response = requests.post(url, headers=headers, files=files)

    if response.status_code != 200:
        raise Exception(f"Error uploading file: {response.status_code}, {response.text}")

    return response.json()['file_id']

upload_file('path_to_your_file')

And for updating an item:

 def update_item(item_id, field_values):
    url = f"https://api.podio.com/item/{item_id}"
    headers = {"Authorization": f"Bearer {access_token}"}
    payload = {"fields": field_values}
    response = requests.put(url, headers=headers, json=payload)

    if response.status_code != 200:
        raise Exception(f"Error updating item: {response.status_code}, {response.text}")

    return response.json()['revision']

    update_item('your_item_id', {'your_field_key': [{'value': 'your_new_value'}]})`

For both of these functions, access_token is the access token obtained through the OAuth 2.0 client credentials grant flow, which works fine downloading files, or pulling values from fields within apps.

It seems like the access token is not being recognized when trying to upload a file or update an item, even though the same token works fine for retrieving information and downloading files.

I have checked and I have the necessary permissions in the Podio app to perform these operations manually through the Podio interface.

Any ideas on why these specific operations might be failing and what I could do to fix it?

I have tried also something simple, to update a text field, but have failed:

 # Prepare the data for updating the 'brt-3' field
data = {
    "fields": {
        "brt-3": [{"value": new_value}]
    }
}

# Send a PUT request to the Podio API to update the item with the new data
response = requests.put(
    f"https://api.podio.com/item/{item_id}",
    headers={"Authorization": f"Bearer {access_token}"},
    json=data,
)

# Check the response
if response.status_code != 200:
    raise Exception(f"Error updating item: {response.status_code}, {response.text}")

I have been getting these error messages:

Traceback (most recent call last):
  File "c:\Users\RC\Documents\Python_personal_scripts\Podio\sending policies\Update Podio.py", line 50, in <module>
    raise Exception(f"Error updating item: {response.status_code}, {response.text}")
Exception: Error updating item: 403, {"error":"forbidden","error_detail":null,"error_description":"Authentication as None is not allowed for this method","error_parameters":{},"error_propagate":false,"request":{"url":"http://api.podio.com/item/2416776158","method":"PUT","query_string":""}}
AC Lotusi
  • 1
  • 1
  • I just answered a similar question here: https://stackoverflow.com/questions/63405612/error-while-using-podio-api-file-upload-operation/77009239#77009239 – George Aug 30 '23 at 15:15

1 Answers1

0

Your Authorization header isn't the right format. Per the docs (https://developers.podio.com/authentication) you want it to be:

Authorization: OAuth2 **ACCESS_TOKEN**

You have Bearer instead of OAuth2.

Jake
  • 90
  • 1
  • 10