This app showcases how a web application split into 2 projects can interact with Deel API to create a fixed-rate contract, sign it, and then invite a contractor to sign it.
The app has 2 projects:
- Client: Front-end application created using Create React App
- Server: Backend using Node.JS Express
This page showcases how to create an individual contractor fixed-rate contract. It only includes the required fields to make the API call successfully. To create a contract:
- Fill all the fields.
- Click Create contract.
If the call is successful and alert will be displayed with the Contract ID. Make a note of it, because you can use that to sign the contract and invite the contractor to sign it.
More info:
This page showcases how to sign a contract that was previously created. It only includes the required fields to make the API call successfully. To sign the contract:
- Fill all the fields.
- Click Sign contract.
If the call is successful an alert will be displayed.
More info:
This page showcases how to invite a contractor to sign a contract that you previously signed. It only includes the required fields to make the API call successfully. To invite a contractor:
- Fill all the fields.
- Click Invite contractor.
If the call is successful, an alert will be displayed.
More info:
- A Deel API token. You can generate a new token following the instructions in API tokens.
- Node.js v18+.
After installing Node.js and retrieving a valid token, you can install the dependencies:
- Open a command-line window and navigate to to the sample directory
samples/create-ic-fixed-rate-contract/
. - Run
npm install
. - Then run
npm run setup
.
API_HOST
- Deel API URL that is used by application.- By default, we're using
https://api-sandbox.demo.deel.com
.
- By default, we're using
API_TOKEN
- Deel API token mentioned in Prerequisites.- The token should be generated in the same environment used by
API_HOST
.
- The token should be generated in the same environment used by
- Save the API token generated in the variable
API_TOKEN
in/server/.env
- Navigate to project directory
samples/create-ic-fixed-rate-contract/client
and runnpm run start
. - Navigate to the server directory with
samples/create-ic-fixed-rate-contract/client
and runnpm run start
.
A browser should open automatically at http://localhost:3098
.
- Navigate to the application directory
samples/create-ic-fixed-rate-contract
. - Run
npm run start
.
A browser should open automatically at http://localhost:3098
.
const getHeaders = () => ({
'Authorization': `Bearer ${process.env.API_TOKEN}`,
'Content-Type': 'application/json'
});
app.post('/api/contracts', async (req, res) => {
const payload = {
data: {...}
};
try {
const response = await axios.post(`${process.env.API_HOST}/rest/v2/contracts`, payload, {
headers: getHeaders(),
});
res.json(response.data.data);
} catch(err) {
return handleError(err, res);
}
});
const payload = {
data: {
...req.body
}
};
const response = await axios.post(`${process.env.API_HOST}/rest/v2/contracts/${req.params.id}/signatures`, payload, {
headers: getHeaders(),
});
res.json(response.data);
const payload = {
data: {
...req.body
}
};
const response = await axios.post(`${process.env.API_HOST}/rest/v2/contracts/${req.params.id}/invitations`, payload, {
headers: getHeaders(),
});
res.json(response.data);