我想为我的组织申请,以便我们可以非常轻松地查看我们的客户,发票和报价。我已经设法从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编写桌面应用程序。
答案 0 :(得分:0)
我在以下链接找到了这个awnser:
http://stackabuse.com/the-node-js-request-module/
使用options对象,此请求使用GET方法进行检索 直接来自Reddit的JSON数据,它作为字符串返回 身体领域。从这里,您可以使用JSON.parse并将数据用作 普通的JavaScript对象。
现在我可以做options.id并拥有客户的ID。