Skip to content

Commit

Permalink
Mailjet API post-contact Server Action and Next.js Environment Variables
Browse files Browse the repository at this point in the history
  • Loading branch information
15Dkatz committed Jul 7, 2023
1 parent e5c1767 commit 15f78aa
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/connect/email-list/post-contact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use server';

const apiKey = process.env.API_KEY;
const secretKey = process.env.SECRET_KEY;

export default async function postContact({ name, email }) {
const url = 'https://api.mailjet.com/v3/REST/contact';
const body = JSON.stringify({ name, email, isExcludedFromCampaigns: true });
const headers = {
'Content-Type': 'application/json',
'Authorization': `Basic ${Buffer.from(apiKey + ":" + secretKey).toString('base64')}`
};

const response = await fetch(url, { method: 'POST', headers, body });
const json = await response.json();

console.log(`json`, json);
return json;
}

0 comments on commit 15f78aa

Please sign in to comment.