1

I am using the Podio API from a Drupal website (with the Podio PHP client). Using it several types of files (all that I allow from a custom webform) are being uploaded and attached to Podio items without any problems.

The only files that seem impossible to be uploaded are .msg files. On uploading a .msg file the following message is received:

PodioBadRequestError: PodioBadRequestError in Podio::request() 

Which doesn't help me a lot.

The .msg file also doesn't seem to be excluded here: https://developers.podio.com/doc/files

Is it at all possible to upload .msg files with the Podio API, and if so would anyone have an idea what I could be doing wrong?

Thanks in advance.

UPDATE

Some of the code I have used to post the items to Podio

PodioIncidentItem: this is the item that gets published to Podio

  /**
  * Post incident to Podio
  */
  public function postToPodio() {
    $podioConnection = new PodioAPIConnection();
    $podioConnection->setupAndAuthenticate();

    if(!$this->podio_link_available) {
      $this->incident_description = t('Ticket by: ' . $this->requested_by . '<br /><br />' . $this->incident_description);
      $this->requested_by = NULL;
    }

    $fields = new PodioItemFieldCollection(array(
      new PodioTextItemField(array(
        "external_id" => "title",
        "values" => $this->short_title,
      )),
      new PodioAppItemField(array(
        "external_id" => "username",
        "values" => array((int)$this->requested_by),
      )),
      new PodioAppItemField(array(
        "external_id" => "sdt-user",
        "values" => array((int)$this->sdt_user),
      )),
      new PodioCategoryItemField(array(
        "external_id" => "contactmethod",
        "values" => (int)$this->contactmethod,
      )),
      new PodioTextItemField(array(
        "external_id" => "text",
        "values" => $this->incident_description,
      )),
      new PodioAppItemField(array(
        "external_id" => "catalog-selection",
        "values" => array((int)$this->catalog_selection),
      )),
      new PodioCategoryItemField(array(
        "external_id" => "urgency",
        "values" => (int)$this->urgency,
      )),
      new PodioCategoryItemField(array(
        "external_id" => "impact",
        "values" => (int)$this->impact,
      )),
      new PodioCategoryItemField(array(
        "external_id" => "status",
        "values" => (int)$this->status,
      )),
      new PodioCategoryItemField(array(
        "external_id" => "source-ticket",
        "values" => (int)$this->source_ticket,
      )),
    ));

    $item = new PodioItem(array(
      'app' => new PodioApp((int)$this->config->get('podioapi.incidents_app_id')),
      'fields' => $fields
    ));

    // Save the new item
    $response = $item->save();

    // Add the uploaded files to the Podio item
    foreach($this->fids as $fid) {
      $file = File::load($fid);
      $file_name = $file->getFilename();
      $uri = $file->getFileUri();
      $base_url = file_create_url("public://");
      $uri_resolved = str_replace('public://', '', $uri);
      $url = $base_url . $uri_resolved;
      $upload_result = PodioFileExtended::uploadFromURL($url);
      $file_id = $upload_result->file_id;
      $attributes = array('ref_type' => 'item', 'ref_id' => $response->item_id);
      PodioFile::attach($file_id, $attributes);
    }

    return $response;
  }

PodioFileExtended: Extended version of the Podio PHP API PodioFile class, this class was extended to enable the upload from URL option

/**
 * @see https://developers.podio.com/doc/files
 */
class PodioFileExtended extends PodioObject {
  public function __construct($attributes = array()) {
    $this->property('file_id', 'integer', array('id' => true));
    $this->property('link', 'string');
    $this->property('perma_link', 'string');
    $this->property('thumbnail_link', 'string');
    $this->property('hosted_by', 'string');
    $this->property('name', 'string');
    $this->property('description', 'string');
    $this->property('mimetype', 'string');
    $this->property('size', 'integer');
    $this->property('context', 'hash');
    $this->property('created_on', 'datetime');
    $this->property('rights', 'array');

    $this->has_one('created_by', 'ByLine');
    $this->has_one('created_via', 'Via');
    $this->has_many('replaces', 'File');

    $this->init($attributes);
  }

  /**
   * @see https://developers.podio.com/doc/files/upload-file-1004361
   */
  public static function uploadFromURL($url) {
    return self::member(Podio::post("/file/from_url/", array('url' => $url)));
  }
}

UPDATE 2

Some more information we have discovered in the meanwhile

Drupal out of the box assigns the application/octet-stream MIME type to .msg files, which is a general MIME type for every custom file type that is not recognised. The MIME type should actually be application/vnd.ms-outlook.

The Podio API doesn't allow files with MIME type application/octet-stream (https://developers.podio.com/doc/files).

But after mapping the .msg files to the correct MIME type, Podio still won't allow it.

jonjacobs
  • 11
  • 5

2 Answers2

0

Upload file by url is internal method and that's why it may not work from any external calls.

Please use "Upload file" method https://developers.podio.com/doc/files/upload-file-1004361
You can find all supported file operations at: https://developers.podio.com/doc/files

Pavlo - Podio
  • 2,003
  • 2
  • 10
  • 19
0

For uploading a file you should use following method provided in the Podio php Client:

PodioFile::upload( $file_path, $file_name );

where $file_path is the path to the file & $file_name is the name of the file.

Note: Request expects the request body to be multipart/form-data

For more information refer here.

Thanks!

Prateek Gupta
  • 1,129
  • 1
  • 11
  • 24