Log daily Loop returns to Sheets and flag big refunds

By General Input

Every morning at 6am, yesterday's Loop returns land in your spreadsheet, and any refund above your limit opens a support ticket for a human.

Integrations

  • Loop Returns
  • Google Sheets
  • Gorgias

Type

Deterministic Code

Categories

  • Operations
  • Customer Support

Every morning at 6am, pull the previous 24 hours of returns from Loop Returns, append one row per return to a Google Sheets log, and open a Gorgias ticket for any return whose refund is above a threshold I set. Every step here is a fixed field mapping plus one threshold check, so build it as a deterministic code workflow rather than an agent.

Trigger: a cron schedule, once a day at 6am in my local timezone. Loop Returns is not available as a polling source on this platform, so cron plus a list call inside the workflow is the right shape.

Step one, fetch the returns. Call the Loop Returns Detailed Returns List operation with no from or to values, because that endpoint already defaults to the previous 24 hours, which lines up exactly with a daily 6am run. Pass paginate=true and a pageSize of 250 so a busy day is not truncated (the default page size is 100 and the max is 750), then keep following nextPageUrl until it comes back null. Loop allows 300 requests per minute per API key and returns a 429 when you exceed it, so pause briefly and retry rather than failing the run.

Step two, normalize each return into a row. Loop reports money as a MoneySet, an integer amount in minor units plus a currency code, so divide the refund amount by 100 before writing it and keep the currency code in its own column. Collapse the line items into a single readable cell, for example: 2 x Merino Crew Sweater, 1 x Wool Socks. Where a return has different reasons across its items, join the distinct reasons with a comma. The columns, in order, are: Return ID, Order Name, Customer Email, Items, Return Reason, Refund Amount, Currency, Status.

Step three, write the rows. Use the Google Sheets Append Values operation to append the whole day's rows in a single call to the returns log tab, below the existing header row rather than overwriting it. Use valueInputOption USER_ENTERED so refund amounts land as numbers rather than text. If there were no returns in the window, write nothing and finish cleanly.

Step four, flag the high-value refunds. Define the threshold as an editable constant at the top of the workflow, expressed in major units (default it to 200), not buried inside a node, so I can change it without touching the logic. For every return whose converted refund amount is at or above that threshold, call the Gorgias Create Ticket operation. Use a subject in the form: High-value return: {order name} ({refund amount} {currency}). The body should restate the return id, order name, customer email, items, return reason, refund amount and currency, and the current return status, then close with a line asking the assigned agent to reach out to the shopper personally before the refund lands. Create the ticket with an internal note message so nothing is emailed to the shopper automatically, and set the ticket customer to the shopper's email so it threads onto their existing Gorgias record.

Gorgias rate limits API key integrations to 40 requests per 20 second window and sends back a Retry-After header when you cross it, so space out ticket creation on a heavy day instead of firing them all at once.

Keep the Loop return id in the first column so that if I ever re-run the workflow by hand, duplicate rows are obvious and easy to clean up.

Related prompts

Explore more prompts
Call overdue Xero customers with an AI collections agentLocal listing health board for every location you manageLet support send one-off Loops emails without an engineerStop cold emails to anyone with a live deal in PipedriveiMessage campaign console with pre-flight checks and delivery boardLinkedIn Ads budget pacing dashboard for every client accountFront desk appointment confirmation board for the next 3 daysGive your team Looker numbers without buying more seatsBuild audience segments from product usage and push to LoopsTurn the people who engage with your posts into Pipedrive leads