File Upload Through GraphQL API - Processing Error

File Upload Through GraphQL API - Processing Error

jacopol
Tourist
18 0 3

Hi everyone!

I'm setting up a Shopify store to sell software online. The purchased software comes with an activation key/license.

Upon order payment, a Shopify webhook is sent to an AWS Lambda that takes care of:  

  1. Gathering the needed customer and order information from the webhook’s payload.
  2. Creating the .xml file containing the activation key.
  3. Uploading the file to Shopify files. 
  4. Attaching the uploaded file to a customer list-of-files metafield for it to be displayed in the customer account page. 

 

I’m doing some tests to implement point 3 by simply trying to upload a local file to Shopify using the GraphQL API, but I’m having some issues.

To upload the file I’m using 2 calls to the GraphQL Admin API: 

  1. stagedUploadsCreate() mutation call to upload the file.
  2. fileCreate() mutation to create the file asset using the link provided by the staged upload. 


Both calls go through correctly and I don’t get any error message in my python script, however, if I keep checked the file page in the Shopify Admin, the file seems to take forever to upload (it’s a 750 bytes xml…), as advised by a pop-up I get in the bottom right corner of the screen, and then the upload promptly fails with a very generic “FileName.xml Processing error” message, with the pop-up replacing the previous one

Any idea of what’s going on?

The following are the specific mutations I’m calling:

 

 

mutation stagedUploadsCreate($input: [StagedUploadInput!]!) {
  stagedUploadsCreate(input: $input) {
    stagedTargets {
      url
      resourceUrl
      parameters {
        name
        value
      }
    }
    userErrors {
      field
      message
    }
  }
}


variables = {
  "input": 
    {
      "filename": "Prova.xml",
      "fileSize": "1000",
      "httpMethod": "POST",
      "mimeType": "application/xml",
      "resource": "FILE"
    }
}

 

 

 
 

 

 

mutation fileCreate($files: [FileCreateInput!]!) {
  fileCreate(files: $files) {
    files {
      alt
      createdAt
    }
    userErrors {
      field
      message
    }
  }
}

variables = {
  "files": [
    {
      "alt": "License file",
      "contentType": "FILE",
      "originalSource": resource_url
    }
  ]
}

 

 

 

With resource_url extracted by the response from the first mutation.

Thanks! 

Ciao!
Replies 0 (0)