Skip to content

API Reference 1.2.0

GarbageSlave edited this page Nov 9, 2021 · 1 revision

Getting started / Installation

To install using npm, simply:

$ npm install afas-connect

Yarn:

$ yarn add afas-connect
Initializing
const { Profit } = require('afas-connect');

const AfasService = new Profit({
  apiKey: '<YOUR_API_KEY_HERE>',
  env: '12345',
  envType: 'production'
})

Examples

REST

Using the GetConnector
// 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')
Using the UpdateConnector
// 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')
Using the CustomConnector
const response = await AfasService.CustomConnector.version()

// -> expected response { version: "<YOUR AFAS VERSION>" }
console.log(response.version)

SOAP

Getting data
const response = await AfasService.SoapConnector.get('Profit_Article')

// -> expected response { GetDataResult: "<XML DATA STRING />" }
console.log(response.GetDataResult)
Updating, inserting and deleting data
// 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)
Clone this wiki locally