# Open Api Module

Adds a the global propert $nioOpenApi to the global Vue object. This will allow you to make API calls to the endpoints exposes on Narrative's Open API.

TIP

The $nioOpenApi property exposes all methods in the axios library. Simply make calls as you would normally make them, but prefeix them with $nioOpenApi instead of axios. See the examples below

# Usage

This module is used automatically internally in Tacklebox to obtain certain data in the application. This includes authentication tokens for subsequent API calls, as well as for fetching data from the services specified in your app's manifest.

Is is only neccessary for you to use this module if you desire to make calls to endpoints that are not included in those services, and if you have authorization to make those API calls. (for example, to fetch the active user's subscriptions). Additionally, PUT or POST requests to the endpoints serving those services will need to be made with this module.

To make use of this module, import in the implementing component:

TIP

Since the Open API is authenticated, and since the authentication token is retreived asyncronously, the $nioOpenApi property may not be available in the mounted lifecycle hook of a component. For this reason, it is suggested that you make use of the provided initCallback method in order to determine the availability of the API and make any calls in the callback function provided as an argument.

import { NioOpenApiModule } from '@narrative.io/tackle-box'

export default {
  data: () => ({
    subscriptions: []
  }),	
  mounted() {
    NioOpenApiModule.initCallback(this.getSubscriptions)
  },
  getSubscriptions() {
      this.$nioOpenApi.get('/subscriptions').then(res => {
        this.subscriptions = res.data.records
      })
    }
  }	
}
Last Updated: 2/10/2021, 5:34:22 PM