hello, I want to use PRISMIC to save LEADS from a website. but I'm having trouble doing the POST. Can anyone who has done this help?
import React, { useState } from 'react'
import axios from 'axios'
const PrismicPostExample = () => {
const [title, setTitle] = useState('')
const [content, setContent] = useState('')
const handlePostSubmit = async e => {
e.preventDefault()
const apiUrl = 'https://porfotlio.cdn.prismic.io/api/v2'
const accessToken =
'MC5aT3VjZUJFQUFDWUF4V2ox.Tu-_vSXvv710J--_ve-_vTXvv73vv73vv70x77-9SO-_vThK77-977-9Fu-_vUpj77-977-9Mg4ibe-_ve-_vQ'
const endpoint = 'contato'
const postData = {
type: 'contato',
lang: 'pt-br',
fields: {
title: [{ type: 'heading1', text: title }],
content: [{ type: 'paragraph', text: content }]
}
}
try {
const response = await axios.post(`${apiUrl}/${endpoint}`, postData, {
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${accessToken}`
}
})
console.log('Documento criado:', response.data)
} catch (error) {
console.error('Erro ao criar o documento:', error)
}
}
return (
<div>
<h2>Criar novo documento</h2>
<form onSubmit={handlePostSubmit}>
<label>
TÃtulo:
<input
type="text"
value={title}
onChange={e => setTitle(e.target.value)}
/>
</label>
<br />
<br />
<button type="submit">Enviar</button>
</form>
</div>
)
}
export default PrismicPostExample
in this test component, I am having CORS error
the component in question has a very simple structure, because I want to make the post work to later scale in other components.