title: Shopify GraphQL PHP
body: <p>I'm having some issues with using Shopify's GraphQL API. I've already made a bunch of REST calls, but for this one I would need GraphQL.
  I'm trying to add videos to certain products and this is what I have so far:</p>
  
  <pre><code>mutation productCreateMedia($productId: ID!, $media: [CreateMediaInput!]!) {
    productCreateMedia(productId: $productId, media: $media) {
      media {
        alt
      }
      mediaUserErrors {
        code
        field
        message
      }
      product {
        id
      }
    }
  }
  </code></pre>
  
  <p>and for variables, I have an array of:</p>
  
  <pre><code>$gid = "gid://shopify/Product/".row('shopifyID');
  $videoLink = "https://www.youtube.com/watch?v=".row('youtubeID');
  $media = array('originalSource'=&gt;$videoLink,'mediaContentType'=&gt;'EXTERNAL_VIDEO');
  $variables = array ('productId'=&gt;$gid,'media'=&gt;$media);
  </code></pre>
  
  <p>I use the next function for the call:</p>
  
  <pre><code>function graph($query , $variables = []){
  $domain = 'domain.myshopify.com';
  $url = 'https://'.$domain.'/admin/api/2020-01/graphql.json';
  
  $request = ['query' =&gt; $query];
  
  if(count($variables) &gt; 0) { $request['variables'] = $variables; }
  
  $req = json_encode($request);
  $parameters['body'] = $req;
  
  $stack = HandlerStack::create();
  $client = new \GuzzleHttp\Client([
      'handler'  =&gt; $stack,
      'headers'  =&gt; [
          'Accept'       =&gt; 'application/json',
          'Content-Type' =&gt; 'application/json',
          'X-Shopify-Access-Token'=&gt;'myAPIpass' // shopify app accessToken
      ],
  ]);
  
  $response = $client-&gt;request('post',$url,$parameters);
  return $body =  json_decode($response-&gt;getBody(),true);
  </code></pre>
  
  <p>}</p>
  
  <p>But what I'm getting back is: 
  Variable productId of type ID! was provided invalid value</p>
  
  <p>I used php-shopify SDK for REST API, but couldn't figure out how it works for GraphQL, so went with the usual way of just calling the JSON endpoint.
  Any help in what I'm doing wrong here?</p>