Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ConvertKit Commerce #11

Open
jsjoeio opened this issue Apr 16, 2021 · 0 comments
Open

Add support for ConvertKit Commerce #11

jsjoeio opened this issue Apr 16, 2021 · 0 comments

Comments

@jsjoeio
Copy link
Owner

jsjoeio commented Apr 16, 2021

I may not need this if I switch to Flurly, but documenting regardless.

Notes

  1. Login to https://app.convertkit.com/
  2. Grab cookie with key ajs_anonymous_id
  3. Make a fetch call to https://app.convertkit.com/purchases/reports
async function getPurchases() {
  const response = await fetch("https://app.convertkit.com/purchases/reports", {
    headers: {
      accept: "application/json",
      "accept-language": "en-US,en;q=0.9",
      "content-type": "application/json",
      "sec-ch-ua":
        '"Google Chrome";v="89", "Chromium";v="89", ";Not A Brand";v="99"',
      "sec-ch-ua-mobile": "?0",
      "sec-fetch-dest": "empty",
      "sec-fetch-mode": "cors",
      "sec-fetch-site": "same-origin",
      "x-csrf-token":
        "redacted",
      cookie:
        "ajs_anonymous_id=<REPLACE-WITH-COOKIE-VALUE>",
    },
    referrer: "https://app.convertkit.com/",
    referrerPolicy: "strict-origin-when-cross-origin",
    body:
      '{"report":{"starting":"2021-04-01","ending":"2021-04-16","interval":"1d","currency":"USD"}}',
    method: "POST",
    mode: "cors",
  })

  const json = await response.json()
  console.log(json)
}

getPurchases()

Response looks like this:

{
  aggregations: true,
  currencies: { all: [ "USD" ], selected: "USD" },
  products: [
    {
      id: 3467430,
      name: "Test Product",
      account_id: 276438,
      created_at: "2020-08-20T18:39:55.000Z",
      updated_at: "2020-08-20T18:39:55.000Z",
      pid: "c4582260-8cb4-4245-901d-a7781867c1c5",
      integration_id: 34082,
      data: {}
    },
    {
      id: 3479594,
      name: "OLD Vim for VSCode Exercise Pack",
      account_id: 276438,
      created_at: "2020-09-01T15:01:33.000Z",
      updated_at: "2020-09-02T04:33:43.000Z",
      pid: "d16a9a3d-3735-41c4-8323-e139cc32ace1",
      integration_id: 34082,
      data: {}
    },
    {
      id: 3480555,
      name: "Vim for VSCode ",
      account_id: 276438,
      created_at: "2020-09-01T19:59:25.000Z",
      updated_at: "2021-04-09T01:35:21.000Z",
      pid: "15516d2b-3b84-4f3c-85cf-e348d811187a",
      integration_id: 34082,
      data: {}
    },
    {
      id: 3699621,
      name: "Product or Tool Feedback",
      account_id: 276438,
      created_at: "2021-02-24T14:33:26.000Z",
      updated_at: "2021-02-24T14:33:26.000Z",
      pid: "0763ea91-d165-4a24-a69b-95643640bcb1",
      integration_id: 34082,
      data: {}
    },
    {
      id: 3733046,
      name: "Speaking Engagement",
      account_id: 276438,
      created_at: "2021-03-16T13:45:26.000Z",
      updated_at: "2021-03-16T13:45:26.000Z",
      pid: "f3c466d7-a22b-4be2-815a-1f30732ead84",
      integration_id: 34082,
      data: {}
    }
  ],
  purchases: {
    "2021-04-01T00:00:00.000Z": { count: 1, total: 2000, products: [ [Object] ] },
    "2021-04-02T00:00:00.000Z": { count: 2, total: 4000, products: [ [Object] ] },
    "2021-04-03T00:00:00.000Z": { count: 3, total: 5500, products: [ [Object] ] },
    "2021-04-04T00:00:00.000Z": { count: 1, total: 1500, products: [ [Object] ] },
    "2021-04-05T00:00:00.000Z": { count: 9, total: 17500, products: [ [Object] ] },
    "2021-04-06T00:00:00.000Z": { count: 3, total: 5500, products: [ [Object] ] },
    "2021-04-07T00:00:00.000Z": { count: 5, total: 9500, products: [ [Object] ] },
    "2021-04-08T00:00:00.000Z": { count: 2, total: 3500, products: [ [Object] ] },
    "2021-04-09T00:00:00.000Z": { count: 4, total: 8000, products: [ [Object] ] },
    "2021-04-10T00:00:00.000Z": { count: 2, total: 3500, products: [ [Object] ] },
    "2021-04-11T00:00:00.000Z": { count: 0, total: 0, products: [] },
    "2021-04-12T00:00:00.000Z": { count: 2, total: 3500, products: [ [Object] ] },
    "2021-04-13T00:00:00.000Z": { count: 4, total: 7500, products: [ [Object] ] },
    "2021-04-14T00:00:00.000Z": { count: 1, total: 1500, products: [ [Object] ] },
    "2021-04-15T00:00:00.000Z": { count: 1, total: 2000, products: [ [Object] ] },
    "2021-04-16T00:00:00.000Z": { count: 2, total: 4000, products: [ [Object] ] }
  },
  refunds: { "2021-04-07T00:00:00.000Z": { count: 1, total: 2000, products: [ [Object] ] } },
  subscriptions: {},
  stats: {
    total: {
      total: "$840.00",
      average: "$20.00",
      purchase_count: 42,
      refunds_count: 1,
      refunds_amount: "$20.00"
    },
    today: {
      total: "$40.00",
      average: "$20.00",
      purchase_count: 2,
      refunds_count: 0,
      refunds_amount: "$0.00"
    }
  }
}

Fetch request will need body payload too:

{
  report: {
    "starting": "2021-04-01",
    "ending": "2021-04-16",
    "interval": "1d",
    "currency": "USD"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant