(PHP - API REST) Problem With Multi-Variant And Multi-Option Product

Topic summary

A developer is struggling to create products with multiple variants and options using Shopify’s REST API via PHP.

Technical Issues:

  • Encountered a parse error (“unexpected token ‘{’”) when using the shopify-php-api library from documentation
  • Successfully implemented GET requests and inventory updates using curl with associative arrays and http_build_query
  • Unable to create multi-variant, multi-option products despite proper array structure

Code Approach:
The developer structured data with nested arrays defining:

  • Product title
  • Variants with option1/option2 values (e.g., color “Nero”/“Blu”, size “35”/“36”)
  • Options array specifying names (“Colore”, “Taglia”) and corresponding values

Current Status:
The issue remains unresolved. One commenter suggested verifying Shopify’s expected data format, but no concrete solution has been provided. The developer confirmed the problem persists with no successful workaround found.

Summarized with AI on October 30. AI used: claude-sonnet-4-5-20250929.

I am trying to create a REST API based connection via PHP to create a product with multiple variations and multiple options but I cannot find a solution. I tried to run the code found in the documentation using the proposed shopify-php-api library but the PHP interpreter gives me the following error: “Parse error: syntax error, unexpected token “{”, expecting “]””.

I also created a procedure with an associative array and the http_build_query function using curl for creating the API request. With this method I was able to handle a GET call of products and update an inventory of a specific variant but I am unable to create multi-variant and multi-option products.

Thank you in advance who will answer me!

Greetings

This is the code:

$prodotto= array();
$prodotto[‘product’][‘title’]=“TEST”;
$prodotto[‘product’][‘variants’][0][‘option1’]=“Nero”;
$prodotto[‘product’][‘variants’][0][‘option2’]=“35”;
$prodotto[‘product’][‘variants’][1][‘option1’]=“Blu”;
$prodotto[‘product’][‘variants’][1][‘option2’]=“36”;
$prodotto[‘product’][‘options’][0][‘name’]=“Colore”;
$prodotto[‘product’][‘options’][0][‘values’][0]=“Nero”;
$prodotto[‘product’][‘options’][0][‘values’][1]=“Blu”;
$prodotto[‘product’][‘options’][1][‘name’]=“Taglia”;
$prodotto[‘product’][‘options’][1][‘values’][0]=“35”;
$prodotto[‘product’][‘options’][1][‘values’][1]=“36”;

@LeoDea is this question still relevant? Did you ever solve this?

Hi @IP1999 , The question is still relevant. I have never been able to solve the problem.

Check Shopify’s expected data format kind of like adjusting your pitch after Sales Training London to match the client’s needs.