Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Setting up the Impac! Finance Bolt

...

 /wiki/spaces/DEV/pages/90439768

The Bolt works differently than Impac! when it comes to data retrieval. In Impac! (caching aside), data is retrieved directly from Connec! before being run through calculations and returned to the client. What’s different with a Bolt is that it has its own database, so when data is CRUD’ed with Connec!, the Bolt receives webhooks to update its own database accordingly.

You can create an instance of Entity::Webhook in Connec! to register a service to receive webhooks when data is CRUD’ed. You can set up the Bolt with Connec! by creating an Entity::Webhook in the Connec! rails console like below (where root keys are the SystemIdentity credentials): 

Code Block
languagebash
titleCreate a webhook for your Bolt
Entity::Webhook.create!(name: 'Impac v2', endpoint: 'http://localhost:4000/api/v2/maestrano/finance/notifications', api_key: 'ROOT_KEY', api_secret: 'ROOT_SECRET', detailed_notifications: true, subscribed_entities: %w(Accounts Journals Company Invoices))

Now your Bolt should be subscribed to Connec! webhooks and will receive all further data syncs.


1.2. Register the Impac! Finance Bolt with Impac!

The Impac! API has a database with a Bolt model that triggers the generation of credentials when it is created. ( before_validation :generate_credentials!, on: :create )

If you take a look at your bolt in the rails console after creating it, it should have generated the api_key and api_secret credentials.

You must register the bolt with Impac! using these credentials as the IMPAC_KEY and IMPAC_SECRET in the Finance Bolt’s application.yml.

If you are having trouble accessing your pre-encrypted Impac! credentials, try using Postman to create the Bolt and retrieve its credentials:

Create a POST request to ‘localhost:4000/api/v2/bolts/’ using Basic Auth with your root (SystemIdentity) credentials. In the request body, choose “raw” and “json”, and paste the following:

Code Block
titleCreating a bolt
{
    "bolts":         
{
     "protocol": "http",
     "provider": "maestrano",
     "name": "finance",
     “host": "localhost:4001",
     "api_path": "api/v1"
   }
}

Send the request, and it should it should return an api_key and api_secret.

These credentials are only returned when the bolt is created (after which they are encrypted for the database), so save them!


1.3. Add Impac! credentials to the Impac! Finance Bolt to allow requests from Impac!

You must register the bolt using the keys generated above as the “IMPAC_KEY” and “IMPAC_SECRET” in the Finance Bolt application.yml

In the Finance Bolt’s application.yml, you should have the following configuration:

Code Block
titleImpac! Finance Bolt application.yml
ROOT_KEY = # From MnoHub: SystemIdentity.first.api_key
ROOT_SECRET = # From MnoHub: SystemIdentity.first.api_secret
IMPAC_KEY = # From Impac: the api_key generated when your bolt is created *see above
IMPAC_SECRET = # From Impac: the api_secret generated when your bolt is created *see above
# These are the Maestrano account pusher keys for development environments
PUSHER_APP_ID: '277973'
PUSHER_KEY: '67da20b2dc7a407dc522'
PUSHER_SECRET: '7fc40a6e8a78bf9ecf1d'
OPENEXCHANGERATES_APP_ID: d8091e280ec44002ae37ede2a63167d2


1.4. Populating the Impac! Finance Bolt with data

As of right now, nothing has been implemented to make sure the Bolt is up to date with Connec!, so if the Bolt is linked up after data has already been synced with Connec!, it will miss out on the webhooks and will have nothing in its own database.

If you run into this issue, you can catch your Bolt up with your current database using the following:

With all of the components running on your machine, run the script below in the Connec! rails console, replacing the webhook_id with the id of the Entity::Webhook you just created, and the channel_id with your organization id:

Code Block
titleCatching up your Bolt's database
channel_id = 'org-fbbj'
[Entity::Account, Entity::Company, Entity::Invoice, Entity::Journal].each do |klass|
 k = klass.to_s.demodulize.pluralize
 k = 'Company' if k == Entity::Company
 klass.on_channel(channel_id).all.each do |entity|
   args = {
     messages: [
       { channel_id: channel_id, entity: k, id: entity.id.to_s }.to_json
     ],
     webhook_id: "5989cc91251fe7107052547e"
   }
   Webhooks::Notifier.notify(args)
 end
end


2. Building your first Bolt Widget

...