Why do I keep getting this error using the gmailr package? (I attached code below the error)

18 Views Asked by At
Error in gmailr_GET(c("messages", id), user_id, class = "gmail_message",  : 
  Gmail API error: 404
  Requested entity was not found.

I'm getting the above error with the following code:

gm_auth_configure(path = "[CTE]GmailCredentials.json")
gm_auth(email = T, cache = ".secret")
# Set API key for gptstudio
#Sys.setenv(OPENAI_API_KEY = Sys.getenv("OPENAI_API_KEY"))

contacts <- read_csv("./[FINAL] UNC Contacts List.csv", show_col_types = F)
contacts_grouped <- contacts %>% 
  filter(!is.na(Email)) %>%
  group_by(Organization) %>% 
  summarise(Emails = paste(Email, collapse = ", "))

# Function to check for sending limit reached
check_for_sending_limit_reached <- function() {
  my_messages <- gm_threads(num_results = 10) # Adjust num_results as needed
  for (msg_id in gm_id(my_messages)) {
    message <- gm_message(msg_id)
    if (any(grepl("You have reached a limit for sending mail. Your message was not sent.", gm_body(message), fixed = TRUE))) {
      return(TRUE) # Sending limit indication found
    }
  }
  return(FALSE) # No sending limit indication found
}

start_index <- match("HackNC", contacts_grouped$Organization)
contacts_grouped[956,]
start_index <- 960
for(i in start_index:nrow(contacts_grouped)) {
  if (i %% 5 == 0 && check_for_sending_limit_reached()) {
    print("Limit for sending mail has been reached. Halting email sending.")
    break # Stop the loop if a sending limit is reached
  }
  to <- contacts_grouped$Emails[i]
  organization <- contacts_grouped$Organization[i]

  send = "FILLED IN"
  my_name <- "FILLED IN"
  my_email <- "FILLED IN"
    
  email <- gm_mime() %>%
    gm_to(to) %>%
    gm_from(send) %>%
    gm_subject("Group Booking Opportunity at Chapel Thrill Escapes") %>%
    gm_attach_file("/Users/riley/Downloads/cte_tri_color (1).png", type = "image/png", id = "YourImageContentID") %>%
    gm_html_body(paste0("<html>
    <head>
    <style>
    body { 
      font-family: 'Times New Roman', Times, serif; 
      font-size: 12pt; 
      color: black; 
    }
    </style>
    </head>
    <body>
      <p>Good Evening,</p>
      
      <p>My name is ", my_name, ", and I am the CEO of Chapel Thrill Escapes–a student-run escape room experience based on-campus at UNC-Chapel Hill. We're planning to launch a brand new location on Franklin Street and will be holding a launch event with the Chamber For a Greater Chapel Hill-Carrboro on February 16th from 5 to 6:30 pm  at the new location (128 E Franklin St, Suite 110) to celebrate. We want to open this launch event to any UNC students or faculty who are interested in attending, and we will be catering the event with free food for those in attendance. It'd be great if you could send this out to ", organization, " members and to ask them to fill out our RSVP form for the event linked <a href=''>here</a> () or our application <a href= ''>here</a> () if they're interested in joining the team.</p>
      
      <p>Also, I am reaching out to offer ", organization, " an exciting and unique team-building opportunity for either your leadership team or members through a group booking. Our escape rooms are designed to challenge and engage participants, promoting teamwork, problem-solving, and a healthy dose of fun. They provide an excellent way for your team to bond and develop essential skills in a thrilling environment.</p>
      
      <h3>Group Booking Details:</h3>
      <ul>
        <li><strong>Date & Time:</strong> We are flexible and can accommodate your schedule. Please let us know your preferred dates and times.</li>
        <li><strong>Group Size:</strong> Our rooms can accommodate groups of 8 people at a time. For larger groups, we can organize multiple rooms.</li>
        <li><strong>Special Arrangements:</strong> If you have any specific requirements or requests, we are more than happy to discuss further over Zoom or email.</li>
      </ul>
      <h3>Booking Process:</h3>
      <ol>
        <li>Choose your preferred date and time <a href='https://www.chapelthrillescapes.com/wonderland/book'>here</a>.</li>
        <li>We will confirm availability.</li>
        <li>Once confirmed, we will provide you with all the necessary information and preparations for your adventure.</li>
      </ol>
      <h3>Why Choose Chapel Thrill Escapes?</h3>
      <ul>
        <li>Unique, immersive, and <strong>affordable</strong> escape room experiences.</li>
        <li>Perfect for team-building, enhancing communication, and leadership skills.</li>
        <li>Professionally designed challenges that cater to all skill levels.</li>
        <li>Convenient location and flexible scheduling.</li>
      </ul>
      <p>We would be delighted to host ", organization, " at Chapel Thrill Escapes. This is a great opportunity for your team to step out of their regular environment and engage in a unique, fun, and intellectually stimulating experience. To proceed with the booking or if you have any questions, please feel free to contact our executive team at ", my_email, ". We are also available to discuss any specific requirements or customization you might need to make your group’s experience truly memorable. Thank you for considering Chapel Thrill Escapes for your team-building event. We look forward to the possibility of hosting you and providing an unforgettable escape room adventure.</p>
      <p>Best,</p>
      <p><strong>", my_name, "</strong><br>
      CEO of Chapel Thrill Escapes<br>
      <p></p>
      <a href='https://www.chapelthrillescapes.com/'><img src='cid:YourImageContentID' width='100'></a><br>
      <strong>Chapel Thrill Escapes</strong><br>
      <strong>Address:</strong> 100 Country Club Rd,<br> Chapel Hill, NC 27514</p>
      <strong>Primary Email:</strong> <a href='mailto:[email protected]'>[email protected]</a><br>
      <strong>Secondary Email:</strong> <a href='mailto:[email protected]'>[email protected]</a><br>
      <strong>Website:</strong> <a href='https://www.chapelthrillescapes.com/'>chapelthrillescapes.com</a>
    </body>
    </html>"))
  gm_send_message(email)
}
print(paste("Last emailed group index:", i - 21))

The code above worked for many previous emails but stopped as of today. I am not meeting or exceeding the API limits–I've checked Google Cloud Console. What else could be causing this issue?

0

There are 0 best solutions below