Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.user_complain = async (req, res) => {
- try{
- if (req.files.length > 0) {
- req.files.forEach(file => {
- imagePaths.push(file.path);
- });
- }
- var API_KEY = YOUR_FRESHDESK_API_KEY;
- var PATH = '/api/v2/tickets';
- var URL = YOUR_FRESHDESK_URL + PATH;
- var fields = {
- subject: 'This is test complain',
- status: 2,
- priority: 1,
- phone: '1234567890',
- name: 'customer name',
- type: 'Issue',
- group_id: 48000389195
- };
- var Request = unirest.post(URL);
- Request.auth({
- user: API_KEY,
- pass: 'X',
- sendImmediately: true
- })
- // .type('json')
- .field(fields)
- .attach('attachments[]', imagePaths)
- .end(function(response) {
- if (response.status == 201) {
- return res.status(200).send({
- data: response.body,
- message: 'Issue registered sucessfully!',
- status: true,
- error: false
- });
- } else {
- console.log(response.status);
- return res.status(404).send({
- data: response.body,
- message: 'Issue While registering Complaint. Try Again!!!',
- error: true
- });
- }
- });
- //to remove image from folder
- if (imagePaths.length > 0) {
- imagePaths.forEach(imagePath => {
- removeImage(imagePath);
- });
- }
- }
- catch (err) {
- console.log(err);
- res.status(400).send({
- message: 'Something wrong!!!',
- status: false,
- error: err
- });
- }
- }
- // remove image function
- const removeFile = function(delPath) {
- if (fs.existsSync(delPath)) {
- fs.unlinkSync(delPath);
- }
- };
Add Comment
Please, Sign In to add comment