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

chore: brevo manual api calls adjust #509

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions brevo-scripts/brevo-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ async function execute({ method, path, query = null, body = null }) {
const response = await fetch(url.href, {
method: method,
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"api-key": process.env.BREVO_API_KEY,
Accept: 'application/json',
'Content-Type': 'application/json',
'api-key': process.env.BREVO_API_KEY,
},
body: body ? JSON.stringify(body) : null,
});
Expand All @@ -21,24 +21,24 @@ async function execute({ method, path, query = null, body = null }) {
try {
return JSON.parse(body);
} catch (e) {
return body;
return response;
}
}
} catch (e) {
console.error(e);
console.log({
extra: { url: `${BREVO_ENDPOINT}${path}`, method, path, query },
level: "error",
level: 'error',
});
}
return response;
}

const BrevoApi = {
get: async (args) => execute({ ...args }),
put: async (args) => execute({ method: "PUT", ...args }),
post: async (args) => execute({ method: "POST", ...args }),
remove: async (args) => execute({ method: "DELETE", ...args }),
put: async (args) => execute({ method: 'PUT', ...args }),
post: async (args) => execute({ method: 'POST', ...args }),
remove: async (args) => execute({ method: 'DELETE', ...args }),
};

export default BrevoApi;
18 changes: 9 additions & 9 deletions brevo-scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ https://developers.brevo.com/reference/updatecampaignstatus
// TIP ids are in the form 9967, 9966, etc.
// So we don'tneed to fetch the campaigns abov

// for (let i = 7791; i > 0; i--) {
// await new Promise((resolve) => setTimeout(resolve, 1000));
// const result = await BrevoApi.put({
// path: `/emailCampaigns/${i}/status`,
// body: { status: 'archive' },
// });
// if (result === 429) break;
// console.log(i, result);
// }
for (let i = 9120; i > 0; i--) {
const result = await BrevoApi.put({
path: `/emailCampaigns/${i}/status`,
body: { status: 'archive' },
});
if (result?.status === 429) break;
console.log({ i, result });
await new Promise((resolve) => setTimeout(resolve, 50000));
}

// const listIds = [];

Expand Down
Loading