Core API

Item Processor

Item Processor is responsible for creating, receiving, updating and deleting items. Please note that you can not delete items from an application. When you delete the items they just marked as deleted.

Item Processor provides such methods for working with items:

  1. getItems

  2. addNewItems

  3. updateItems

  4. deleteItems

getItems

Method returns items from the application. It takes an application ID as an argument.

import GudHub from '@gudhub/core';
const gudhub = new GudHub(authkey);

let app_id = 343;
let trash = false;

let gottenItems = await gudhub.getItems(app_id, trash);
console.log(gottenItems)
Argument Name Type Description
app_id number application ID where we want to get the field model
trash boolean if it's true then it returns deleted items only

This method returns a promise, which in turn returns items from a particular application:

[{
    "item_id": 2987986,
    "fields": [{
        "field_id": 645888,
        "field_value": "John",
    }],
    },{
    "item_id": 2987996,
    "fields": [{
        "field_id": 645888,
        "field_value": "Johana",
    }]
}]

addNewItems

The method adds a new item in the items list. It takes application ID and an item list as arguments.

import GudHub from '@gudhub/core';
const gudhub = new GudHub(authkey);

let app_id = 345;
let itemsList = [{
  "item_id": 2987986,
  "fields": [{
        "field_id": 645888,
        "field_value": "John",
      }],
  },
  {
  "item_id": 2987996,
  "fields": [{
        "field_id": 645888,
        "field_value": "Johana",
      }]
  }
];

let newItem = await gudhub.addNewItems(app_id, itemsList);
console.log(newItem)
Argument Name Type Description
app_id number application ID where we want to get the field model
itemsList array array of application items

In response, we will get a promise with new item object:

[{
    "item_id": 2987986,
    "fields": [{
        "field_id": 645888,
        "field_value": "John",
    }],
    },{
    "item_id": 2987996,
    "fields": [{
        "field_id": 645888,
        "field_value": "Johana",
    }]
}]

updateItems

The method allows you to update an existing item. It takes application ID and items list as arguments.

import GudHub from '@gudhub/core';
const gudhub = new GudHub(authkey);
let itemsList = [{
  "item_id": 2987986,
  "fields": [{
        "field_id": 645888,
        "field_value": "John",
      }],
  },
  {
  "item_id": 2987996,
  "fields": [{
        "field_id": 645888,
        "field_value": "Johana",
      }]
  }
];

let updatedItems = await gudhub.updateItems(app_id, itemsList);
console.log(updatedItems)
Argument Name Type Description
app_id number application ID where we want to get the field model
itemsList array array of application items

It returns promise that will return an updated item object:

[{
    "item_id": 2987986,
    "fields": [{
        "field_id": 645888,
        "field_value": "John",
    }],
},{
    "item_id": 2987996,
    "fields": [{
        "field_id": 645888,
        "field_value": "Johana",
    }]
}]

deleteItems

This method is called for deleting existed items. As arguments, it takes application ID and items list.

import GudHub from '@gudhub/core';
const gudhub = new GudHub(authkey);

let app_id = 454;
let itemsIds = [{
    item_id: 3129206
    },{
    item_id: 3129207
}];

let deletedItems = await gudhub.deleteItems(app_id, itemsIds);
console.log(deletedItems)
Argument Name Type Description
app_id number application ID where we want to get the field model
itemsList array array of application items

As a result we get a success message:

[{
    "item_id": 3129206,
    "fields": [{
        "field_id": 645888,
        "field_value": "John",
    }],
},{
    "item_id": 3129207,
    "fields": [{
        "field_id": 645888,
        "field_value": "Johana",
    }]
}]