Creer un ticket sur Azure React

Par tarikm, il y a 2 ans


Javascript React

Décrivez ici votre problème ou ce que vous cherchez à faire.

je veux crrer un ticket sur Azure dev-Ops (de type Bug) depuis mon interface React , mais ça marche pas : import React from "react"; import axios from 'axios'; import { useState } from "react"; const CreateTicketForm = () => { const [title, setTitle] = useState(''); const [description, setDescription] = useState(''); const createTicket = async () => { const url = 'https://dev.azure.com/Covage/Portail%20Support/_apis/wit/workitems/$Bug?api-version=7.0'; const personalAccessToken ='MON PAT'; // Remplacez par votre Personal Access Token const ticketData = [ { op: 'add', path: '/fields/System.Title', value: 'Nouveau ticket' }, { op: 'add', path: '/fields/System.Description', value: 'Description du ticket' }, { op: 'add', path: '/fields/System.AreaPath', value: 'MonProjet\\MonEspaceDeTravail' }, { op: 'add', path: '/fields/System.IterationPath', value: 'MonProjet\\Iteration1' }, { op: 'add', path: '/fields/System.AssignedTo', value: 'Utilisateur1' }, { op: 'add', path: '/fields/System.Tags', value: 'Ticket, Urgent' }, { op: 'add', path: '/fields/CustomField1', value: 'Valeur personnalisée' } ]; try { console.log("test1") const response = await axios.post(url, ticketData, { headers: { 'Content-Type': 'application/json-patch+json', Authorization: `Bearer ${personalAccessToken}`, }, }); console.log("test1") console.log(response.data); // Réponse de la requête POST } catch (error) { console.error(error); } }; const handleSubmit = (e) => { e.preventDefault(); createTicket(); }; return ( <form onSubmit={handleSubmit}> <div> <label htmlFor="title">Titre :</label> <input type="text" id="title" value={title} onChange={(e) => setTitle(e.target.value)} /> </div> <div> <label htmlFor="description">Description :</label> <textarea id="description" value={description} onChange={(e) => setDescription(e.target.value)} ></textarea> </div> <button type="submit">Créer le ticket</button> </form> ); } export default CreateTicketForm;

Ce que je veux

creer un ticket
Ce que j'obtiens

j'obtiens un 302 alors que mon PAT est valide

1 réponse

Grafikart, il y a 2 ans

Si tu recois une 302 c'est une redirection tu ne devrais pas la suivre non ? Je ne connais pas Azure