Media upload failed Image: Media processing failed

Hello All,

I tried using this GraphQL/R code below to bulk upload Product Image via urls; however it doesn’t work.

  # Define your Shopify API URL and access token
  url <- "https://example-store.myshopify.com/admin/api/2024-10/graphql.json"
 # url <- paste0("https://example-store.myshopify.com/admin/api/2024-10/products/", product_Id, "/images.json")
  access_token <- "abc"  # Replace with your actual access token
  
  # Set up the headers for authorization and content type
  headers <- add_headers(
    `Content-Type` = "application/json",
    `X-Shopify-Access-Token` = access_token
  )
  
  # Define the GraphQL mutation and variables for the media creation
  query <- "
mutation productCreateMedia($media: [CreateMediaInput!]!, $productId: ID!) { 
  productCreateMedia(media: $media, productId: $productId) { 
    media { 
      alt 
      mediaContentType 
      status 
    } 
    mediaUserErrors { 
      field 
      message 
    } 
    product { 
      id 
      title 
    } 
  } 
}
"

# Define the variables
variables <- list(
  media = list(
    list(
      alt = "",
      mediaContentType = "IMAGE",
      originalSource = url
    )
  ),
  productId = paste0("gid://shopify/Product/", product_Id)
)

# Combine the query and variables into the JSON payload
payload <- toJSON(list(query = query, variables = variables), auto_unbox = TRUE)

# Send the POST request to Shopify's GraphQL API
response <- POST(url, headers, body = payload)

# Check the response status and parse the content
if (status_code(response) == 200) {
  content <- content(response, "parsed")
  print("Media creation response:")
  print(content)
} else {
  print(paste("Request failed with status code", status_code(response)))
  print(content(response, "text"))
}

The API call made it through, response as below:

[1] "Media creation response:"
$data
$data$productCreateMedia
$data$productCreateMedia$media
$data$productCreateMedia$media[[1]]
$data$productCreateMedia$media[[1]]$alt
[1] ""

$data$productCreateMedia$media[[1]]$mediaContentType
[1] "IMAGE"

$data$productCreateMedia$media[[1]]$status
[1] "PROCESSING"

$data$productCreateMedia$mediaUserErrors
list()

$data$productCreateMedia$product
$data$productCreateMedia$product$id
[1] "gid://shopify/Product/9499904278775"

$data$productCreateMedia$product$title
[1] "TV Cabinet"

$extensions
$extensions$cost
$extensions$cost$requestedQueryCost
[1] 20

$extensions$cost$actualQueryCost
[1] 20

$extensions$cost$throttleStatus
$extensions$cost$throttleStatus$maximumAvailable
[1] 2000

$extensions$cost$throttleStatus$currentlyAvailable
[1] 1980

$extensions$cost$throttleStatus$restoreRate
[1] 100

but it throws this error on shopify web version. when i tried to upload the image through URL via Shopify web (not through GraphQL), it seems to work perfectly fine.

Does anyone have any insights?

Hi @laylaqtran

Are all URLs in the parameters accessible? Is there cross domain validation?