-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mailjet API post-contact Server Action and Next.js Environment Variables
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |