Integration recipe
Daily pixPLace stats in Pipedream
A Pipedream code step reads your account statistics for the last 7 days every morning and passes the daily series on.
Who it is for
People who run workflows in Pipedream and want their pixPLace numbers in Slack, a sheet or an email.
What it automates
Read the growth of your account per day (posts, likes, comments, new followers) every morning and pass the series to the next step.
Steps
- Create a workflow with a Schedule trigger, for example every day at 08:00.
- Store the API key as the environment variable PIXPLACE_API_KEY in the Pipedream project settings.
- Add a Node.js code step with the code below. It calls GET /api/v1/account/stats for the last 7 days and exports the series.
- Add a Slack, email or spreadsheet step that uses steps.stats.$return_value. Metrics the platform does not collect are listed in data.unavailable and have no numbers.
- When you create the key, tick the `read` scope. A key without it gets 403 insufficient_scope on these calls.
Example
Placeholders: ppk_live_XXXXXXXX is your key. The ids and the image address are samples. The API address is always https://pixplace.space/api/v1.
Code step "stats"
export default defineComponent({
async run({ steps, $ }) {
const day = 86400000;
const to = new Date().toISOString().slice(0, 10);
const from = new Date(Date.now() - 6 * day).toISOString().slice(0, 10);
const url = `https://pixplace.space/api/v1/account/stats?from=${from}&to=${to}&granularity=day`;
const res = await fetch(url, { headers: { Authorization: `Bearer ${process.env.PIXPLACE_API_KEY}` } });
if (!res.ok) throw new Error(`pixPLace answered ${res.status}: ${await res.text()}`);
const { data } = await res.json();
$.export("period", data.period);
return data.series;
},
});Common errors
| Status | Cause | What to do |
|---|---|---|
| 400 | The range is invalid: from is after to, a date is not YYYY-MM-DD, the range is longer than the maximum, or granularity is not day. | Keep the range short as in the example and use only granularity=day. |
| 401 | The API key is missing, malformed, revoked or sent in the wrong header. | The environment variable is empty or has another name. Check that it is called PIXPLACE_API_KEY and that the workflow was deployed after you saved it. The header must read Authorization: Bearer followed by your ppk_live_ key. Check the key in Settings → Developer. |
| 403 | The key lacks a scope the call needs: the answer is 403 with error.code insufficient_scope and the missing scope in error.required. | Create a new key in Settings → Developer with the `read` scope ticked and use it instead; repeating the call with the same key fails the same way. |
| 503 | The database is momentarily unavailable. The answer carries Retry-After: 5. | Reading is safe to repeat: run the step again. The code above throws, so the run shows red and you can replay it. |
The full list of statuses, the retry rules and the limits are in Errors and retries.