How to post a story with a file

In order to add a file to a story you will first need to upload the file and get a token that you will have to reference to the story.

Get a file token

You first need to upload the file and get a token.

To get an upload token for a file, you must post it to the following endpoint:

curl \
--data-raw @./version1.pdf \
-H 'Authorization: Bearer kp-oauth2-AXLmAPDkbuEGt7oWaza60N5cFw9i' \
-H 'Content-Type: application/octet-stream' \
-H 'Content-Disposition: attachment; filename=version1.pdf' \
https://mycompany.elium.com/api/upload/file

It gives a JSON response with the token identifying that file:

response
{
"file": {
"token": ".eJw...xMWA"
//...
},
"success": true
}

Create a story referencing the received token

In the variables, you need to reference the file token in the variables in addition of a uuid (version 1) that you would have generated on your side.

graphql
mutation storyPostExample($input: StoryPostInput!) {
storyPost(input: $input) {
story {
slug
version {
title
mainAsset {
__typename
... on FileAsset {
downloadUrl
embed
mimetype
filesize
}
}
}
}
}
}
variables
{
"input": {
"assets": [
{
"type": "FILE",
"file": ".eJw...xMWA",
"uuid": "GENERATED_UUID"
}
],
"publish": true,
"spaceId": "SPACE_ID",
"mainAsset": "GENERATED_UUID",
"title": "My story with a file as main asset"
}
}

Expected return:

response
{
"data": {
"storyPost": {
"story": {
"slug": 278,
"version": {
"mainAsset": {
"__typename": "FileAsset",
"downloadUrl": "https://mycompany.elium.com/api/story/asset/278/download/95/untitled",
"embed": {
"cover_url": "https://mycompany.elium.com/api/story/asset/278/thumbnail/95?fallback=false&tclass=cover",
"digest": "9bfd53912a4364ad1ff99e45a70860eda0f64ae13f04d568d24e0d45f67b0c6a",
"filename": "untitled",
"filesize": 1191622,
"image_url": "https://mycompany.elium.com/api/story/asset/278/thumbnail/95?fallback=false&tclass=xxlarge",
"mimetype": "application/pdf",
"thumbnail_fallback_url": "https://mycompany.elium.com/api/story/asset/278/thumbnail/95?fallback=false&tclass=xxlarge",
"thumbnail_url": "https://mycompany.elium.com/api/story/asset/278/thumbnail/95?fallback=false&tclass=xxlarge",
"url": "https://mycompany.elium.com/api/story/asset/278/download/95/untitled"
},
"mimetype": "application/pdf",
"filesize": 1192
},
"title": "My story with a file as main asset"
}
}
}
}
}

Was this page helpful?