Could not create expenses

const https = require('https');
const url = 'https://integrations.expensify.com/Integration-Server/ExpensifyIntegrations';
const requestBody = {
requestJobDescription: JSON.stringify({
type: 'create',
credentials: {
"partnerUserID": "USERID",
"partnerUserSecret": "SECRET"
},
inputSettings: {
"type": "expenses",
"employeeEmail": "[email protected]",
transactionList: [
{
"created": "2016-01-01",
"currency": "USD",
"merchant": "Stipre",
"amount": 120
},
{
"created": "2016-01-21",
"currency": "EUR",
"merchant": "Deel",
"amount": 600,
"policyID": "E40D9B8DF456E233",
"tax": {
"rateID": "id_TAX_OPTION_16"
}
},
{
"created": "2016-01-31",
"currency": "CAD",
"merchant": "Expensify",
"amount": 700,
"reportID": "R006AseGxMka",
"tax": {
"rateID": "id_TAX_OPTION_16",
"amount": 600
}
}
],
},
}),
};
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
};
const req = https.request(url, options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log('Response Data:', JSON.parse(data));
});
});
req.on('error', (error) => {
console.error('Request Error:', error);
});
req.write(JSON.stringify(requestBody));
req.end();
I am getting below error
Response Data: {
responseMessage: "'requestJobDescription' is missing",
responseCode: 500
}
Answers
-
I tried differently that worked
const url = "https://integrations.expensify.com/Integration-Server/ExpensifyIntegrations";
const querystring = require('querystring');
const data = {
requestJobDescription: JSON.stringify({
type: "create",
credentials: {
partnerUserID: "MY_PARTNER_USER_ID",
partnerUserSecret: "MY_PARTNER_USER_SECRET"
},
inputSettings: {
type: "expenses",
employeeEmail: "MY EMPLOYEE EMAIL",
transactionList: [
{
created: "2023-10-20",
currency: "USD",
merchant: "AWS",
amount: 50000,
},
{
created: "2023-11-20",
currency: "USD",
merchant: "META",
amount: 60000,
},
{
created: "2023-10-25",
currency: "USD",
merchant: "UBER",
amount: 200000,
},
],
},
}),
};
const formData = querystring.stringify(data);
const options = {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: formData, // Send the formatted form data
};
fetch(url, options)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json(); // Parse the JSON response
})
.then(responseData => {
console.log("Response Data:", responseData);
// You can work with the response data here
})
.catch(error => {
console.error("Fetch Error:", error);
});