-
Notifications
You must be signed in to change notification settings - Fork 8
API Reference 1.2.0
GarbageSlave edited this page Nov 9, 2021
·
1 revision
To install using npm, simply:
$ npm install afas-connect
Yarn:
$ yarn add afas-connect
const { Profit } = require('afas-connect');
const AfasService = new Profit({
apiKey: '<YOUR_API_KEY_HERE>',
env: '12345',
envType: 'production'
})
// Getting data
const response = await AfasService.GetConnector.get('Profit_Article')
// -> expected response { skip: 0, take: 100, rows: [...ect] }
console.log(response.rows)
// Getting data using filter
const config1 = {
skip: 0,
take: 50,
orderby: [
{
fieldId: 'Itemcode',
order: 'ASC'
},
{
fieldId: 'Date',
order: 'DESC'
}
],
filter: [
{
filterfieldid: 'Itemcode',
filtervalue: '12345AB',
operatortype: 1,
or: [
{
filtervalue: '6789CD',
operatortype: 6
},
{
filtervalue: '0000',
operatortype: 10
}
]
}
]
}
const response1 = await AfasService.GetConnector.get('Profit_Article', config1)
// Or, using the jsonFilter
const config2 = {
skip: 0,
take: 50,
orderby: [{ fieldId: 'Itemcode', order: 'ASC' }, { fieldId: 'Date', order: 'DESC' }],
jsonFilter: {
"Filters": {
"Filter": [
// Base
{
"@FilterId": "Filter 1",
"Field": [
{
"@FieldId": "Itemcode",
"@OperatorType": 1,
"#text": "12345AB"
},
{
"@FieldId": "Date",
"@OperatorType": 1,
"#text": "01-01-2021"
}
]
},
// Or
{
"@FilterId": "Filter 2",
"Field": [
{
"@FieldId": "Itemcode",
"@OperatorType": 6,
"#text": "6789CD"
},
{
"@FieldId": "Date",
"@OperatorType": 1,
"#text": "02-02-2021"
}
]
},
// Or
{
"@FilterId": "Filter 3",
"Field": [
{
"@FieldId": "Itemcode",
"@OperatorType": 10,
"#text": "0000"
}
]
}
]
}
}
}
const response2 = await AfasService.GetConnector.get('Profit_Article', config2)
// Get metainfo of Getconnector
const metainfo = await AfasService.GetConnector.metainfo('Profit_Article')
// Inserts a record
await AfasService.UpdateConnector.insert('FbItemArticle', {
FbItemArticle: {
Element: {
Fields: {
ItCd: "123"
}
}
}
})
// Updates main record, inserts sub record
await AfasService.UpdateConnector.insertSubUpdateMain('FbItemArticle', 'FbArticleCustom', {
FbItemArticle: {
Element: {
Fields: {
ItCd: "123"
}
}
}
})
// Updates a record
await AfasService.UpdateConnector.update('FbItemArticle', {
FbItemArticle: {
Element: {
Fields: {
ItCd: "456"
}
}
}
})
// Deletes a record
await AfasService.UpdateConnector.delete('FbItemArticle', 'FbItemArticle/FbItemArticle/ItCd/123')
// Get metainfo
const metainfo = await AfasService.UpdateConnector.metainfo('FbItemArticle')
const response = await AfasService.CustomConnector.version()
// -> expected response { version: "<YOUR AFAS VERSION>" }
console.log(response.version)
const response = await AfasService.SoapConnector.get('Profit_Article')
// -> expected response { GetDataResult: "<XML DATA STRING />" }
console.log(response.GetDataResult)
// Insert a record
const XMLstring1 = `
<FbItemArticle xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Element>
<Fields Action="insert">
<ItCd>123</ItCd>
</Fields>
</Element>
</FbItemArticle>
`
await AfasService.SoapConnector.update('FbItemArticle', XMLstring1)
// Update a record
const XMLstring2 = `
<FbItemArticle xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Element>
<Fields Action="update">
<ItCd>123</ItCd>
</Fields>
</Element>
</FbItemArticle>
`
await AfasService.SoapConnector.update('FbItemArticle', XMLstring2)
// Delete a record
const XMLstring3 = `
<FbItemArticle xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Element>
<Fields Action="delete">
<ItCd>123</ItCd>
</Fields>
</Element>
</FbItemArticle>
`
await AfasService.SoapConnector.update('FbItemArticle', XMLstring3)