title: GitLab CI get last artifact
body: <p>I'm trying to get the latest build artifact using <code>curl</code>. Here's what I've tried. </p>
  
  <p>First, get last pipeline id:</p>
  
  <pre><code>curl -v -H "Content-Type: application/json" -H "PRIVATE-TOKEN: &lt;my-token-here&gt;" https://&lt;project&gt;/api/v4/projects/&lt;project&gt;/pipelines?per_page=1&amp;page=1
  </code></pre>
  
  <p>Next, get job id based on pipeline id just obtained before:</p>
  
  <pre><code>curl -sS --header "PRIVATE-TOKEN: &lt;my-token-here&gt;" "https://[redacted,host]/api/v4/projects/[redacted,project]/pipelines/&lt;pipeline-id&gt;/jobs" | jq '.[] | select(.name == "build-assets" and .status == "success" and .artifacts_file != null) | .id'
  </code></pre>
  
  <p>Finally, get the artifacts to <code>build.zip</code> based on job id:</p>
  
  <pre><code>curl -sS --header "PRIVATE-TOKEN: &lt;my-token-here&gt;" "https://[redacted,host]/api/v4/projects/[redacted, project]/jobs/&lt;JOB_ID&gt;/artifacts" &gt; build.zip
  </code></pre>
  
  <p>These steps above do work, but I have to hit three endpoints (and process the JSON response for each step).</p>
  
  <p>I also read in <a href="https://docs.gitlab.com/ee/user/project/pipelines/job_artifacts.html#downloading-the-latest-artifacts" rel="noreferrer">GitLab's documentation</a>, that there's a <em>single</em> endpoint available for this. So I also tried this:</p>
  
  <pre><code>curl -sS --header "PRIVATE-TOKEN: &lt;my-token-here&gt;" "https://&lt;url&gt;/&lt;namespace&gt;/&lt;project&gt;/-/jobs/artifacts/&lt;refs&gt;/download?job=&lt;job_name&gt;"
  </code></pre>
  
  <p>but this always redirects me to the login page, saying this:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;html&gt;&lt;body&gt;You are being &lt;a href="https://&lt;url&gt;/users/sign_in"&gt;redirected&lt;/a&gt;.&lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p>Is there any simpler way to do this task? Or how to use the endpoint that is described on the documentation above propeprly?</p>