Using Harmony APIs

All public Nedap Harmony APIs are available to call using the api object. The api object uses the openapi-client-axios library in the background for making the calls. The names of the function equal the names of the API calls in the API Reference.

The api object is already pre-loaded with a limited-validity access token for your workspace and a reference to the active read point, so there is nothing to worry about there.

General structure

const apiClient = await api.getClient()
const result = await apiClient.<MethodName>(parameters, body, options)
const <DataYouNeed> = result.data

Example to create or replace a document

// retrieve the API client
const apiClient = await api.getClient()

// do the API call
try
{  
  const document = {
    type: 'shipment',
    reference: '12345',
    contents: {
     ... 
    }
  }
  
  await apiClient.CreateOrReplaceDocument(null, document)
} catch (error)
{
  console.log(error) 
}

Example to find documents

// retrieve the API client
const apiClient = await api.getClient()

// do the API call
try
{  
  const result = await apiClient.FindDocuments({
    type: 'inboundLpn',
    references: [newReference]
  })
  
  // get the results
	const documents = result.data
} catch (error)
{
  console.log(error) 
}

Example to trigger a read point on page load

// only execute once on page load
useEffect(() => {
  const trigger = async () => {
		// retrieve the API client
    const apiClient = await api.getClient()

    // call the API with the given parameters
    await apiClient.TriggerReadPoint(null, {
      type: 'RfidStartReading'
    }}
  }

  // call the function
  trigger()
    // make sure to catch any error
    .catch(console.error);
}, [api])