title: Post image to Instagram from a Javascript using Instagram API
body: <p>Instagram Graph API:<br />
  <a href="https://developers.facebook.com/docs/instagram-api/" rel="nofollow noreferrer">https://developers.facebook.com/docs/instagram-api/</a></p>
  <p>Content Publishing:<br />
  <a href="https://developers.facebook.com/docs/instagram-api/guides/content-publishing/" rel="nofollow noreferrer">https://developers.facebook.com/docs/instagram-api/guides/content-publishing/</a></p>
  <p>My code <code>Javascript</code> in <code>Google App Script</code>:</p>
  <pre><code>function InstagramPost() {
  
    const id = '123456789';
    const image = 'https://www.w3schools.com/images/w3schools_green.jpg';
    const text = 'Hello%20World';
    const access_token = 'TESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTESTTEST';
    const container = 'https://graph.facebook.com/v11.0/' + id + '/media?image_url=' + image + '&amp;caption=' + text + '&amp;access_token=' + access_token;
  
    const response = UrlFetchApp.fetch(container);
    const creation = response.getContentText();
  
    Logger.log(creation);
  }
  </code></pre>
  <p>The return in my Logger of my container to Post via Instagram API request comes as follows:</p>
  <pre><code>{
    &quot;data&quot;: [
      {
        &quot;id&quot;: &quot;11111111111111111&quot;
      },
      {
        &quot;id&quot;: &quot;22222222222222222&quot;
      },
      {
        &quot;id&quot;: &quot;33333333333333333&quot;
      }
    ],
    &quot;paging&quot;: {
      &quot;cursors&quot;: {
        &quot;before&quot;: &quot;QWOURQWNGEWRONHWENYWPETGNWQPGNPGNWEPGNWEPGNWEPNGWPENGPWEG&quot;,
        &quot;after&quot;: &quot;WIWEPGNEPBNWE´GNÉ´BNWE´BNWÉBWNEB´WENBNWEBWEBEWBWE&quot;
      },
      &quot;next&quot;: &quot;https://graph.facebook.com/v11.0/11111111111111111/media?access_token=PQWNFWPQINPWNBQPWNBQPWNBPQWNVQWPNVPQWVNPQWPVNQPWNVQPWVNQPWNVPQWNVQPWNVQPWVNQASASLGÇAJKSGLJAAÇSNAÇKNSVÇLKNASBÇANSBÇAS&quot;
    }
  }
  </code></pre>
  <p>To make the final call for post image it is necessary to use an <code>creation_id=</code>:</p>
  <pre><code>const sendinstagram = 'https://graph.facebook.com/v11.0/' + id + '/media_publish?creation_id=' + creation + '&amp;access_token=' + access_token;
  UrlFetchApp.fetch(sendinstagram);
  </code></pre>
  <p>If the return from the container is several <code>id</code> in sequence, how do I know which one to define for the call?</p>
  <p>Note: I can't loop to try every id because Instagram has a daily limit of 25 calls and posts, so if I did that I would end up with my calls just trying to post a single image.</p>