Internal error on a stagedUploadsCreate Mutation

Hello,

When I try and use a staged upload mutation to upload a jsonl file, I get this response back:

=> “#<GraphQL::Client::Response:0x00007fa9fd399cd0 @Original _hash={"errors"=>[{"message"=>"Internal error. Looks like something went wrong on our end.\nRequest ID: c051d4e4-e0d3-4611-8323-fd70703a6e9f (include this in support requests).", "extensions"=>{"code"=>"INTERNAL_SERVER_ERROR", "requestId"=>"c051d4e4-e0d3-4611-8323-fd70703a6e9f"}}]}, @Data_3 =nil, @errors=#<GraphQL::Client::Errors @messages={"data"=>["Internal error. Looks like something went wrong on our end.\nRequest ID: c051d4e4-e0d3-4611-8323-fd70703a6e9f (include this in support requests)."]} @details ={"data"=>[{"message"=>"Internal error. Looks like something went wrong on our end.\nRequest ID: c051d4e4-e0d3-4611-8323-fd70703a6e9f (include this in support requests).", "extensions"=>{"code"=>"INTERNAL_SERVER_ERROR", "requestId"=>"c051d4e4-e0d3-4611-8323-fd70703a6e9f"}, "normalizedPath"=>["data"]}]}>, @extensions=nil>”

Here are the variables for the query

{"input"=>[{"resource"=>"BULK_MUTATION_VARIABLES", "filename"=>"./tmp/staged_upload1631316638.jsonl", "mimeType"=>"text/jsonl", "fileSize"=>"8"}]}

Here is the query as it appears in my code

client = ShopifyAPI::GraphQL.client
          staged_upload_query = client.parse <<-GRAPHQL
          mutation($input: [StagedUploadInput!]!) {
              stagedUploadsCreate(input: $input) {
                stagedTargets {
                  resourceUrl
                  url
                }
                userErrors {
                  field
                  message
                }
              }
            }
          GRAPHQL

I am using Ruby on Rails for this app.

I’ve located the source of the error. The query does not contain the httpMethod in its variables. The resourceUrl parameters are also missing. Here is the correct query.

client = ShopifyAPI::GraphQL.client
          staged_upload_query = client.parse <<-GRAPHQL
          mutation($input: [StagedUploadInput!]!) {
              stagedUploadsCreate(input: $input) {
                stagedTargets {
                  resourceUrl
                  url
                  parameters {
                    name
                    value
                  }
                }
                userErrors {
                  field
                  message
                }
              }
            }
          GRAPHQL
1 Like

Hey @strocode ,

Had a doubt on how you were making the multipart form POST request for uploading the file to the returned amazon url.

For e.g. I have this code.

form_inputs = {}
result.params.each {|param| form_inputs[param.name] = param.value}
form_inputs[:file] = file # JSON file with the graphql variables

response = HTTP.post(result.url, :form => form_inputs)

But the response is always coming back as a 400 Bad Request.

I checked the StagedUploadsCreationMutator - and it looks correct.

result.url is the URL returned from StagedUploadsCreationMutator

Is there a repo you have of this?

If you have any inputs on this, it would greatly help.

Thank you!

Arjun

form_inputs has all the inputs for the form.

{"key"=>"tmp/61399695614/bulk/95e555c4-cc9d-4b99-9883-1770ddcad337/bulk_op_vars", "Content-Type"=>"text/jsonl", "success_action_status"=>"201", "acl"=>"private", "policy"=>"eyJleHBpcmF0aW9uIjoiMjAyMS0xMi0yNlQwNToxNToxNVoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJzaG9waWZ5In0sWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsMSwyMDk3MTUyMF0seyJrZXkiOiJ0bXAvNjEzOTk2OTU2MTQvYnVsay85NWU1NTVjNC1jYzlkLTRiOTktOTg4My0xNzcwZGRjYWQzMzcvYnVsa19vcF92YXJzIn0seyJDb250ZW50LVR5cGUiOiJ0ZXh0L2pzb25sIn0seyJzdWNjZXNzX2FjdGlvbl9zdGF0dXMiOiIyMDEifSx7ImFjbCI6InByaXZhdGUifSx7IngtYW16LWNyZWRlbnRpYWwiOiJBS0lBSllNNTU1S1ZZRVdHSkRLUS8yMDIxMTIyNi91cy1lYXN0LTEvczMvYXdzNF9yZXF1ZXN0In0seyJ4LWFtei1hbGdvcml0aG0iOiJBV1M0LUhNQUMtU0hBMjU2In0seyJ4LWFtei1kYXRlIjoiMjAyMTEyMjZUMDQxNTE1WiJ9XX0=", "x-amz-credential"=>"AKIAJYM555KVYEWGJDKQ/20211226/us-east-1/s3/aws4_request", "x-amz-algorithm"=>"AWS4-HMAC-SHA256", "x-amz-date"=>"20211226T041515Z", "x-amz-signature"=>"2f1cbc9353ab7cc181a57bc3456a599d557946e6ab7b26457ef9d3be69159cf1", :file=>#

Actually got this working using RestClient.

response = RestClient.post(result.url, form_inputs)

Thank you!

Arjun