“Unauthorized” response when cityiq API












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?










share|improve this question



























    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?










    share|improve this question

























      0












      0








      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?










      share|improve this question













      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?







      javascript cityiq






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 '18 at 3:46









      AlexAlex

      14.3k11836




      14.3k11836
























          1 Answer
          1






          active

          oldest

          votes


















          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}')





          share|improve this answer





















          • Thank you very much.That works.
            – Alex
            Nov 15 '18 at 16:54











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273491%2funauthorized-response-when-cityiq-api%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          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}')





          share|improve this answer





















          • Thank you very much.That works.
            – Alex
            Nov 15 '18 at 16:54
















          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}')





          share|improve this answer





















          • Thank you very much.That works.
            – Alex
            Nov 15 '18 at 16:54














          1












          1








          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}')





          share|improve this answer












          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}')






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 '18 at 15:56









          jethompson911jethompson911

          262




          262












          • Thank you very much.That works.
            – Alex
            Nov 15 '18 at 16:54


















          • Thank you very much.That works.
            – Alex
            Nov 15 '18 at 16:54
















          Thank you very much.That works.
          – Alex
          Nov 15 '18 at 16:54




          Thank you very much.That works.
          – Alex
          Nov 15 '18 at 16:54


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273491%2funauthorized-response-when-cityiq-api%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()