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

Solved
GopalSingh20
Shopify Partner
2 0 1

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
    }
  }
}

 

 

Accepted Solution (1)
awwdam
Shopify Staff
Shopify Staff
249 42 35

This is an accepted solution.

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 | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 2 (2)
awwdam
Shopify Staff
Shopify Staff
249 42 35

This is an accepted solution.

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 | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

GopalSingh20
Shopify Partner
2 0 1

@awwdam Thanks For reply now its working.