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

  5. getFilteredItemsAPI

getItems() #

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

async gudhub.getItems(app_id, trash)
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
import GudHub from '@gudhub/core';

const AUTHKEY = "NKJHIUHknjcnkhios9w92ehds78/7";
let app_id = 343;
let trash = false;

(async ()=>{
    const gudhub = await new GudHub(AUTHKEY);
    let gottenItems = await gudhub.getItems(app_id, trash);
    console.log(gottenItems);
})();

This method 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.

async gudhub.addNewItems(app_id, itemsList)
Argument Name Type Description
app_id number application ID where we want to get the field model
itemsList array array of application items
import GudHub from '@gudhub/core';

const AUTHKEY = "NKJHIUHknjcnkhios9w92ehds78/7";
let app_id = 345;
let itemsList = [{
  "fields": [{
        "field_id": 645888,
        "field_value": "John",
      }],
  },
  {
  "fields": [{
        "field_id": 645888,
        "field_value": "Johana",
      }]
  }
];

(async ()=>{
    const gudhub = await new GudHub(AUTHKEY);
    let newItem = await gudhub.addNewItems(app_id, itemsList);
    console.log(newItem)
})();

In response, we will get an array of items:

[{
    "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.

async gudhub.updateItems(app_id, itemsList)
Argument Name Type Description
app_id number application ID where we want to get the field model
itemsList array array of application items
import GudHub from '@gudhub/core';

const AUTHKEY = "NKJHIUHknjcnkhios9w92ehds78/7";
let itemsList = [{
  "item_id": 2987986,
  "fields": [{
        "field_id": 645888,
        "field_value": "John",
      }],
  },
  {
  "item_id": 2987996,
  "fields": [{
        "field_id": 645888,
        "field_value": "Johana",
      }]
  }
];

(async ()=>{
    const gudhub = await new GudHub(AUTHKEY);
    let updatedItems = await gudhub.updateItems(app_id, itemsList);
    console.log(updatedItems);
})();

It returns 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.

async gudhub.deleteItems(app_id, itemsIds)
Argument Name Type Description
app_id number application ID where we want to get the field model
itemsList array array of application items
import GudHub from '@gudhub/core';

const AUTHKEY = "NKJHIUHknjcnkhios9w92ehds78/7";
let app_id = 454;
let itemsIds = [3129206, 3129207];

(async ()=>{
    const gudhub = await new GudHub(AUTHKEY);
    let deletedItems = await gudhub.deleteItems(app_id, itemsIds);
    console.log(deletedItems);
})();

As a result we get an array of deleted items:

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

getFilteredItemsAPI() #

This method calls the server's Get Items endpoint directly, returning items filtered and paginated on the server side instead of filtering an already-fetched items list in memory. It is a low-level method on the item processor (like addItemsApi/updateItemsApi/deleteItemsApi) and is called through gudhub.itemProcessor rather than directly on gudhub. As arguments, it takes an application ID, a filters list, and an options object for pagination/specific items.

async gudhub.itemProcessor.getFilteredItemsAPI(app_id, filters_list, options)
Argument Name Type Description
app_id number application ID where we want to get items from
filters_list array list of filters to apply on the server side
options.items array optional list of specific item IDs to fetch
options.offset number optional offset for pagination
options.limit_to number optional limit on the number of items returned
import GudHub from '@gudhub/core';

const AUTHKEY = "NKJHIUHknjcnkhios9w92ehds78/7";
let app_id = 343;
let filters_list = [];
let options = {
  offset: 0,
  limit_to: 10
};

(async ()=>{
    const gudhub = await new GudHub(AUTHKEY);
    let filteredItems = await gudhub.itemProcessor.getFilteredItemsAPI(app_id, filters_list, options);
    console.log(filteredItems);
})();

In response, we get the filtered items list from the server (or null if the request fails):

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