File Upload API Reference
This guide covers usage of the GraphQL API to create and modify assets in your asset library. Scope uses the Apollo file upload protocol to upload assets using multi-part GQL requests.
There are two file upload operations:
createAsset - for uploading a new asset to your library
updateAsset - for modifying existing assets in your library
Both require that you configure a multi-part GraphQL request using an HTTP or GQL Client. The examples in this guide use Postman to configure upload parameters.
We’ll cover three use cases:
Prerequisites
Valid API Token: See Getting API Tokens to generate an API token
OR Valid Bearer Token
API endpoint:
<https://cms.scopear.com/api/v3/graphql/?permalink={{company_permalink}}>
High Level Flow Diagram
This is the high-level flow diagram for the operation of uploading files to the WorkLink asset libraries.
Note that the diagram above assumes that you are obtaining the token from an IDP system for an SSO user. Other options for authentication include:
The token being used is an API token provided by WorkLink in which case steps 1 and 2 are skipped and the token is provided to the PLM directly. See here for more details.
The token is being provided by WorkLink for a non-SSO user. In this case steps 1 and 2 would go to WorkLink for authentication rather than an IDP.
Uploading a file as the author
To recreate an Apollo file upload request in Postman, you can follow these steps to mimic how Apollo uploads files via a GraphQL multipart request.
Note: The request template provided here generalizes to all three use cases with slight modifications.
What you need
A valid user token
An HTTP client - The steps shown below describe using Postman.
Procedure
Open Postman and create a new collection
Click on the collection, go to the variables tab, and add the following variables and set their values
company_permalink
username
password
The values should be your username and password, and the company permalink can be found on your company profile page on the CMS.
Make sure to save the collection after you are done creating those variables.
Within new collection create a new request and set it to an HTTP
POST
request type.Click the ‘+' icon in the top right to create a new request, and choose the 'POST’ option from the dropdown menu on the left. You can enter the GQL endpoint in the URL field.Enter the GQL endpoint URL:
https://cms.scopear.com/api/v3/graphql/?permalink={{company_permalink}}
in the URL field.Go to the
Body
tab:Select the
form-data
option.
Note: You'll need to add multiple key-value pairs here, similar to how a GraphQL multipart request is structured.
Add the
operations
field:In the key field, enter
operations
.Set the type to
Text
.In the value field, you need to input a JSON object describing the GraphQL mutation and variables.
Example of JSON Object to specify variables:
"variables": { "input": { "file": null } }
Example of completed JSON Object with query and variables:
{ "query": "mutation createAsset($input: CreateAssetMutationInput!){ createAsset(input: $input) { asset { id databaseId name type createdBy { databaseId name } owner { ...on User { id databaseId name } ...on Organization { id databaseId name } } originalFile { fileUrl } }, errors { fullMessage, message, path, type } } }", "variables": { "input": { "file": null } } }
Note: By default, the "createdById" argument will be set to the current user's ID. The "name" arg will be set to the file name. Folder will be set to null, meaning the asset will be added to the root of the Personal Library.
Add the
map
field:In the key field, enter
map
.Set the type to
Text
.The value should be a JSON object that maps the file to the variable in the
operations
object. Example:{ "0": ["variables.input.file"] }
This indicates that the first file (index 0
) will be assigned to the file
variable in the mutation.
Add the file itself:
In the next key field, enter
0
(this corresponds to the key specified in themap
field).Set the type to
File
.Upload the file you want to send.
Set the request headers:
Postman automatically detects this is a multipart request. However, you should ensure that the header for
Content-Type
is set tomultipart/form-data
.Add the
Authorization
header with your access token. Example:Authorization: Token token=eyJhbGciOiJIUzI1NiJ9.eyJkYXRhIjp7InVzZXJfaWQiOjY1NzA3LCJkZXZpY2VfaWQiOjIwMzM3LCJjb21wYW55X2RhdGFiYXNlX2lkIjoxLCJjb21wYW55X2dxbF9pZCI6IndlaUllck1tTGh1T1RSOTFXVDRhMmFIazRpaUpXT1I5MUpsVWM4Tl9IRE9wSE41Ym1HWk5na2lrbHg5dXdFamwiLCJjb21wYW55X3Blcm1hbGluayI6InNjb3BlIn0sImV4cCI6MTcyODc2MDM3NywianRpIjoiMGRhMDgwMTcyMWZiNjI4MzA5ODVhNDZkY2FkNWM2Y2RlNmRhMzRhNTFiNmI4NTg1OTdiZWY2MjliNjBjOTNmNyIsImlhdCI6MTcyNjE2ODM3N30.TePbk7-MkEtIBk1npnV7DEPmtQ9HHvnwm5pSPhTK8Wk
If this doesn’t work, you can try using a bearer token instead:
Click on the
Headers
tab.Add a field under
Key
titledAuthorization
.In the
Value
field, enter your bearer token:Bearer <yourtokenstring>
Send the request:
Now, you can send the request, and it will mimic an Apollo GraphQL file upload.
Sample Response:
Uploading a file on behalf of an author
An asset can be uploaded on behalf of an author to either their personal asset library, or to the company assets library, while assigning ownership to the specified author. This can be accomplished using the credentials of an admin user.
Note: The procedure is identical to uploading a new asset with the exception of the variables entered in step 4, and the token entered in step 7. See Uploading a file as the author to read the steps in detail.
What you need
User credentials for a user with admin access
Sample Variables
name: Defaults to the file name
createdById: Refers to the library the asset will belong to. If passing the author ID, the asset will be part of their Personal Assets list. If passing the Organization ID, the asset will end up listing under 'Company Assets'.
file: populated by multi-part Apollo Upload.
folderId: optional - In case you need to upload the asset directly into a folder. The folder asset needs to belong to the same ownerId.
Creating a folder
Folders are unique types of assets that don’t require a file to be uploaded. You can simply specify a name and, optionally, a parent folder if you want to create a folder tree.
Note: Once again the procedure is nearly identical to uploading a new asset with the exception of the variables entered in step 4. See Uploading a file as the author to read the steps in detail.
What you need
A valid admin or user token
Optional: A parent folder ID
Hint: How to Browse the Current List of Folders in Your Asset Library
If you need to find the name and gql-id of a parent folder in your asset library to upload your new folder to, you can use a GraphQL query like this one:
If you’d prefer to list the current company’s folders, you can use a GraphQL query like this:
Note: In both cases, you can browse assets in general rather than folders by removing the “types” filter from your query.
Sample Variables
type: Mandatory when creating folders.
folderId: Optional. When left null, the new folder is in the root directory.
ownerId: Optional. This is the root library the folder will belong to, which is the author ID by default. By passing the author ID, the folder will be part of their Personal Assets list and by passing the Organization ID, the folder will end up listing under ‘Company Assets’. Nested folders need to belong to the same ownerId as the parent.