Olá, estou tentando mandar o value pego de um formulário pra uma API no JS.
Aqui eu quero usar o cardID e o userToken
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Deletar Card</title>
</head>
<body>
<section>
<form id="deleta-card" method="post" action="#">
<div>
<label for="card-id">ID do Card</label><br>
<input id="card-id" name="cardId" type="number" class="campo">
</div>
<div>
<label>User Token</label><br>
<textarea name="userToken"></textarea>
</div>
<button id="deletar-card" class="botao-principal" type="submit">Deletar</button>
</form>
</section>
<script>
var botaoDeletar = document.querySelector("#deletar-card")
botaoDeletar.addEventListener("click", function() {
event.preventDefault();
var form = document.querySelector("#deleta-card");
var cardId = form.cardId.value;
var userToken = form.userToken.value;
});
var request = new XMLHttpRequest();
request.open('POST', 'https://app.pipefy.com/queries');
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestHeader('Authorization', 'Bearer USAR_userToken_AQUI');
request.onreadystatechange = function () {
if (this.readyState === 4) {
console.log('Status:', this.status);
console.log('Headers:', this.getAllResponseHeaders());
console.log('Body:', this.responseText);
}
};
var body = {
'query': 'mutation{ deleteCard(input: {id: USAR_cardId_AQUI}) { success } }'
};
request.send(JSON.stringify(body));
</script>
</body>
</html>
Alguém pode me ajudar?