# Prismic::SearchForm::AuthorizationException

**URL:** <https://community.prismic.io/t/prismic-authorizationexception/9359>\
**Category:** Developing with Prismic\
**Tags:** ruby\
**Created:** [March 15, 2022, 10:20am UTC](https://community.prismic.io/t/prismic-authorizationexception/9359 "2022-03-15T10:20:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohamed](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/mohamed/32/5734_2.png) [@mohamed](https://community.prismic.io/u/mohamed)\
**Post date:** [March 15, 2022, 10:20am UTC](https://community.prismic.io/t/prismic-authorizationexception/9359/1 "2022-03-15T10:20:21Z")

</div>

I don't get this error. It appears randomly when I make calls:

```ruby
Prismic::SearchForm::AuthorizationException: Prismic::SearchForm::AuthorizationException

```

I'm using the ruby gem [prismic.io | RubyGems.org | your community gem host](https://rubygems.org/gems/prismic.io)

My configuration is:

```ruby
CACHE = Prismic::BasicNullCache.new.freeze
ACCESS_TOKEN = "..."
api = Prismic.api(
  "https://your-repo-name.cdn.prismic.io/api",
  access_token: ACCESS_TOKEN,
  api_cache: CACHE,
  cache: CACHE
)

```

---

<div class="post-metadata">

**Author:** ![Phil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/phil/32/14_2.png) [@Phil](https://community.prismic.io/u/Phil)\
**Post date:** [March 15, 2022, 12:26pm UTC](https://community.prismic.io/t/prismic-authorizationexception/9359/2 "2022-03-15T12:26:37Z")

</div>

Hi Mohamed,

My guess is because you are caching the content from Prismic, this isn't recommended as you will get this error and outdated content using old master refs.

> [@Prismic data caching](https://community.prismic.io/t/prismic-data-caching/437/6):
>
> Hey Dmitry, Yes, we don’t recommend using a caching system as this can cause issues when the master ref is changed on every document update, this can cause websites to break. Make sure you are using your CDN endpoint to offer your website extra protection and speed, for example [https://your-repo-name.cdn.prismic.io/api/v2](https://your-repo-name.cdn.prismic.io/api/v2). Also like Paulina said the platform is very stable. We have exceeded the Uptime of 99.9% for the past 26 consecutive months and are committed to maintaining this standard.

Thanks.

---

<div class="post-metadata">

**Author:** ![mohamed](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/mohamed/32/5734_2.png) [@mohamed](https://community.prismic.io/u/mohamed)\
**Post date:** [March 15, 2022, 1:54pm UTC](https://community.prismic.io/t/prismic-authorizationexception/9359/4 "2022-03-15T13:54:52Z")

</div>

Hello Phil,

I don't use caching, that is why I have this line of code `CACHE = Prismic::BasicNullCache.new.freeze`

I saw that you are mentioning the API v2 (`https://your-repo-name.cdn.prismic.io/api/v2`),  
while I'm mentioning the API v1 (`https://your-repo-name.cdn.prismic.io/api`).

I change my code to use the API v2:

```ruby
CACHE = Prismic::BasicNullCache.new.freeze
ACCESS_TOKEN = "..."
api = Prismic.api(
  "https://your-repo-name.cdn.prismic.io/api/v2",
  access_token: ACCESS_TOKEN,
  api_cache: CACHE,
  cache: CACHE
)

```

But the [gem](https://rubygems.org/gems/prismic.io) doesn't work with this version of the API.  
It's totally broken.

---

<div class="post-metadata">

**Author:** ![Phil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/phil/32/14_2.png) [@Phil](https://community.prismic.io/u/Phil)\
**Post date:** [March 15, 2022, 3:38pm UTC](https://community.prismic.io/t/prismic-authorizationexception/9359/5 "2022-03-15T15:38:19Z")

</div>

That's correct the ruby gem uses version 1 of the API.

Have you set your repository to private?

How are you passing the master ref?

---

<div class="post-metadata">

**Author:** ![mohamed](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/mohamed/32/5734_2.png) [@mohamed](https://community.prismic.io/u/mohamed)\
**Post date:** [March 16, 2022, 9:10am UTC](https://community.prismic.io/t/prismic-authorizationexception/9359/6 "2022-03-16T09:10:21Z")

</div>

I found the issue. I was saving the connetion (`Prismic.api(...)`) inside a variable, like so:

```ruby
@api ||= Prismic.api(...)

```

and this `@api` variable had the wrong `ref` when we updated documents.

Solution:

```ruby
@api = Prismic.api(...)

```

---

<div class="post-metadata">

**Author:** ![Phil](https://dub1.discourse-cdn.com/flex013/user_avatar/community.prismic.io/phil/32/14_2.png) [@Phil](https://community.prismic.io/u/Phil)\
**Post date:** [March 16, 2022, 11:00am UTC](https://community.prismic.io/t/prismic-authorizationexception/9359/7 "2022-03-16T11:00:33Z")

</div>

Great, I'm glad you were able to figure this issue out. 🙂
