Skip to content

Commit

Permalink
chore: brevo manual api calls adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudambro committed Apr 4, 2024
1 parent cef837f commit 7347aa9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
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

0 comments on commit 7347aa9

Please sign in to comment.