Recommended versions node >=16 and npm >=8.
A stable 1.x version of this package is available as js-dataverse at https://www.npmjs.com/package/js-dataverse
Install the package stable version using npm:
npm install js-dataverseAn unstable 2.x version of this package with breaking changes is under development.
Until a 2.0 version is officially released, it can be installed from https://github.com/IQSS/dataverse-client-javascript/pkgs/npm/dataverse-client-javascript
To install the @iqss/dataverse-client-javascript
from the GitHub registry, follow these steps to create an .npmrc file in the root of your project using your GitHub token.
-
Create
.npmrcin your project's root directory.touch .npmrc
-
Replace the Token
Open the newly created
.npmrcfile and replaceYOUR_GITHUB_TOKENwith your actual GitHub token.legacy-peer-deps=true //npm.pkg.github.com/:_authToken=<YOUR_GITHUB_AUTH_TOKEN> @iqss:registry=https://npm.pkg.github.com/
If you don't have a GitHub token yet, follow these steps:
-
Go to your GitHub account settings.
-
Navigate to "Developer settings" -> "Personal access tokens."
-
Click "Personal access tokens" -> "Tokens (classic)" -> "Generate new token (classic)".
-
Give the token a name and select the "read:packages" scope.
-
Copy the generated token.
-
Replace
YOUR_GITHUB_AUTH_TOKENin the.npmrcfile with the copied token.
Now, you should be able to install the Dataverse JavaScript client using npm.
Install the package development version using npm:
npm install @iqss/dataverse-client-javascriptIn order for the package to connect to the Dataverse API, there is an APIConfig object that should be initialized to set the preferred authentication mechanism with the associated credentials for connecting to the Dataverse API.
Currently, the supported authentication mechanisms are:
-
API Key: The recommended authentication mechanism. The API Key should correspond to a particular Dataverse user account.
-
Session Cookie: This is an experimental feature primarily designed for Dataverse SPA development. To use this mechanism, you must enable the corresponding feature flag in the Dataverse installation (See https://guides.dataverse.org/en/latest/installation/config.html?#feature-flags). It is recommended not to use this mechanism and instead use API Key authentication.
It is recommended to globally initialize the ApiConfig object from the consuming application, as the configuration will be read on every API call made by the package's use cases.
For example, in a React application, we can globally initialize the ApiConfig object in the App file, like this:
ApiConfig.init(<DATAVERSE_API_BASE_URL>, DataverseApiAuthMechanism.API_KEY, <DATAVERSE_API_KEY>)
function App() {
/* Yor App code */
}
export default AppThe same example but with example values set:
ApiConfig.init(
'http://localhost:8000/api/v1',
DataverseApiAuthMechanism.API_KEY,
'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
)
function App() {
/* Yor App code */
}
export default AppWe can initialize the ApiConfig object as an unauthenticated user, by setting undefined as the API Key value.
This will allow use cases that do not require authentication to be successfully executed, but those that do require authentication will fail.