0

I am trying to access the Current powered by GE CityIQ API to develop a parking app, I followed the API documentation however I cannot seem to successfully query because I do not have an access token. I have a user name and password as well as the urls and predix zone id for parking provided by the city I am using. When I try and run my javascript and log my access token the response is “Unauthorized”. Do i have to raise a request to the city for the access token?

The code is written in javascript and is using node.js and node-fetch.

Here is my code:

const fetch = require("node-fetch")
function request(url, headers, body) {
    let options = { headers: headers, body:body}
    return fetch(url, options).then(result => {
        if (result.status>=400) return(result.statusText)
        else return result.text().then(txt => {
            try { return JSON.parse(txt) }
            catch (err) { return txt }
        })
    })
}
// my credentials
const developer, uaa, metadataservice, eventservice, predixZone

developer = '{user}:{pass}'
uaa='{uaaURL}'    
eventservice='{eventURL}'    
metadataservice='{metadataURL}'    
predixZone='{predixzoneParking}' 

async function example(event){
    let devToken = (await request(uaa+'?grant_type=client_credentials', {authorization: 'Basic '+developer}))
    console.log(devToken)
    let output = (await request(metadataservice+'/assets/search?q=eventTypes:PKIN',{authorization: 'Bearer '+devToken,'predix-zone-id':predixZone})).content
    console.log(output)
}
example()

What am I doing wrong or probably missing?

Alex
  • 16,739
  • 1
  • 28
  • 51

1 Answers1

1

It looks like you have not base64 encoded your username and password.
At the top of your code:

const btoa = str => new Buffer(str).toString('base64')

When you declare your user name and pass:

developer = btoa('{user}:{pass}')