缺少方连接的必需参数:idempotency_key,NodeJS

问题描述

每次我尝试通过方形连接api创建订单时,都会出现以下错误

{"errors": [{"code": "MISSING_required_ParaMETER","detail": "Missing required parameter.","field": "idempotency_key","category": "INVALID_REQUEST_ERROR"}]}.

我相信我在请求中正确包含了idempotency_key,但是我一直收到相同的错误。关于如何解决此问题的任何想法?

router.post(
    '/startorder',[
        check('email','Please enter your email').not().isEmpty(),check('email','Please enter a valid email').isEmail(),check('address','Please enter your address').not().isEmpty(),check('zipCode','Please enter your zipcode').not().isEmpty(),check('name','Please enter your name').not().isEmpty(),check('city','Please enter your city').not().isEmpty(),check('country','Please enter your country').not().isEmpty(),check('state','Please enter your state').not().isEmpty(),],async (req,res) => {
        const errors = validationResult(req);

        if (!errors.isEmpty()) {
            return res.status(400).json({ errors: errors.array() });
        }

        const { email,address,zipCode,name,city,country,state } = req.body;

        const apiInstance = new SquareConnect.OrdersApi();

        const locationId = process.env.LOCATION_ID; // String | The ID of the business location to associate the order with.

        const request_body = {
            order: {
                location_id: locationId,},idempotency_key: crypto.randomBytes(22).toString('hex'),};
        const body = new SquareConnect.CreateOrderRequest(request_body); 

        try {
            console.log('this is the body',body);
            const response = await apiInstance.createOrder(locationId,body);
            console.log(response);
            res.json(response);
        } catch (error) {
            console.error(error);
            return res.status(500).json({ msg: error });
        }
    }
);

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)