1

Is it possible to upload a new asset via some POST request to craft's API? Or maybe through a graphql mutation?

I noticed in the public schema there is the option for Creating assets within a volume.

Kind regards

1 Answer 1

1

An Asset mutation looks like this:

mutation MyMutation(
  $filename: String = "", 
  $url: String = "", 
  $title: String = ""
) {
  save_assets_Asset(
    _file: {filename: $filename, url: $url}
    title: $title
  ) {
    id
    title
  }
}

With the following variables:

{
  "filename": "image.jpg",
  "url": "https://domain.com/image.jpg",
  "title": "Asset from GQL"
}

You would need to change save_assets_Asset to match your own volume, of course (save_assets_VolumeName).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.