<?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>Forem: Anton Ödman</title>
    <description>The latest articles on Forem by Anton Ödman (@banjoanton).</description>
    <link>https://forem.com/banjoanton</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F226007%2Ff3e1d300-5d69-43db-aa3a-5004e324b13d.jpeg</url>
      <title>Forem: Anton Ödman</title>
      <link>https://forem.com/banjoanton</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/banjoanton"/>
    <language>en</language>
    <item>
      <title>My Tiny Git CLI Tool I Use Daily To Improve My Git Workflow</title>
      <dc:creator>Anton Ödman</dc:creator>
      <pubDate>Sun, 19 Feb 2023 21:00:36 +0000</pubDate>
      <link>https://forem.com/banjoanton/my-tiny-git-cli-tool-i-use-daily-to-improve-my-git-workflow-1cmo</link>
      <guid>https://forem.com/banjoanton/my-tiny-git-cli-tool-i-use-daily-to-improve-my-git-workflow-1cmo</guid>
      <description>&lt;p&gt;Most developers work with Git on a daily basis. I would almost assume there are as many work flows as there are developers. I recently came upon a problem all over again. Finally I decided to create a tiny CLI application to solve the problem I was having, and I ended up using that so much that I changed my actual Git workflow.&lt;/p&gt;

&lt;p&gt;The problem I was facing was the constant switching of branches. Bug fixes, features, dev reviews, and so much more. With long branch names like &lt;code&gt;bugfix/&amp;lt;CATEGORY&amp;gt;-&amp;lt;ID&amp;gt;-long-descriptive-name&lt;/code&gt;, I always forgot the names of the branches.  &lt;/p&gt;

&lt;p&gt;Enter: &lt;code&gt;git-recent-branch&lt;/code&gt;, my new very simple CLI tool.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JjQNnuRB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t2mmgzdtsup4u0el8b27.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JjQNnuRB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t2mmgzdtsup4u0el8b27.gif" alt="Gif showing usage of git-recent-branch" width="676" height="518"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just run &lt;code&gt;git-recent-branch&lt;/code&gt; (or &lt;code&gt;rb&lt;/code&gt; as an alias), and you'll get a nice looking prompt, allowing you to checkout one of your 5 recent branches with on click on the keyboard.  I use it almost all the time when switching branches. &lt;/p&gt;

&lt;p&gt;It might be a bit of a shameless plug, but it really helped me a lot and who knows, other people might perhaps find it helpful.&lt;/p&gt;

&lt;p&gt;The code is all open-source and available on &lt;a href="https://github.com/banjo/git-recent-branch"&gt;Github&lt;/a&gt; for those who want to look or contribute. Or feel free to hit me up on &lt;a href="https://twitter.com/banjo_dev"&gt;Twitter&lt;/a&gt; if you want to talk code.&lt;/p&gt;

&lt;p&gt;Happy coding! &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>productivity</category>
      <category>javascript</category>
      <category>node</category>
    </item>
    <item>
      <title>Introducing Regcode - Create Regular Expressions Easily with Code</title>
      <dc:creator>Anton Ödman</dc:creator>
      <pubDate>Mon, 31 May 2021 08:44:27 +0000</pubDate>
      <link>https://forem.com/banjoanton/introducing-regcode-create-regular-expressions-easily-with-code-2glk</link>
      <guid>https://forem.com/banjoanton/introducing-regcode-create-regular-expressions-easily-with-code-2glk</guid>
      <description>&lt;p&gt;Every programmer has most likely heard the term Regex, or Regular Expressions. It's extremely useful, but the unreadable syntax makes it hard the learn and easy to forget once you've learned it. &lt;/p&gt;

&lt;p&gt;I really wanted to make Regex easy, so therefore I created &lt;a href="https://www.regcodejs.com"&gt;&lt;strong&gt;Regcode&lt;/strong&gt;&lt;/a&gt; - a tool to create regular expressions easily with code (&lt;a href="https://github.com/banjo/regcode"&gt;Github repo&lt;/a&gt; for those interested, it's open-source).&lt;/p&gt;

&lt;p&gt;Regcode can be easily summarized in this picture:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--a7_1XlmC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c458l4sbpfyw0i0nmsqi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--a7_1XlmC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c458l4sbpfyw0i0nmsqi.png" alt="regcode explanation"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Features
&lt;/h2&gt;

&lt;p&gt;Regcode comes loaded with different features to make it easier for the developer to create their own regular expressions - without actually knowing Regex.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create Regular Expressions with simple code&lt;/li&gt;
&lt;li&gt;English-like syntax that is easy to read&lt;/li&gt;
&lt;li&gt;Easy to learn, easy to read&lt;/li&gt;
&lt;li&gt;Simple API&lt;/li&gt;
&lt;li&gt;Easy documentation&lt;/li&gt;
&lt;li&gt;Convert to Regex or match directly to a string in the API&lt;/li&gt;
&lt;li&gt;Web app to use it create it in the browser&lt;/li&gt;
&lt;li&gt;Get started in minutes&lt;/li&gt;
&lt;li&gt;No need to learn Regex to create an expression&lt;/li&gt;
&lt;li&gt;Free and open-source&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Regcode - the simple way to write Regex
&lt;/h2&gt;

&lt;p&gt;As you can see on the picture above - Regcode is not at all difficult to use. The syntax is basically English, making it easy to read and learn.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;matchAll&amp;gt; hasBefore(https://) [character]{any} normal(.) [character]{any} hasAfter(.[character]{2,6});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a simple regcode to match different URLs that ends with &lt;code&gt;.com&lt;/code&gt; or &lt;code&gt;.net&lt;/code&gt; (and starts with &lt;code&gt;https://&lt;/code&gt; but does not include it). The syntax makes it easy for the developer to write, but also for other developers to read and actually understand. The regex it generates is much harder to understand.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/(?&amp;lt;=https:\/\/)[A-Za-z\u00C0-\u017F]*\.[A-Za-z\u00C0-\u017F]*[A-Za-z\u00C0-\u017F]{2,6}/g
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Web app - use it directly in the browser
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GzU6-kv0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/ogqxtWk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GzU6-kv0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/ogqxtWk.png" alt="Web app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can create your own regcode directly in the browser over at the &lt;a href="https://www.regcodejs.com"&gt;main page for regcode&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Generate your regex directly, and compare your code directly with your own strings to see if they match.&lt;/p&gt;




&lt;h2&gt;
  
  
  API - use it in your project
&lt;/h2&gt;

&lt;p&gt;The API can be installed directly from &lt;a href="https://www.npmjs.com/package/regcode"&gt;NPM&lt;/a&gt; and used inside of your JavaScript/TypeScript projects.&lt;/p&gt;

&lt;p&gt;Install it as usual with NPM.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vb"&gt;&lt;code&gt;&lt;span class="n"&gt;npm&lt;/span&gt; &lt;span class="n"&gt;install&lt;/span&gt; &lt;span class="n"&gt;regcode&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;save&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, import it and use it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;regCode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;RegCode&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;code&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hasBefore(https://) normal(www.) [character]{any} normal(.com)[or]normal(.net)&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sentenceToMatch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;The url is https://www.regcodejs.com, here you go!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// look for matches&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;match&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;regCode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sentenceToMatch&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;    &lt;span class="c1"&gt;// ["www.regcodejs.com"]&lt;/span&gt;

&lt;span class="c1"&gt;// or convert to regex and match the normal way&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;regex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;regCode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;convert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;code&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;match&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sentenceToMatch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;match&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;           &lt;span class="c1"&gt;// ["www.regcodejs.com"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Documentation with examples
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CFSLHj86--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/Y19Oq6C.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CFSLHj86--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/Y19Oq6C.png" alt="Documentation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The documentation is short and hopefully easy to understand, with a lot of different examples to easily get you going. It's really easy to &lt;a href="https://docs.regcodejs.com/"&gt;get started with the basics&lt;/a&gt;. And for those eager to get going directly, you can start at the &lt;a href="https://docs.regcodejs.com/introduction/examples"&gt;examples&lt;/a&gt; page.&lt;/p&gt;




&lt;p&gt;Thank you for very much for taking your time and reading this post. I really hope Regcode comes to good use for you. Feel free to ask me if you have any questions, or create your own issues/pull request if you want to contribute to the project.&lt;/p&gt;

</description>
      <category>regex</category>
      <category>tool</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>My 7 Favorite VS Code Extensions (That Everyone Hasn't Mentioned Yet)</title>
      <dc:creator>Anton Ödman</dc:creator>
      <pubDate>Mon, 28 Oct 2019 22:17:59 +0000</pubDate>
      <link>https://forem.com/banjoanton/my-7-favorite-vs-code-extensions-that-everyone-hasn-t-mentioned-yet-4al</link>
      <guid>https://forem.com/banjoanton/my-7-favorite-vs-code-extensions-that-everyone-hasn-t-mentioned-yet-4al</guid>
      <description>&lt;p&gt;I — like many others — love customizing my VS Code setup. I am constantly looking for new plugins, settings, themes, fonts and productivity tips to enhance my experience. Sometimes I probably spend more time working on my workspace than actually getting any job done.&lt;/p&gt;

&lt;p&gt;I see new articles about VS Code all the time, and I probably read all of them — but most articles always contain the same great plugins. You know, &lt;strong&gt;Bracket Pair Colorizer 2&lt;/strong&gt;, &lt;strong&gt;Prettier&lt;/strong&gt;, &lt;strong&gt;Git Lens&lt;/strong&gt;, &lt;strong&gt;Auto Rename Tag&lt;/strong&gt;, &lt;strong&gt;Live Server&lt;/strong&gt;, &lt;strong&gt;Bookmarks&lt;/strong&gt;… I guess most people already know of them and use them because they are so damn useable. Therefore, I decided to create a list with some of my favorite VS Code extensions, that aren’t as popular and well known as the ones mentioned before. So without further ado — let's begin!&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://marketplace.visualstudio.com/items?itemName=michelemelluso.gitignore#overview" rel="noopener noreferrer"&gt;Gitignore&lt;/a&gt;
&lt;/h3&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ABSUdOBmzqr6Mjy24FGaV6g.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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2ABSUdOBmzqr6Mjy24FGaV6g.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This little plugin is quite simple. It just adds an &lt;code&gt;Add to .gitignore&lt;/code&gt; menu option when you right-click a file. Handy if you quickly want to add it without any hassle.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://marketplace.visualstudio.com/items?itemName=vincaslt.highlight-matching-tag" rel="noopener noreferrer"&gt;Highlight Matching Tag&lt;/a&gt;
&lt;/h3&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%2Fcdn-images-1.medium.com%2Fmax%2F2470%2F1%2A9c_15YnfnbjTrJkt_oFhYw.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%2Fcdn-images-1.medium.com%2Fmax%2F2470%2F1%2A9c_15YnfnbjTrJkt_oFhYw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, it does exactly what the name suggests. Highlights the matching closing tag, whether it is on the same line or far down the editor. This is especially useful when you are nested a few tabs in and have several lines of code to work with. Even though it might come to good use within a situation like the one on the picture, it doesn’t really give the plugin justice…&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://marketplace.visualstudio.com/items?itemName=kisstkondoros.vscode-gutter-preview" rel="noopener noreferrer"&gt;Image Preview&lt;/a&gt;
&lt;/h3&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%2Fcdn-images-1.medium.com%2Fmax%2F2106%2F1%2AWF9qfUTFBsxtHO6LEo1QiA.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%2Fcdn-images-1.medium.com%2Fmax%2F2106%2F1%2AWF9qfUTFBsxtHO6LEo1QiA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A small plugin that justs show a preview on the left-hand side of your editor. It doesn't matter if it is the import statement or in the actual code. As long as the picture is referenced, it is shown like this.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://marketplace.visualstudio.com/items?itemName=byi8220.indented-block-highlighting" rel="noopener noreferrer"&gt;Indented Block Highlighting&lt;/a&gt;
&lt;/h3&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%2Fcdn-images-1.medium.com%2Fmax%2F3120%2F1%2AV73FsLpXARBy0Z1uNveDOw.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%2Fcdn-images-1.medium.com%2Fmax%2F3120%2F1%2AV73FsLpXARBy0Z1uNveDOw.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is my latest find — and I really love it. I cannot believe this isn’t more popular. It, also, does exactly as the name suggests. It highlights the indented block you are currently working with. In my case, it highlights the whole StartPage component. Say for example, that I would step inside the HandleSubmit component, only that part would be highlighted. Like this:&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%2Fcdn-images-1.medium.com%2Fmax%2F2280%2F1%2AFe7_LzOrd0vcY6Knf_Izvg.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%2Fcdn-images-1.medium.com%2Fmax%2F2280%2F1%2AFe7_LzOrd0vcY6Knf_Izvg.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://marketplace.visualstudio.com/items?itemName=WallabyJs.quokka-vscode" rel="noopener noreferrer"&gt;Quokka&lt;/a&gt;
&lt;/h3&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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AHbJ5rM_AkzMyxeKjUmacIQ.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%2Fcdn-images-1.medium.com%2Fmax%2F2000%2F1%2AHbJ5rM_AkzMyxeKjUmacIQ.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Quokka is like a live scratchpad for JavaScript (or TypeScript). It gives you a live preview of your code results, whether be it an error or a value. This is great if you are trying out some new concept, or just like to play around.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://marketplace.visualstudio.com/items?itemName=natqe.reload" rel="noopener noreferrer"&gt;Reload&lt;/a&gt;
&lt;/h3&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%2Fcdn-images-1.medium.com%2Fmax%2F2190%2F1%2ASM7U_Ma5wSl84dwzJKy2JA.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%2Fcdn-images-1.medium.com%2Fmax%2F2190%2F1%2ASM7U_Ma5wSl84dwzJKy2JA.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I like the very simple ones. This just adds a Reload button to your bottom bar. Not life-changing, but I use it more than I thought I would.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://marketplace.visualstudio.com/items?itemName=albert.TabOut" rel="noopener noreferrer"&gt;TabOut&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Developers seem to be great at naming their applications. This plugin essentially allows you to use tab to escape out of quotes or brackets. I got so used to it with IntelliJ that now, I can’t live without it.&lt;/p&gt;

&lt;p&gt;So these are 7 of my favorite VS Code extensions that I use on a daily basis. They might not be the most popular — and some of them are just stupidly simple — but they get the job done.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>vscode</category>
      <category>productivity</category>
    </item>
    <item>
      <title>A Beginner’s Guide to the Gmail API and Its Documentation</title>
      <dc:creator>Anton Ödman</dc:creator>
      <pubDate>Sun, 08 Sep 2019 21:02:58 +0000</pubDate>
      <link>https://forem.com/banjoanton/a-beginner-s-guide-to-the-gmail-api-and-its-documentation-4bm0</link>
      <guid>https://forem.com/banjoanton/a-beginner-s-guide-to-the-gmail-api-and-its-documentation-4bm0</guid>
      <description>&lt;p&gt;A crucial part of programming is the ability to communicate with different Application Programming Interfaces (APIs). If you visit &lt;a href="https://cloud.google.com/monitoring/api/apis-explorer"&gt;Google API Explorer&lt;/a&gt;, you will find a huge library of APIs, including all of their well-known applications like Gmail, Drive, and Calendar. Simply put, an API allows you to fetch or send data to the services via HTTP requests.&lt;/p&gt;

&lt;p&gt;The usage and documentation of these APIs might be a bit tricky at first, but once you learn it, you‘ll be able to apply your knowledge to most Google applications.&lt;/p&gt;

&lt;p&gt;I decided to write a beginner’s guide for how to use and understand the Gmail API. The guide is based on the documentation, meaning you’ll learn what to look for and how to read it instead of just copying code. As most of the other Google API references documents are alike, you’ll see that adapting to them is much easier once you know how to actually read the docs. This will allow you to write your own code and actually understand what you’re doing.&lt;/p&gt;

&lt;p&gt;Python 3 is used in this guide, but the usage should look quite similar in other languages as well.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quickstart
&lt;/h2&gt;

&lt;p&gt;Google usually offers a quickstart guide to make authorization easier. This guide will use the authorization from the quickstart guide, which means it’ll come with some limitations, but it’s sufficient for our purposes. The other way to get the API key is to create a new project, which is a bit trickier.&lt;/p&gt;

&lt;p&gt;The Python quickstart guide can be accessed &lt;a href="https://developers.google.com/gmail/api/quickstart/python"&gt;at this link&lt;/a&gt;, but I’ll follow along and show you how everything is done here.&lt;/p&gt;

&lt;p&gt;Here’s what the quickstart looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZWT_F_eB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2788/1%2AZM4CSq5j9b7kNr7ZCnhGwQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZWT_F_eB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2788/1%2AZM4CSq5j9b7kNr7ZCnhGwQ.png" alt="" width="880" height="611"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Turn on the Gmail API
&lt;/h2&gt;

&lt;p&gt;The first step is to enable the API and download the credentials to use in our project. By pressing the “enable the Gmail API”* *button, we open a new window with our credentials.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--l6G9oWjk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AzdsZCQWFkIXWjdbrq5-DHg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--l6G9oWjk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AzdsZCQWFkIXWjdbrq5-DHg.png" alt="" width="860" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our Client ID and Client Secret will be shown. Choose the client configuration for download. A file will be saved, called credentials.json. We’ll save this to the same folder our code will be in.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sTyOlLjZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A4Ve-ijpUOxE6J1Y9ThepdA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sTyOlLjZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A4Ve-ijpUOxE6J1Y9ThepdA.png" alt="" width="610" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing the Libraries
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ETaDUWUV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AGPmZbjJSEtQGtw84EdMAcg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ETaDUWUV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AGPmZbjJSEtQGtw84EdMAcg.png" alt="" width="880" height="191"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Installing the required libraries is done with a simple pip command, provided by Google. I pasted it below as well. I would recommend doing it in a &lt;a href="https://realpython.com/python-virtual-environments-a-primer/"&gt;virtual environment&lt;/a&gt;. That is, however, not covered in this guide.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install — upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  First Run — Allow Access
&lt;/h2&gt;

&lt;p&gt;Before we continue following the guide, we’ll need to allow access to the Gmail API for our script. Let’s start by making the actual script.&lt;/p&gt;

&lt;p&gt;Create a &lt;em&gt;.py&lt;/em&gt; file in the project directory (same as the directory with credentials.json). For the sake of it, let’s call it gmail.py.&lt;/p&gt;

&lt;p&gt;Copy the example code from the Python quickstart to the gmail.py* *file. Ignore the code for now, we’ll dive into that later. We only need to allow access on the first run — it will be saved for all later runs as well.&lt;/p&gt;

&lt;p&gt;Just run the file as you normally would, and you’ll be able to sign in to your Google account in the web browser.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;python gmail.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Login to your account. A warning saying that the app is not verified will be shown. As we are using the quickstart method, our app is not yet verified. Just click the link shown on the picture to continue for now and allow access.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--r_hr1ZrG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AG-MWaFDYhIQ1573iRCGwtg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--r_hr1ZrG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AG-MWaFDYhIQ1573iRCGwtg.png" alt="" width="509" height="551"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DcDwBTW4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AbS5oC8evV6jqKNFtwnTmvw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DcDwBTW4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AbS5oC8evV6jqKNFtwnTmvw.png" alt="" width="741" height="530"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8-9w_2nL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A2wqor9ubBbVY1eevIOdddQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8-9w_2nL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A2wqor9ubBbVY1eevIOdddQ.png" alt="" width="483" height="651"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding the Code
&lt;/h2&gt;

&lt;p&gt;The example code may look overwhelming at first, but I’ll divide it into smaller parts to keep it simple. By the end, you’ll see that it actually isn’t that difficult.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Import and scopes&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5sINwLFd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3332/1%2ADaHBPVvcjHKHZcCKePZ6ww.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5sINwLFd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3332/1%2ADaHBPVvcjHKHZcCKePZ6ww.png" alt="" width="880" height="342"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As with any other Python script, we’ll start with the imports. Most imports are used for authorization with the credentials.json file. All of these are provided by default so we don’t need to change anything.&lt;/p&gt;

&lt;p&gt;Scopes are, however, the most important part. This variable will be modified later, but for now, we’ll settle for the default scope provided.&lt;/p&gt;

&lt;p&gt;What this is saying is that it will allow us to access data from the gmail.readonly scope. There are many more scopes, and this allows for a set of actions and requests we can make to the Gmail API. Some other requests require other scopes.&lt;/p&gt;

&lt;p&gt;Later on, we will add another scope to use other functionalities.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Credentials&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4z9kMwwo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3332/1%2A_d1IOUoZlQpTSGrCtJ8hsA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4z9kMwwo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3332/1%2A_d1IOUoZlQpTSGrCtJ8hsA.png" alt="" width="880" height="554"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The authorization is probably to the most advanced part of the script. We will not dive too much into that for now, as it’s already configured to work from the box.&lt;/p&gt;

&lt;p&gt;This is the part the gets the credentials you downloaded from credentials.json. First, it looks for a token.pickle file. That is the file that is created once you have allowed access to your account the first time. If the file already exists, it gets the credentials from it, meaning you don’t have to allow access several times.&lt;/p&gt;

&lt;p&gt;If the token.pickle file doesn’t exist, it loads the credentials from your credentials.json file instead. This requires that you allow access via the web browser, which you did before.&lt;/p&gt;

&lt;p&gt;The credentials are, in either case, saved in the creds variable for later use.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;API&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--57Tz3aCs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3332/1%2AFGXnbjWbRSYwinAkXhavDg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--57Tz3aCs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3332/1%2AFGXnbjWbRSYwinAkXhavDg.png" alt="" width="880" height="279"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the fun part of the script: The part the fetches the data from the Gmail API. As you can see, it’s actually not that advanced. This is the part that we’ll look deeper into.&lt;/p&gt;

&lt;p&gt;The service is built using the earlier imported build function. The credentials that we got earlier are passed as an argument to it.&lt;/p&gt;

&lt;p&gt;service is then used to fetch all Gmail labels for the account that was authorized. The data is saved to the results variable.&lt;/p&gt;

&lt;p&gt;The last line saves all labels to the labels variable. They are formatted as a list, therefore a default value ( [] ) is specified if the list is empty.&lt;/p&gt;

&lt;p&gt;The next part of this guide will look at the documentation to make some sense of this.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Result&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DLxFJpTq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3332/1%2Al2mDGxSl5GlFyvJ_6pJyeA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DLxFJpTq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3332/1%2Al2mDGxSl5GlFyvJ_6pJyeA.png" alt="" width="880" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At the end, the label names are printed (if there are any).&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding the Documentation
&lt;/h2&gt;

&lt;p&gt;So that was the quickstart example code. However, it doesn’t make much sense without reading the documentation. This part will show you how to actually understand what is written in the code, and how you’ll use the documentation to write your own code.&lt;/p&gt;

&lt;p&gt;First, let's go to the “Reference”** **tab to access the docs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iPOvVOAJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AcKX-uX8EnrqbFIhZhJ91Lg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iPOvVOAJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AcKX-uX8EnrqbFIhZhJ91Lg.png" alt="" width="521" height="117"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To the left, a large summary menu is shown. It’s full of a lot of information, but it’ll be extremely useful in the upcoming step.&lt;/p&gt;

&lt;p&gt;As we’re working with labels, let's choose the Users.labels section, and the Overview part to get some basic information about labels.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qakEtkdD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AL-0XnE0WLYAXeGioiY1vig.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qakEtkdD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AL-0XnE0WLYAXeGioiY1vig.png" alt="" width="261" height="583"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are greeted by this screen:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jsL20-kL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A4bfXKfw7KX1W_GkZJwj3vw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jsL20-kL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A4bfXKfw7KX1W_GkZJwj3vw.png" alt="" width="880" height="563"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A text saying that that list of methods is at the end of the page, as well as the &lt;em&gt;resource representations&lt;/em&gt;** **of the label. Information is usually sent as JSON, which is handled like dictionaries in Python.&lt;/p&gt;

&lt;p&gt;This is the information that each label we fetch holds. If we scroll down further, we should see a table that provides information about each property in the dictionary.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Xq3lS3c2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A9YXrKqRLQdCmMyCFkX2Olw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xq3lS3c2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A9YXrKqRLQdCmMyCFkX2Olw.png" alt="" width="867" height="189"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have highlighted the name part because we’ve used it before. We accessed the name of the label when we printed the labels earlier. Like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--F_aRBLyr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3332/1%2AcSISXp-VSOnfK3I1iI5OdQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--F_aRBLyr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3332/1%2AcSISXp-VSOnfK3I1iI5OdQ.png" alt="" width="880" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The label is, in this case, a dictionary, and we access the name property within it. We could access any other property that is named above, but for now, name is fine.&lt;/p&gt;

&lt;p&gt;It’s important to note that name is a string, but some values might be integers. It’s easy to find in the documentation.&lt;/p&gt;

&lt;p&gt;If we continue to scroll down to the bottom of the page, we’ll see all methods. A short description of each method is presented, as well as a hyperlink to the documentation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0q_aSaG5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2064/1%2A9fiTsokRfDRgpO9JpcgEbw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0q_aSaG5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2064/1%2A9fiTsokRfDRgpO9JpcgEbw.png" alt="" width="880" height="505"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You’ll use different methods depending on what you want to do. The quickstart example uses the list method to fetch all labels on the Gmail account. If we wanted to create a new label, we’d use the create method, which we’ll actually do later.&lt;/p&gt;

&lt;p&gt;If we go back up to the top and look at the overview at our left, you’ll see that each method has its own menu button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--urPc3ohy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A-L0nw6sol46cDfw5CfOJhA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--urPc3ohy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A-L0nw6sol46cDfw5CfOJhA.png" alt="" width="168" height="200"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;List Method&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Let’s take a closer look at the list method, which we used before by clicking list on the menu bar.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Bw-uo7BR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ALNvvhombnBYy1EfrZGvMOQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Bw-uo7BR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ALNvvhombnBYy1EfrZGvMOQ.png" alt="" width="880" height="560"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This provides a lot of useful information. For starters, an HTTP GET request is sent to the labels URL to fetch all the labels:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://www.googleapis.com/gmail/v1/users/userId/labels
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;We could do this manually using, for example, the requests library in Python. However, we’ll use the provided Google library in this guide.&lt;/p&gt;

&lt;p&gt;Authorization is required, but we already took care of that part earlier.&lt;/p&gt;

&lt;p&gt;And last, but not least, the parameters we can pass to the list method. As you can see, userId is the only one we can pass.&lt;/p&gt;

&lt;p&gt;The userId is a string that represents the user's email address. The value me can be used instead to indicate the authenticated user. We actually used the me value in the example code.&lt;/p&gt;

&lt;p&gt;We’ll soon go deeper into this, but first, we’ll read through the other parts of the list method documentation.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Authorization and scope&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cEgyxd2O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ALtM3AI9S7ROYG7-dFy1yuA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cEgyxd2O--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2ALtM3AI9S7ROYG7-dFy1yuA.png" alt="" width="880" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Scopes may sound familiar, that’s because we touched briefly on it earlier. To access the list method, at least one of the provided scopes are required.&lt;/p&gt;

&lt;p&gt;As you can see, we have already added the gmail.readonly scope at the top of our code.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--INqS_OJ9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3332/1%2AQiNaL9tlnQUZGV03vhK3tw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--INqS_OJ9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3332/1%2AQiNaL9tlnQUZGV03vhK3tw.png" alt="" width="880" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Response&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IUlN7XxD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A8ScFzWLx1vzS73TBLVkDUg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IUlN7XxD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A8ScFzWLx1vzS73TBLVkDUg.png" alt="" width="880" height="339"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The last part shows us what a successful request would return: a body in the JSON format. All labels are stored as a list that can be accessed with the labels key. Basically this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;list_of_labels = response["labels"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Exactly like you would use a normal dictionary in Python.&lt;/p&gt;

&lt;h2&gt;
  
  
  Making the List Request
&lt;/h2&gt;

&lt;p&gt;Let’s look back at the API part of our code now that we have gathered some more information from the documentation.&lt;/p&gt;

&lt;p&gt;First, the service is built with our credentials. This is simply the base that is used for making requests (using the methods we previously saw).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7hGf4Lce--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3332/1%2AX_MsWsepVs5Y51nPLlDqnw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7hGf4Lce--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3332/1%2AX_MsWsepVs5Y51nPLlDqnw.png" alt="" width="880" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we actually make the request using the list method with this code. It might look a bit more familiar now once we have looked through the docs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dpG6r8pO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2856/1%2A91CEaMVUGVNuAnxWns-pVQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dpG6r8pO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2856/1%2A91CEaMVUGVNuAnxWns-pVQ.png" alt="" width="880" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To easier show you how the syntax is built, I have color-coded the code along with the menu to show you how the API is working.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pye1pYQa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AW_C0IJhZpD8fsUIPOZvQ0Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pye1pYQa--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AW_C0IJhZpD8fsUIPOZvQ0Q.png" alt="" width="181" height="206"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lHSCjkdS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2856/1%2AyWPFL2hijRc_ms7Wg_vUgw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lHSCjkdS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2856/1%2AyWPFL2hijRc_ms7Wg_vUgw.png" alt="" width="880" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We start off with the service variable. By simply following the tree-like structure, method by method, we’ll finally get to the list method.&lt;/p&gt;

&lt;p&gt;Let’s actually take a closer look at the list method, and especially the familiar userId parameter that has me passed as an argument.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KjtEm189--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2856/1%2AKojfZwqfQdWnNnJEI2yVNw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KjtEm189--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2856/1%2AKojfZwqfQdWnNnJEI2yVNw.png" alt="" width="880" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we scroll back up to the top of the list method documentation, we’ll see the summary of the parameters that we talked about earlier. The userId parameter is specified, in case we don’t know what it is.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hgtr6INW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AchQYaFuL3HKx57PNTXrOQA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hgtr6INW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AchQYaFuL3HKx57PNTXrOQA.png" alt="" width="746" height="230"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We simply pass it as an argument to the list method in the code.&lt;/p&gt;

&lt;p&gt;As you probably recall, the request should return a dictionary, according to the response part of the documentation. We store it in the results variable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IUlN7XxD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A8ScFzWLx1vzS73TBLVkDUg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IUlN7XxD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A8ScFzWLx1vzS73TBLVkDUg.png" alt="" width="880" height="339"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To access the labels, we use the .get method of the dictionary. The first argument we pass is the name of what we want to get ( labels ), and the second argument is what we get returned if it doesn’t find anything with that name.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wNlwU-7c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2856/1%2A1RHuCGcDTHA9hseyiNH-rw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wNlwU-7c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2856/1%2A1RHuCGcDTHA9hseyiNH-rw.png" alt="" width="880" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If there is no key called labels, an empty list will be returned.&lt;/p&gt;

&lt;p&gt;So that is basically how the documentation is read, and how the list method works. Let’s try to do something else from start by following the API documentation instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a New Label
&lt;/h2&gt;

&lt;p&gt;Let’s use our newfound knowledge and do something new, something from scratch (almost).&lt;/p&gt;

&lt;p&gt;Remove all API-related code from your document. Keep only the imports, the scope, and the credential handling. We’ll try to create a new label via the API.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5_DxFIv_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AN0qMsmZcIJGvxrZ-z3JaEw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5_DxFIv_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AN0qMsmZcIJGvxrZ-z3JaEw.png" alt="" width="263" height="584"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s head to the Overview page of the labels. Scroll down to the methods to see which one we need to use to create our own method.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YaDrH183--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AWxk5gAfa3DMuE7sNHE_J6g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YaDrH183--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AWxk5gAfa3DMuE7sNHE_J6g.png" alt="" width="880" height="544"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LR2UN-OG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A46D2EVnXysPTradWR9Qonw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LR2UN-OG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2A46D2EVnXysPTradWR9Qonw.png" alt="" width="197" height="631"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may have noticed that there is a method that is literally called create that we’ll use. Go to the documentation of that method to see what we need.&lt;/p&gt;

&lt;p&gt;Let’s start off with the authorization and the scopes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--m_pOaaYv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AaUKVTjr-6qcJa56xk3CEdw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--m_pOaaYv--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AaUKVTjr-6qcJa56xk3CEdw.png" alt="" width="750" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, we require at least one of the three scopes that are present. However, we do not have any one of them in our code. Let’s add the gmail.labels scope.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wy07PEjz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2856/1%2A1nqtecorR_PVjfMnc0j7og.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wy07PEjz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2856/1%2A1nqtecorR_PVjfMnc0j7og.png" alt="" width="880" height="251"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The SCOPES variable takes a list, meaning that we could simply add the new scope with a comma separation.&lt;/p&gt;

&lt;p&gt;As the old authorization was stored in the token.pickle file (and that file is used for authorization as long as it exists), we need to remove it and re-create it with our new scope.&lt;/p&gt;

&lt;p&gt;Run the Python app again with python gmail.py to re-authorize, however, a minor change can be seen:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PMFddZWD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2Ads0-62GI7iv5MqduIsYKyg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PMFddZWD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2Ads0-62GI7iv5MqduIsYKyg.png" alt="" width="481" height="715"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A new dependency is added. You might not understand it because of the Swedish language, but it basically says “Handle Labels.” So the new scope added a new dependency to our application.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Code
&lt;/h3&gt;

&lt;p&gt;If we look at the top of the create method documentation, we can see that it is quite similar to the list method. It requires authorization, it makes an HTTP POST request and a userId parameter is needed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q8vURlkp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AlRRp4YiL4av0dNzJ4Gb3RQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q8vURlkp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AlRRp4YiL4av0dNzJ4Gb3RQ.png" alt="" width="749" height="625"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But somehow we need to pass the actual label in our request. If we scroll down to the request body, we’ll see how to do that.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qmG70oit--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2Acf-bScqmtyapkFk9qQutyA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qmG70oit--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2Acf-bScqmtyapkFk9qQutyA.png" alt="" width="745" height="836"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the body of our request, a label with at least the following properties should be present to create a label:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;labelListVisibility&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;messageListVisibility&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;name&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can learn about which type they should be in, as well as what they are, in the documentation.&lt;/p&gt;

&lt;p&gt;Exactly like we received the data in a dictionary, the data should be sent as a dictionary.&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating the label
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7l7TD_2j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2856/1%2AS7NYvPMJnEvrerP45au8RQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7l7TD_2j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2856/1%2AS7NYvPMJnEvrerP45au8RQ.png" alt="" width="880" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a simple function to create a label. It requires a name and two other optional arguments. If they are not specified, show and labelShow will be used as default.&lt;/p&gt;

&lt;p&gt;The label is created as a dictionary, and then returned.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---ZfY6aYo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2856/1%2AZVo9q8H4Ttqjyw-On-rWWQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---ZfY6aYo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2856/1%2AZVo9q8H4Ttqjyw-On-rWWQ.png" alt="" width="880" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To create a label with the name Test we would use the syntax above.&lt;/p&gt;

&lt;h3&gt;
  
  
  Making the request to the API
&lt;/h3&gt;

&lt;p&gt;Time to make the actual request to the API, and pass our label to our Gmail account. Let’s follow the same procedure as last time.&lt;/p&gt;

&lt;p&gt;I have color-coded the path to the create method.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HYEOqp-z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AZDrK7YXkrOQEmZ4wnA3Bgg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HYEOqp-z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AZDrK7YXkrOQEmZ4wnA3Bgg.png" alt="" width="201" height="208"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are not changing much compared to our last API call. We start with service, which we created before, and add each method until we reach the create method. We are, however, not completely done there.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--k3yarlUV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2856/1%2AX4AvizoiMDFJ21bVKDOkIQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k3yarlUV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2856/1%2AX4AvizoiMDFJ21bVKDOkIQ.png" alt="" width="880" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we scroll to the Parameters** **part of the documentation, we see that we need to pass userId as a parameter, like our last call.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hgtr6INW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AchQYaFuL3HKx57PNTXrOQA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hgtr6INW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AchQYaFuL3HKx57PNTXrOQA.png" alt="" width="746" height="230"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let’s use me again, like the documentation suggests.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fuERPwPH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2856/1%2Ashmtm6JubEoLe8c7SMs0Zg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fuERPwPH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2856/1%2Ashmtm6JubEoLe8c7SMs0Zg.png" alt="" width="880" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We’re still missing something: the actual label. We need to somehow pass the label in our request as well. Let’s scroll down to the request body again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WlSYcvKK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AAuhg-AF_hvawmH2T-rte6w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WlSYcvKK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AAuhg-AF_hvawmH2T-rte6w.png" alt="" width="732" height="241"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We’ve already created the label with all the required properties, so we need to pass it in the request body. This is done by simply adding another parameter to the create method called body.&lt;/p&gt;

&lt;p&gt;Let’s pass our label object in it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jfq51VC---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3044/1%2AjLcsDZFcRFP6UtyMwhPl2A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jfq51VC---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3044/1%2AjLcsDZFcRFP6UtyMwhPl2A.png" alt="" width="880" height="213"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The actual call is done, but to add some error checking, let’s wrap it into a try/except statement.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1Yacprkf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3044/1%2AMr1KQMjm0ltujEAow6eA5g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1Yacprkf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3044/1%2AMr1KQMjm0ltujEAow6eA5g.png" alt="" width="880" height="352"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If something goes wrong, the error message will be printed in our console. If everything goes as planned, Label created will be printed (and the label will be created).&lt;/p&gt;

&lt;p&gt;So let’s look back at the parts of the code we created to make the new API request:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kECHK4I0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3044/1%2AcsDxXfIBHowGghU2BG-DUw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kECHK4I0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/3044/1%2AcsDxXfIBHowGghU2BG-DUw.png" alt="" width="880" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The API handling is in fact not that difficult. The actual fetching doesn’t require many lines of code — the tricky part is the authorization, which we don’t even need to handle ourselves.&lt;/p&gt;

&lt;p&gt;If we save and run the code with python gmail.py, a new label should be created in our Gmail account.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_NheKOh8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AesN51KWw8J7-nkiZJXkhzw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_NheKOh8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/2000/1%2AesN51KWw8J7-nkiZJXkhzw.png" alt="" width="248" height="49"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Done!&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;We successfully made an API call to Gmail from scratch and created our own label. The same basic principle applies to most other methods in the Gmail API, and other Google APIs, as well.&lt;/p&gt;

&lt;p&gt;Feel free to try making other requests just to get the hang of it. The best way to learn is to practice. Once you begin to understand the documentation, creating your own calls isn’t that hard.&lt;/p&gt;

&lt;p&gt;Try creating your own mail drafts, or fetch all your inbox messages based on a query — everything is specified in the documentation.&lt;/p&gt;

&lt;p&gt;I have provided the &lt;a href="https://github.com/banjoanton/gmail-api-guide/blob/master/gmail.py"&gt;full code&lt;/a&gt; on GitHub if you want to look at the final results of our example. Good luck with your projects and happy coding!&lt;/p&gt;

</description>
      <category>python</category>
      <category>api</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
