<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: The Jucktion</title>
    <description>The latest articles on DEV Community by The Jucktion (@jucktion).</description>
    <link>https://dev.to/jucktion</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F803387%2F2e19cb95-5dd7-4bb5-8b5d-2b4960180ec9.jpg</url>
      <title>DEV Community: The Jucktion</title>
      <link>https://dev.to/jucktion</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jucktion"/>
    <language>en</language>
    <item>
      <title>Accessing your standalone Gitlab Snippets with Curl</title>
      <dc:creator>The Jucktion</dc:creator>
      <pubDate>Sat, 01 Jan 2022 19:20:28 +0000</pubDate>
      <link>https://dev.to/jucktion/accessing-your-standalone-gitlab-snippets-with-curl-457e</link>
      <guid>https://dev.to/jucktion/accessing-your-standalone-gitlab-snippets-with-curl-457e</guid>
      <description>&lt;p&gt;GitLab is an open-source collaborative git platform with tons of features. Gitlab offers a broad range of features for its users to make git more collaborative and accessible. It offers free tier for users with personal and hobby projects. Users can create private repositories if they don’t want the code to be public. Similar to GitHub’s gists, GitLab has its snippets. Snippets are short standalone programs that usually server a specific purpose. You can have private snippets as well. Here’s how you access your private snippets remotely without logging into your GitLab account.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft2hm0ltczz2smybwbaia.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft2hm0ltczz2smybwbaia.png" alt="Gitlab Snippets"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;GitLab has &lt;a href="https://docs.gitlab.com/ee/api/repository_files.html" rel="noopener noreferrer"&gt;documented API access&lt;/a&gt; for files in a repository, but it’s missing them for standalone snippets. The documentation has snippets access shown &lt;a href="https://docs.gitlab.com/ee/api/project_snippets.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;, but it targets snippets that are already inside a project. It says nothing about snippets not inside a project.&lt;/p&gt;

&lt;p&gt;You will need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A GitLab private access token(requires login) to access the file remotely or through your terminal.&lt;/li&gt;
&lt;li&gt;The ID of your snippet.&lt;/li&gt;
&lt;li&gt;General understanding of curl&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now you will have to format a curl syntax to make it grab your snippets file. The private access token will verify our request so the file inaccessible to anyone but us.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl --header “PRIVATE-TOKEN: &amp;lt;private-access-token&amp;gt;” “https://gitlab.com/api/v4/snippets/&amp;lt;snippet-id&amp;gt;/raw” -o main.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl --header “PRIVATE-TOKEN: 2LAX6jyj4f8Zb5fd5Ft4yA” “https://gitlab.com/api/v4/snippets/9999999/raw” -o main.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The “main.py” is file name you want the output to be pasted to. It can be any name you prefer the file name and extension to be saved. Obviously, it it is a source code file, you’ll have to name it properly, but the idea is that It doesn’t have to reflect the exact filename on your snippet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fucii775xw12zlrtd4gog.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fucii775xw12zlrtd4gog.png" alt="Curl Operation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If all goes well, you will see a file download progress and the file should appear on your folder. Notice the “Total” column, it should have a file size information. It’s a sign that the command worked.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>curl</category>
      <category>gitlab</category>
      <category>snippets</category>
    </item>
  </channel>
</rss>
