Skip to content

Attributes

Attributes use data stores which are JSON documents. To get or set use JSONPath to refer to a specific location in the document. It is very similar to XPath for XML documents.

To get a value at a specific path use dot notation prefixed with the root, for example $.full.path.dots.

JSONPath information: * Tutorial at restfulapi.net * Online tester at jsonpath.com

Data mutations

Data mutations for DataSet

{
    path=JSONPath,
    value=Any
}

Data mappers for DataMap and DataMapContext

{
    from=JSONPath,
    to=JSONPath
}

DataGet

core.DataGet(query)

Get data for a user

  • query:String user query such as given user [..] and JSON path expression

Data response

{
    "1": {
        "updatedAt":"2021-06-04T16:21:03.000+09:00",
        "schemaId":"3e6e1a3e-b65c-40bd-857b-99b60be8f5ad",
        "text":"value or json object",
        "id":"303318bc-9d64-4791-8a8b-5fa36edc8e1f",
        "createdAt":"2021-06-04T16:21:03.000+09:00",
        "userId:"uuid"
    }
}
local data = core.DataGet("given user [<user id>] $.intake")
log.info(data)

DataHasValue

core.DataHasValue(query)

Check if a query has a value set.

  • query:String user query such as given user [..] and JSON path expression

Boolean

local hasvalue = core.DataHasValue("given user [<user id>] $.intake")
log.info(hasvalue)

DatatSet

core.DatatSet(userId, mutation1, mutation2, ...)

Save data for a user

  • userId:UUID user id
  • mutations see above; this function supports variable arguments

Boolean

core.DataSetList(
    "<user id>",  
    {path="$.intake.height", value="180"}, 
    {path="$.intake.weight", value="65"}
)

DatatSet

core.DatatSetIfEmpty(userId, query, mutation1, mutation2, ...)

Save data for a user if a path is empty

  • userId:UUID user id
  • mutations see above; this function supports variable arguments

Boolean

core.DatatSetIfEmpty(
    "<user id>",  
    {path="$.intake.height", value="180"}
)

DatatSetList

core.DatatSet(userId, mutations)

Save data for a user

  • userId:UUID user id
  • mutations[] see above; supports a lua table of mutations

Boolean

local ls = {}
table.insert(ls, {path="$.intake.height", value="180"})
table.insert(ls, {path="$.intake.weight", value="65"})    

log.pairs(ls)

core.DataSetList(
    "<user id>",  ls
)

DataMap

core.DataMap(query, mappers)

This will use the mappers to update user attributes for each dispatch in the series.

  • query:String Dispatch query
  • mappers[] data mappers, see above

Data at the path or nil

DataMapContext

This will use the mappers to update user attributes for the context dispatch; this assumes the script was called by a dispatch lifecycle trigger.

core.DataMapContext(path)
  • mappers[] data mappers, see above

Data at the path or nil

Examples

Executed during a lifecycle trigger; copies data from the dispatch to the user attributes.

    core.DataMapContext(
        {from="$.height", to="$.intake.height"},
        {from="$.weight", to="$.tracking.weight"},
        {from="$.about", to="$.about.blurb"},
        {from="$.location", to="$.about.location"}
    )

Executed using a dispatch query.

    core.DataMap(
        "given tracker [intake]",
        {from="$.height", to="$.intake.height"},
        {from="$.weight", to="$.tracking.weight"},
        {from="$.about", to="$.about.blurb"},
        {from="$.location", to="$.about.location"}
    )