【问题标题】:Node JS request from API来自 API 的 Node JS 请求
【发布时间】:2017-11-19 00:30:20
【问题描述】:

我想为我的组织提出申请,以便我们可以非常轻松地查看我们的客户、发票和报价。我已经设法从 RESTful API 表单 Moneybird(我们将使用的程序)中得到如下回复(出于隐私原因,我删除了个人详细信息):

{
    "id": "206357083043398674",
    "administration_id": "BLANK",
    "company_name": "BLANK",
    "firstname": "BLANK",
    "lastname": "BLANK",
    "address1": "BLANK",
    "address2": "",
    "zipcode": "BLANK",
    "city": "BLANK",
    "country": "NL",
    "phone": "BLANK",
    "delivery_method": "Email",
    "customer_id": "9",
    "tax_number": "BLANK",
    "chamber_of_commerce": "BLANK",
    "bank_account": "BLANK",
    "attention": "BLANK",
    "email": "BLANK",
    "email_ubl": true,
    "send_invoices_to_attention": "BLANK",
    "send_invoices_to_email": "BLANK",
    "send_estimates_to_attention": "BLANK",
    "send_estimates_to_email": "BLANK",
    "sepa_active": false,
    "sepa_iban": "BLANK",
    "sepa_iban_account_name": "BLANK",
    "sepa_bic": "BLANK",
    "sepa_mandate_id": "",
    "sepa_mandate_date": null,
    "sepa_sequence_type": "FRST",
    "credit_card_number": "",
    "credit_card_reference": "",
    "credit_card_type": null,
    "tax_number_validated_at": "2017-1118T15:04:32.107Z",
    "tax_number_valid": true,
    "invoice_workflow_id": "BLANK",
    "estimate_workflow_id": "BLANK",
    "created_at": "20171118T15:04:31.825Z",
    "updated_at": "2017-1118T15:39:03.345Z",
    "version": 1511019543,
    "sales_invoices_url": "BLANK",
    "notes": [],
    "custom_fields": [],
    "events": [{
            "administration_id": "BLANK",
            "user_id": "BLANK",
            "action": "contact_changed",
            "link_entity_id": null,
            "link_entity_type": null,
            "data": {
                "changes": {
                    "send_invoices_to_email": ["BLANK", "BLANK"]
                }
            },
            "created_at": "2017-11-18T15:39:03.373Z",
            "updated_at": "2017-11-18T15:39:03.373Z"
        },
        {
            "administration_id": "BLANK",
            "user_id": "BLANK",
            "action": "contact_changed",
            "link_entity_id": null,
            "link_entity_type": null,
            "data": {
                "changes": {
                    "send_invoices_to_email": ["BLANK", "BLANK"]
                }
            },
            "created_at": "2017-11-18T15:25:43.938Z",
            "updated_at": "2017-11-18T15:25:43.938Z"
        },
        {
            "administration_id": "BLANK",
            "user_id": "BLANK",
            "action": "contact_created",
            "link_entity_id": null,
            "link_entity_type": null,
            "data": null,
            "created_at": "2017-11-18T15:04:31.860Z",
            "updated_at": "2017-11-18T15:04:31.860Z"
        }
    ]
}

我设法使用以下代码获得了此响应:

request({
        url: 'https://moneybird.com/api/v2/'+accountID+'/contacts/206357083043398674.json?',
        auth: {
            'bearer': accessToken
        },
        method: 'POST'
    }, function(error, response, data) {
        body.data = data;
        mainWindow.webContents.send('user:view', body.data);
    });

显然没有更多的 console.log();因为我想在无序列表中显示每个用户在他/她自己的行上。

我不知道如何使用从请求中获得的信息到 index.html 文件并使其可读。

我正在使用 Electron 和 Node.JS 编写一个桌面应用程序。

【问题讨论】:

    标签: javascript json node.js electron


    【解决方案1】:

    我在以下链接找到了遮阳篷:

    http://stackabuse.com/the-node-js-request-module/

    使用选项对象,此请求使用 GET 方法检索 直接来自 Reddit 的 JSON 数据,在 身体领域。从这里,您可以使用 JSON.parse 并将数据用作 普通的 JavaScript 对象。

    现在我可以只做 options.id 并获得客户的 ID。

    【讨论】:

      猜你喜欢
      • 2015-03-08
      • 2020-02-16
      • 2019-06-30
      • 2017-01-31
      • 2019-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-08
      相关资源
      最近更新 更多