title: Google Photo returns "error 400: Request contains an invalid media item id. (INVALID_ARGUMENT)" when adding a media item into an existing album
body: <p>After getting a list of media items and a list of albums from <a href="https://developers.google.com/photos/library/reference/rest/" rel="nofollow noreferrer">the Google Photo API</a> (using Go and the Google Photo REST API), adding items to an album returns an error.</p>
  
  <p>(Note: using the web interface to add the items to the album works fine).</p>
  
  <p>Code to add the media item to the album:</p>
  
  <pre class="lang-golang prettyprint-override"><code>func (a Album) AddItems(items ...MediaItem) error {
      rel := &amp;url.URL{Path: fmt.Sprintf("/v1/albums/%s:batchAddMediaItems", a.ID)}
      u := a.service.baseURL.ResolveReference(rel)
      for len(items) &gt; 0 {
          ids := []string{}
          for i := 0; i &lt; 50 &amp;&amp; i &lt; len(items); i++ {
              ids = append(ids, items[i].ID)
          }
          items = items[len(ids):]
          toAdd := map[string]interface{}{
              "mediaItemIds": ids,
          }
          bodyData, err := json.Marshal(toAdd)
          if err != nil {
              return err
          }
          req, err := http.NewRequest("POST", u.String(), bytes.NewBuffer(bodyData))
          if err != nil {
              return err
          }
          resp, err := a.service.client.Do(req)
          if err != nil {
              return err
          }
          defer resp.Body.Close()
          respErr := struct {
              Error ServerError `json:"error"`
          }{}
          body, err := ioutil.ReadAll(resp.Body)
          if err != nil {
              return err
          }
          err = json.Unmarshal(body, &amp;respErr)
          if err != nil {
              return err
          }
          err = respErr.Error.Error()
          if err != nil {
              return err
          }
      }
      return nil
  }
  </code></pre>
  
  <p>The server returns the following error:</p>
  
  <pre><code>error 400: Request contains an invalid media item id. (INVALID_ARGUMENT). 
  </code></pre>
  
  <p>The media item ID is copied from the ID field of the <a href="https://developers.google.com/photos/library/reference/rest/v1/mediaItems#MediaItem" rel="nofollow noreferrer">JSON representation</a> of a media item returned from <a href="https://developers.google.com/photos/library/reference/rest/v1/mediaItems/search" rel="nofollow noreferrer">a search request</a>. The other fields of the media item seem to be valid (e.g. the ProductURL). </p>
  
  <p>What is wrong in this <code>batchAddMediaItems</code> request? or how to get a valid media item ID suitable for <code>batchAddMediaItems</code> ?</p>
  
  <p>Thank you.</p>