4

I have an issue trying to download files attached to Podio items:

podio.request('get', '/file/{file_id}/raw').then(console.log);

The above program displays:

{}

This is a JSON stringified empty object (instead of raw file content).

Details:

  • The above file can be accessed with its URL when logged in
  • The above code is run after proper authentication
  • It actually works when using a file_id from an image field of the item, but not from a file attachment (pdf files in my case).
  • When using API endpoint /item/app/{app_id}/filter to get a list of items, the property file_count is set, but not files. I have to request /item/{item_id} individually to get the files property included in the response, not sure why.

Question: Do you know what is the issue, and how I can download raw attached files?

EDIT: aditionnal info

If I request a single file metadata using the folowing command:

podio.request('get', '/file/1234').then(console.log);

I get a file JSON object which includes many fields, but not the file content :

{
  ...
  link: 'https://files.podio.com/1234',
  file_id: 1234,
  ...
}

As stated in my comment to @stengaard, if I try to request the API for the above link, here is the response :

{ [PodioNotFoundError: [object Object]]
  message:
   { error_parameters: {},
     error_detail: null,
     error_propagate: false,
     request:
      { url: 'http://api.podio.com/1234',
        query_string: '',
        method: 'GET' },
     error_description: 'No matching operation could be found. The path \'/1234\' was not found..',
     error: 'not_found' },
  status: 404,
  url: 'https://api.podio.com:443/1234',
  name: 'PodioNotFoundError' }
Pandaiolo
  • 11,165
  • 5
  • 38
  • 70

2 Answers2

6

To use the GET /file/{file_id}/raw endpoint you need an API key with elevated trust levels.

Instead use GET /file/{file_id} endpoint. That contains a link attribute (a URL) you should follow to get the file content.

The link attribute will look like: https://files.podio.com/{file_id}. To fetch the file do https://files.podio.com/{file_id}?oauth_token={oauth_token}. Where the OAuth token is the same as the one used to GET /file/{file_id}. If you know the file ID (e.g. from a GET /item/{item_id} you can skip the GET /file/{file_id} and contact files.podio.com directly. (Note: You can also set the Authorization: OAuth2 {oauth_token} header in your HTTP request if you don't like passing the auth token in a URL paramter.)

For an example on how to use it see https://github.com/podio/podio-js/blob/master/lib/general.js#L11

Typically in the JS client, if you use podio as your Podio API object, the OAuth token would be located there:

podio.authObject.accessToken

So to get the raw content of the file in nodejs:

var url = 'https://files.podio.com/'+file_id+'?oauth_token='+podio.authObject.accessToken;
request(url, function (err, fileContent) {
    // use fileContent here, write to a file, etc...
});
Pandaiolo
  • 11,165
  • 5
  • 38
  • 70
  • This does not work: the link cannot be called by a program, it needs human interaction for authentication. I need a way to download the file programmatically, hence the use of the API. As stated in my question, `/file/{fileId}/raw` works for image fields - which are also files - but not files attached to items. – Pandaiolo Jul 12 '16 at 12:47
  • See my updated answer about the JSON answer when requesting the `link` via the API – Pandaiolo Jul 25 '16 at 15:13
  • Sorry - you need to supply your `oauth_token` as a parameter. I'll update my answer. – Brian Stengaard - Podio Jul 26 '16 at 18:57
  • 2
    Thanks for the details, it works! When using `podio` as podio API object, the OAuth token is located there: `podio.authObject.accessToken` – Pandaiolo Jul 27 '16 at 11:13
0

It seems your request has an error. please try the below method and get raw file content from its response.

podio.request('get', '/file/{file_id}').then(console.log);

FYI, we couldn't get the files by filtering the items. we need to request /item/{item_id} individually to get the files property as you said.

Mûhámmàd Yäsår K
  • 1,492
  • 11
  • 24
  • Hi @Mûhámmàd, thanks for your answer. It does not work. I have updated my answer to show why. (the request you propose gets the file metadata, not the actual file content) – Pandaiolo Jul 25 '16 at 15:12