Third Light Developer Exchange

Code and templating community forum for developers and software integrators

You are not logged in.

Announcement

If you wish to join the Developer Exchange, please contact your account manager - this is to avoid unnecessary spam in the forums. Many thanks for your understanding.

#1 2022-02-01 17:50:01

mmcs
Member
Registered: 2022-01-31
Posts: 18

Creating folders in a space

Hi all,

Is it possible to create a folder in a space or sub-space rather than in a folder using the REST API?

I've been looking on the REST API documentation but couldn't find what I'm looking for.
The only option that I found was: POST /rest/v1/content/{folderId}/folders - but not sure if there's a folder id of the root of a space.

Thanks,
Marcelo

Offline

#2 2022-02-03 16:57:27

kim
Third Light Staff
Registered: 2021-09-23
Posts: 2

Re: Creating folders in a space

Hi Marcelo,

Is is possible to do that! You can get the backing folder ID of a space by using the `GET /rest/v1/contexts/{contextId}` endpoint.

The returned JSON should contain a field "backingFolderId" which you can then use in the endpoint you mentioned above to create a folder :)

Kim

Offline

#3 2022-02-04 10:36:02

mmcs
Member
Registered: 2022-01-31
Posts: 18

Re: Creating folders in a space

Hi Kim,

Just tested it and seems that it has worked, thanks!

One additional question, I'm trying to work on a space with 3 different sub-spaces, one for each environment for our project. On each sub-space, I'm trying to link it's own API keys to each of our environment.
I was able to create a folder on the sub space but when trying to create an upload (/rest/v1/uploads) I'm now getting a permission error:

403 Forbidden: "{"code":7,"message":"ACTION_NOT_PERMITTED","details":[]}"

Any ideas of what I'm missing here?
Thanks,
Marcelo

Offline

#4 2022-02-10 11:09:03

ben
Third Light Staff
From: Third Light
Registered: 2013-06-06
Posts: 79

Re: Creating folders in a space

Hi Marcelo,
I guess the question is: do you definitely have any rights on the folder you're uploading to, and if so do the rights include upload rights. The default configuration for Spaces would allow this but it might be that the Space (and associated Role configuration) prevents this.

So I would do this:
Check you can get details of the Folder with /rest/v1/content/{itemId}
Assuming yes, check the rights you have on that folder with /rest/v1/content/{folderId}/rights
If that comes back indicating upload rights are present, retry the upload and if that still fails, please could you send over more details of the the transaction.

If one of the previous steps fails, then we'd need to examine the setup in the Chorus site itself which I can help with here if you need.

Cheers, Ben

Offline

#5 2022-02-10 11:38:57

mmcs
Member
Registered: 2022-01-31
Posts: 18

Re: Creating folders in a space

Hi Ben,

Ok, so just created a new folder on the space that I'm using to test your steps. Results:

1. Yes, I can view the details via /rest/v1/content/{itemId}

2. Looks like I have the upload permissions on that folder as well. Response from the API:
{
    "createDerivative": true,
    "delete": true,
    "download": true,
    "edit": true,
    "publish": true,
    "share": true,
    "upload": true,
    "view": true,
    "viewAttachments": true
}

3. Tried to create the upload using /rest/v1/uploads, details below:
Request:
Headers: Same used to create the folder and check the rights on it
Payload:
{
  "destinationFolderId": "Same folder GUID used to check the rights from item #2"
}

Response:
Status code: 403
{
    "code": 7,
    "message": "ACTION_NOT_PERMITTED",
    "details": []
}

Any ideias?

Thanks,
Marcelo

Offline

#6 2022-02-10 12:02:26

ben
Third Light Staff
From: Third Light
Registered: 2013-06-06
Posts: 79

Re: Creating folders in a space

> Any ideias?

Not immediately. I will investigate and get back to you.
Ben

Offline

#7 2022-02-10 12:59:00

ben
Third Light Staff
From: Third Light
Registered: 2013-06-06
Posts: 79

Re: Creating folders in a space

Hi again,
OK well investigation this end has revealed that the permissions request (i.e.  /rest/v1/content/{folderId}/rights) is buggy and seems to return true for everything even when permissions have not been granted.

We will of course fully investigate and fix that, but in the mean time you could check permissions by using the Chorus UI and looking at the permissions actually configured. You'd need to login as a manager of the Space in question, and start by looking at the permissions configured on the Roles for that Space.

Cheers
Ben

Offline

#8 2022-02-10 14:16:03

mmcs
Member
Registered: 2022-01-31
Posts: 18

Re: Creating folders in a space

Hi Ben,

For the quick reply.

Sorry, how do I check the permissions via the UI interface?
What've done is click on the space -> Manage Space -> People. There's only my user as Manager. Checking the permissions for the managers, looks like it has access to everything (all checkboxes selected, including the Upload / Add item.

Is this the correct place to look at?
How do I check the permissions for the API KEY that I created?

Thanks,
Marcelo

Offline

#9 2022-02-10 14:17:11

mmcs
Member
Registered: 2022-01-31
Posts: 18

Re: Creating folders in a space

*Thanks for the quick reply

Offline

#10 2022-02-10 15:14:47

ben
Third Light Staff
From: Third Light
Registered: 2013-06-06
Posts: 79

Re: Creating folders in a space

Hi again,
2 things:

1. I forgot you were using Space API Keys. You can't see these permissions directly in the UI but Space Keys inhabit a special role slightly above Managers and should have access to everything in the space.
2. I've found a bug with Space API Key usage which means uploads are blocked - this (finally) is the crux of your problem.

The fix is straight forward. If you let me know which site you are working against I can get a fix applied very quickly.

Sorry about the issues here,
Ben

Offline

#11 2022-02-10 15:42:40

mmcs
Member
Registered: 2022-01-31
Posts: 18

Re: Creating folders in a space

Hi Ben,

Ok, understood!
The Thirdlight instance that we've been working is under https://assets.creativescotland.com/.
Is that what you need?

Thanks!
Marcelo

Offline

#12 2022-02-10 15:54:39

ben
Third Light Staff
From: Third Light
Registered: 2013-06-06
Posts: 79

Re: Creating folders in a space

Yep that's enough. Fix applied. Please let me know how you get on.
Ben

Offline

#13 2022-02-10 17:06:00

mmcs
Member
Registered: 2022-01-31
Posts: 18

Re: Creating folders in a space

Hi Ben,

Looks like I'm now able to create the upload and add files to it.
But for some reason I'm not getting an error when trying to finish the upload via /rest/v1/uploads/{uploadId}/finish
Response:
Status code 400
"{"code":9,"message":"UPLOAD_NOT_FOUND","details":[]}"

Any ideas?

Thanks,
Marcelo

Offline

#14 2022-02-11 14:40:19

ben
Third Light Staff
From: Third Light
Registered: 2013-06-06
Posts: 79

Re: Creating folders in a space

Hi Marcelo,
I'm afraid that was another bug with Space API Keys. Now patched.
Ben

Offline

#15 2022-02-11 17:53:22

mmcs
Member
Registered: 2022-01-31
Posts: 18

Re: Creating folders in a space

Hi Ben,

Ok, that seems to be working. Thanks!
But I'm afraid that I'm now getting another error on the following request: /rest/v1/files/{fileId}/directUrl

Response:
403 Forbidden: "{"code":7,"message":"ACTION_NOT_PERMITTED","details":[]}"

Any thoughts?
Marcelo

Offline

#16 2022-02-15 15:27:13

steve
Third Light Staff
Registered: 2013-06-06
Posts: 105

Re: Creating folders in a space

Hi Marcelo,

Its possible this has a similar cause to the earlier issue. Do you find that it works with a site API key but not a space level one?

Best Regards,
Steve

Offline

#17 2022-02-15 15:29:27

mmcs
Member
Registered: 2022-01-31
Posts: 18

Re: Creating folders in a space

Hi Steve,

Correct, that same request works fine with the site level API key.

Regards,
Marcelo

Offline

#18 2022-02-15 18:26:47

steve
Third Light Staff
Registered: 2013-06-06
Posts: 105

Re: Creating folders in a space

Hi Marcelo,

Thanks for confirming, we have another change to make it seems so will let you know when it is ready

Best Regards,
Steve

Offline

#19 2022-02-16 15:06:46

ben
Third Light Staff
From: Third Light
Registered: 2013-06-06
Posts: 79

Re: Creating folders in a space

Hi again Marcelo - just to say that the directUrl endpoint has been patched to work with Space keys.
Ben

Offline

#20 2022-02-16 16:53:04

mmcs
Member
Registered: 2022-01-31
Posts: 18

Re: Creating folders in a space

Hi Ben,

Thanks, that seems to be working now.
Unfortunately I'm having an issue trying to delete an image now with /content/{itemId}

Response: 500 Internal Server Error: "{"code":2,"message":"INTERNAL_ERROR (code: f84090554d9a45698fd3c85731cc6256)","details":[]}"

Sorry for being a pain here.
Thanks,
Marcelo

Offline

#21 2022-02-16 18:49:27

ben
Third Light Staff
From: Third Light
Registered: 2013-06-06
Posts: 79

Re: Creating folders in a space

You're not being a pain, don't worry about that!

This one, at least, is slightly more involved than some incorrect permissions logic with Space API Keys. The issue is that a delete call would normally put a file in the user's recycle bin. But when logged in using a Space API Key, you don't have a recycle bin because you're not a real user. So currently there's no quick fix. How important is the delete call to your integration?

Ben

Offline

#22 2022-02-17 10:02:14

mmcs
Member
Registered: 2022-01-31
Posts: 18

Re: Creating folders in a space

Hi Ben,

Unfortunately we need to be able to delete images on this integration. Is there any possible solution / workaround?
Would that mean that when deleting, I should be using a site api key instead then of the space api key?

Thanks,
Marcelo

Offline

#23 2022-02-17 14:09:13

steve
Third Light Staff
Registered: 2013-06-06
Posts: 105

Re: Creating folders in a space

Hi Marcelo,

A potential workaround would be to consider creating a 'service account' user through the UI and make them a member of the space and then use the API to login as the service account and delete files that way.

Best Regards,
Steve

Offline

#24 2022-02-18 09:16:57

mmcs
Member
Registered: 2022-01-31
Posts: 18

Re: Creating folders in a space

Hi Steve,

Ok, understood. We will follow that suggestion for deletion then. Thanks.
Got a new error, but now when updating metadata using the space API keys:

Request:
/content/{itemId}/metadata/{tagName}
Response:
400 Bad Request: "{"code":9,"message":"ACTION_NOT_PERMITTED","details":[]}"

That same request seems fine using the site level API key.

Any ideas?
Marcelo

Offline

#25 2022-02-21 16:41:02

steve
Third Light Staff
Registered: 2013-06-06
Posts: 105

Re: Creating folders in a space

Hi Marcelo,

Thanks for testing with both Site and Space API keys. It seems that we may have a general problem with the latter and may need to do a sweep of this combination. Please bear with us while this is reviewed

Best Regards,
Steve

Offline

Board footer