<?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: Bryon Larrance</title>
    <description>The latest articles on DEV Community by Bryon Larrance (@beelarr).</description>
    <link>https://dev.to/beelarr</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%2F36478%2Fef441d12-f3da-42d0-aa9f-21bf2ccc9e9d.jpg</url>
      <title>DEV Community: Bryon Larrance</title>
      <link>https://dev.to/beelarr</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/beelarr"/>
    <language>en</language>
    <item>
      <title>Accessing Prismic Releases Programmatically</title>
      <dc:creator>Bryon Larrance</dc:creator>
      <pubDate>Tue, 05 May 2020 18:51:04 +0000</pubDate>
      <link>https://dev.to/beelarr/accessing-prismic-releases-programmatically-2ldm</link>
      <guid>https://dev.to/beelarr/accessing-prismic-releases-programmatically-2ldm</guid>
      <description>&lt;p&gt;I have been working with the Prismic CMS for the past several months and ran into a problem running Cypress E2E tests with Prismic data that was not yet in a published &lt;a href="https://user-guides.prismic.io/en/articles/778358-what-is-a-release"&gt;release&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The tests fail because the Prismic data isn’t available (not published) and the view isn’t rendered.  &lt;/p&gt;

&lt;p&gt;When you are developing locally there is no issue, because you have access to the &lt;strong&gt;release&lt;/strong&gt; preview link, but I needed a way to access Prismic releases programmatically in my staging and testing environments.&lt;/p&gt;

&lt;p&gt;I am primarily querying by Uid in a Node environment which looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;api.query(
  Prismic.Predicates.at('my.docName.uid', 'uid')
);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://prismic.io/docs/javascript/query-the-api/query-options-reference#32_0-ref"&gt;The Prismic docs mention a query option ref&lt;/a&gt;, so I could simply create an env variable and pass it in like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;api.query(
  Prismic.Predicates.at('my.docName.uid', 'uid'),
  {
    ref: process.env.PRISMIC_RELEASE_REF
  }
);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;I also need to create a token that allows refs other than master be queried. That can be found at &lt;a href="https://your-repository-name.prismic.io/settings/apps"&gt;https://your-repository-name.prismic.io/settings/apps&lt;/a&gt; &amp;gt; API &amp;amp; Security.&lt;/p&gt;

&lt;p&gt;The final step is finding my release ref uid. An easy way to find it is in the Prismic API browser which is located at:&lt;br&gt;
&lt;a href="https://your-repository-name.prismic.io/api/v2"&gt;https://your-repository-name.prismic.io/api/v2&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Xq5HM1lx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://images.prismic.io/prismicio-docs%252Fd8077650-c681-4b34-a8a0-46de62ae691a_ref_browser.gif%3Fauto%3Dcompress%2Cformat" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Xq5HM1lx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://images.prismic.io/prismicio-docs%252Fd8077650-c681-4b34-a8a0-46de62ae691a_ref_browser.gif%3Fauto%3Dcompress%2Cformat" alt="alt text" title="gif showing how to find the release ref"&gt;&lt;/a&gt;&lt;br&gt;
or when you init the api the refs are listed under &lt;code&gt;data.refs&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Plug that into your config and you’ll be off and running with passing E2E tests. ✅&lt;/p&gt;

</description>
      <category>cypress</category>
      <category>prismic</category>
      <category>e2etesting</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
