I checked the json and i connected to sendinblue helpdesk, but i can’t to compose a valid json. I think this is problem not in my code, i think this problem in your configurating of json or interface of fetch. In console i get a following message:
{"error":{"status":400,"message":"Input must be a valid JSON object","code":"bad_request"}}
I have following js module:
import {fetch} from 'wix-fetch';
export function sendWithService(key, senderMail, recipient, subject, body) {
const url = 'https://api.sendinblue.com/v3/smtp/email';
const headers = {
"content-type": "application/json",
"api-key": key
};
const sender = {
"email" : senderMail
};
const to= [{
"email" : recipient,
"name" : "Product Advice"
}];
const replyTo = {
"email" : senderMail,
"name" : "Product Advice"
};
const data = {
"sender" : sender,
"to" : to,
"htmlContent": body,
"subject": subject,
"replyTo" : replyTo,
};
const request = {
"method": "POST",
"headers": headers,
"body": data
};
console.log(request);
return fetch(url, request)
.then(response => response.json());
}
Referense information about API of transactional email can be found in Getting started
Please, help me understand this.
Correctly code, which work good:
import {fetch} from 'wix-fetch';
export function sendWithService(key, senderMail, recipient, subject, body) {
const url = 'https://api.sendinblue.com/v3/smtp/email';
const headers = {
"content-type": "application/json",
"api-key": key
};
const sender = {
"email" : senderMail
};
const to= [{
"email" : recipient,
"name" : "Product Advice"
}];
const replyTo = {
"email" : senderMail,
"name" : "Product Advice"
};
const data = {
"sender" : sender,
"to" : to,
"htmlContent": body,
"subject": subject,
"replyTo" : replyTo,
};
const request = {
"method": "POST",
"headers": headers,
"body": JSON.stringify(data)
};
return fetch(url, request)
.then(response => response.json());
}