Exchanging data
When two entities exchange data, such as a user typing into a chatbot, an AI agent handing off data to an MCP tool, or any other systematic data exchange, we use the produce endpoint to generate a cryptographically signed event record. The below example creates and saves an event in the data store, signs it, makes an audit record, signs that, and delivers the audit record to the archive server.
const userEvent = (await axios.post(
`https://api-test.jlinc.io/api/v1/data/event/produce`,
{
type: 'data',
senderShortName: user.didDoc.shortName,
recipientShortName: system.didDoc.shortName,
agreementId: agreement.created.agreementId, // Or `00000000-0000-0000-0000-000000000000` if just auditing
meta: {
myCustomId: 'my_custom_identifier'
},
data: {
query: 'Why am I making this?',
},
archive: {
url: `https://api-test.jlinc.io`,
key: archiveToken,
},
},
{
headers: {
'Authorization': `Bearer ${token}`,
}
}
)).data;
console.log(`User data event: ${JSON.stringify(userEvent, null, 4)}\n`);
In the above, the meta field can be used to include custom identifiers that will be stored and indexed in the data store. This makes future lookups easier as you may use identifiers already leveraged in your system to find signed data events and audit records.
Now the system accepts (signs) that data. If the data was not already sent to the system using the processes already developed within the application, it can be retrieved from the JLINC data store:
const gotProviderEvent = (await axios.post(
`https://api-test.jlinc.io/api/v1/data/event/get`,
{
eventId: userEvent.created.eventId,
},
{
headers: {
'Authorization': `Bearer ${token}`,
}
}
)).data;
console.log(`System got event: ${JSON.stringify(gotProviderEvent, null, 4)}\n`);
Or instead, the system could get the data by custom meta ID:
const gotProviderEventByMetaId = (await axios.post(
`https://api-test.jlinc.io/api/v1/data/event/get`,
{
meta: {
myCustomId: 'my_custom_identifier', // Multiple specified keys respond with AND not OR
}
},
{
headers: {
'Authorization': `Bearer ${token}`,
}
}
)).data;
console.log(`System got event by meta ID: ${JSON.stringify(gotProviderEventByMetaId, null, 4)}\n`);
Once the system has the data, either via the application's current interfaces or retrieved via the data store, the system indicates it has received and will use the data by cross-signing the event.
const processedSystemEvent = (await axios.post(
`https://api-test.jlinc.io/api/v1/data/event/process`,
{
eventId: userEvent.created.eventId,
shortName: system.didDoc.shortName,
archive: {
url: config.archiveUrl,
key: archiveToken,
},
},
{
headers: {
'Authorization': `Bearer ${token}`,
}
}
)).data;
console.log(`System processed data event: ${JSON.stringify(processedProviderEvent, null, 4)}\n`);