# songwhip-appreciation-engine

A wrapper service around the Appreciation Engine (AE) API. Built specifically for Songwhip to create/setup AE Brands/Segments for a prerelease Album page and then push Members (fans) into the Segment to opt them in to "Social Listening". It uses [songwhip-queue](https://github.com/theorchard/songwhip-queue) to ensure that failed requests are retried.

## Prerequisites

- Node.js configured repo\
  https://www.notion.so/Node-js-project-setup-guide-86feadffeb304962b06e6b1bb8f09213
- Vercel CLI (for `yarn dev`)

## Setup

Add the Vercel cli globally

```bash
yarn global add vercel
```

## Async API

We expose both a "sync" and "async" APIs. Async APIs use [songwhip-queue](https://github.com/theorchard/songwhip-queue) to make the request to ensure that if/when the Appreciation Engine API is down the request is retried. **In production you should always use the `/async/…` APIs**.

### Create a new Segment (async)

Create (or update) Brand (artist) and Segment (campaign) to push Members into after they complete oauth.

`PUT /async/segments`

### Push a fan into a Segment (async)

Add (or update) a member/fan to a Brand's Segment.

`PUT /async/segments/:segmentId/members`

## ProTip: Testing the `callbackUrl`

A handy way to test if the `callbackUrl` is working is to use requestbin.com ([create new bin](https://public.requestbin.com/r)). Use the given endpoint as the `callbackUrl` and you'll be able to inspect the response in real-time the console 😎
