Created
January 12, 2018 02:43
-
-
Save librarywebchic/ea30d2108e73a9e588ada6d5d986716d to your computer and use it in GitHub Desktop.
Call to WC DIscovery API nodeJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var WSKey = require('oclc-wskey') | |
const axios = require("axios"); | |
var https = require('https') | |
var url = require('url') | |
var me = { principalID: 'principalID', principalIDNS: 'principalIDNS' } | |
var key = new WSKey('key', 'secret', me) | |
var request_url = 'https://authn.sd00.worldcat.org/oauth2/accessToken?grant_type=client_credentials&authenticatingInstitutionId=128807&contextInstitutionId=128807&scope=WorldCatDiscoveryAPI'; | |
var authorization = key.HMACSignature('POST', request_url) | |
var config = { | |
headers: { | |
'Authorization': authorization, | |
'Accept': 'application/json' | |
} | |
}; | |
axios.post(request_url, null, config) | |
.then(response => { | |
console.log(response.data); | |
console.log(response.data.access_token); | |
var headers = { | |
'Authorization': 'Bearer ' + response.data.access_token, | |
'Accept': 'application/json' | |
} | |
axios.get('https://beta.worldcat.org/discovery/bib/data/41266045', {headers}) | |
.then(response =>{ | |
var graph = response.data['@graph'][0] | |
var bib = graph['schema:about'] | |
console.log(bib['schema:name']['@value']) | |
}) | |
.catch (error => { | |
console.log(error.response.status); | |
console.log(error.response.data); | |
}) | |
}) | |
.catch(error => { | |
console.log(error.request.method); | |
console.log(error.request.path); | |
console.log(error.response.status); | |
console.log(error.response.data); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment