Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setFiles #21

Open
vgavrilovikj opened this issue Jun 27, 2021 · 4 comments
Open

setFiles #21

vgavrilovikj opened this issue Jun 27, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@vgavrilovikj
Copy link

I can see in the Entities\Properties - Files is listed as property, however, setFiles() function is not present in the Page.php..

Is this something that can be added? Thank you :) @mechelon

@johguentner
Copy link
Member

Hi @vgavrilovikj,
thank you so much for the question!
Currently the notion api unfortunately does not allow you to directely download or upload files.
For file properties, only the pure file-names (no path or url) can be retrieved at the moment.

You can see this in the dev-description for the notion-api:
https://developers.notion.com/reference/page#files-property-values

To be sure, I also searched a bit, and also found a small stackoverflow-thread, which describes the current state:
https://stackoverflow.com/questions/67551832/notion-api-how-to-get-the-url-of-uploaded-files

Since the property can be retrieved in some way the property class Files::class exist, but cannot be set within the page with'setFiles'.

🎯 To avoid confusion, we'll plan to use a 'modifiable'-trade within property classes, to clarify, if a page property can be modified within page update and creation. This will be the case in version 0.5.0 or latest in 0.6.0 of laravel-notion-api.

As soon as the notion api gets updated in some way, we'll make sure to include the feature asap.
This includes setting/uploading files within pages
🔥😊

@johguentner johguentner added enhancement New feature or request blocked by dependency Future feature, which has to wait until the notion-api supports this feature labels Jun 27, 2021
@vgavrilovikj
Copy link
Author

Hey, @johguentner thank you so much for getting back on such short notice!

Cool, I wanted to use it so I can insert images (from URL) into Notion, but for the time being, I made it work by changing the Notion property to URL so I can insert the URL and when I need the image, I will just change the property type to File & media so I can view the image..

But totally as soon as Notion updates their API would be good to use the setFiles

@johguentner
Copy link
Member

For sure @vgavrilovikj!

Yeah, that seems like the best practice for now!
That's right... url-strings are also possible for images. I'll try in the next few days, if setting the files-property with url-strings works.

Of course! We'll make sure to attach the linked pull-request to this issue and write a short notice, as soon as it's out ✨.

@johguentner
Copy link
Member

johguentner commented Jul 18, 2021

Hi @vgavrilovikj,
just wanted to let you know, that it's currently not possible with the notion-api to set even urls within files-properties.

I implemented the following:

# retreive page with property "Files" as files-property
$page = \Notion::pages()->find($pageId);
$page->set("Files", Files::value([$imgurl]));
$page = \Notion::pages()->update($page);

# the patched/posted data the laravel-notion-api is generating is the following:
array:1 [
  "properties" => array:1 [
    "Files" => array:1 [
      "files" => array:1 [
        0 => array:1 [
          "name" => "<<the_inserted_url>>"
        ]
      ]
    ]
  ]
]

The notion-api accepts the patch-request, however the files-property "Files" is not updated at all.

We'll have an eye on the changelog of the notion-api (https://developers.notion.com/changelog)
and will support setting files, as soon as the notion-api allows it ✨.

@johguentner johguentner removed the blocked by dependency Future feature, which has to wait until the notion-api supports this feature label Sep 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants