Please tell me if there is any way to start workflow through own button or toggle switch?
import React, { useState, useEffect } from 'react';
import {
Button,
Text,
hubspot,
} from '@hubspot/ui-extensions';
hubspot.extend(({actions}) => (
<Extension
fetchProperties={actions.fetchCrmObjectProperties}
/>
));
const Extension = ({ fetchProperties }) => {
const post = "https://api.hubapi.com/automation/v2/workflows/:workflowsID/enrollments/contacts/";
const [email, setemail] = useState("");
useEffect(() => {
fetchProperties(["email"])
.then(properties => {
setemail(properties.email);
});
}, [fetchProperties]);
function myOnClickFunction() {
fetch(post + email, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': 'Bearer TOKEN',
'Content-Type': 'application/json',
'Content-Length': '0',
},
});
}
return (
<><Text>Post:{email} </Text><Button onClick={myOnClickFunction}>Enroll</Button></>
);
}