API Use to Upload Pdf Fie in Settings->Files Section

Hello Guys,

I have used the graphql API for upload pdf in shopify Settings->Files sections. But i didn’t get success if anyone have any suggestion regarding this please let us know.
i have used this code

mutation  {
  stagedUploadsCreate(input:{
    fileSize: "1000",
    filename: "test.pdf"
    mimeType: "pdf",
    resource: FILE,
    httpMethod:POST,
   
  }) {
    stagedTargets {
      resourceUrl
      url:"https://virtual-employees.myshopify.com/admin/settings/files"
    }
    userErrors {
      field
      message
    }
  }
}

Hey @GopalSingh20 ,

I took a look at what you shared, and it appears you are may have run into a few issues in the file staging process for creating a new file asset in the admin. Here is our stagedUploadsCreate mutation doc that provides a good starting point of the mutation body and variable structure.

I suggest testing and debugging with an API client (like Insomnia), as this process requires multiple stages and requests to complete. Here is an example of a mutation I tested that successfully returned a staging url and details:

mutation fileStagedUploads($input: [StagedUploadInput!]!) {
	stagedUploadsCreate(input: $input) {
		stagedTargets {
			url
			resourceUrl
			parameters {
				name
				value
			}
		}
		userErrors {
			field
			message
		}
	}
}
{
  "input": {
    "fileSize": "500",
    "filename": "new.pdf",
    "httpMethod": "POST",
    "mimeType": "file/pfd",
    "resource": "FILE"
  }
}

If you aren’t familiar with this type of workflow I’d suggest taking a look at our product media upload API examples for insights on a similar process. The data returned from the initial mutation will need to be formatted as multipart form data then uploaded through an HTTP request (examples provided in cURL).

Once a file is staged, you can use the url and fileCreate mutation to create a new file asset.

Hope that offers a good starting point for you - Cheers!

@awwdam Thanks For reply now its working.