jul 5, 20215:07 AM - editado jul 26, 20217:53 AM
Miembro
how to set jwt in my api route in node js
I am new to Nodejs. I tried to create an API that connect CRM to my website, during which it will be sending data and I get no token error. I tried to solve that but I can't. This is my route file : unionwells germany
const express = require("express");
const auth = require("../../middleware/auth");
const soap = require('strong-soap').soap;
const router = express.Router();
/**
*
* Package: npm i strong-soap
*
* Description: A simple solution to save person.
*/// Enter the field with the username and password that has the necessary permission to find the person.const username = 'admin';
const password = 'admin';
// @route Get api/users/createCustomer// @desc Create new customer in PayamGostar// @access Private
router.post (
"/",
auth,
(req, res) => {
User.findById(req.user._id).then((user) => {
// Replace <url> keyword to your CRM host address.let url = "http://sajjadshiasi.demo.payamgostar.com/Services/API/IPerson.svc?wsdl";
let requestArgs = {
username: username,
password: password,
person: {
FirstName: "Sajjad",
LastName: "Shiasi",
CrmObjectTypeCode: "person",
IdentityType: "حقیقی",
Categories: { CategoryInfo: { Key: "siteclients" } },
PhoneContacts: {
IdentityContactPhone: {
PhoneNumber: "901",
PhoneType: "موبایل",
IsDefault: true,
},
},
Emails: { string: ["4@test.com"] },
Subject: "عضویت در سایت",
},
};
let options = {};
soap.createClient(url, options, asyncfunction (err, client) {
let method = client["SavePerson"];
console.log(client);
awaitmethod(requestArgs, function (err, result, envelope, soapHeader) {
if (result.SavePersonResult.Success) {
user.CrmId = result.SavePersonResult.CrmId;
User.findByIdAndUpdate(
user._id,
user,
{ upsert: true },
function (err, doc) {
if (err) return res.send(500, { error: err });
return res.send("Succesfully saved.");
},
);
}
});
});
});
},
);
module.exports = router;