Search code examples
javascriptapipushbullet

Javascript101 help | API | stuck


Per Pushbullet API doc I need: Header as: 'Access-Token: o.I'veLearnedNotToPost' 'Content-Type": "application/json' Url is https://api.pushbullet.com/v2/users/me

Problem with my code (don't laugh too hard) is that it only returns "Retrieving information for o.I'veLearnedNotToPost"

Front end code needs to take token from user input text element and put it in backend code (getuser.jsw) to fetch User Info. But the issue is that it's not - nothing except the placeholder text appears in the textbox element (id #result)

Side note: $w is Wix's write to element

// FRONT END CODE
import {getUserInfo} from 'backend/getuser';

export function button1_click(event, $w) {
    console.log("Retrieving information for " + $w("#sendToken").value);

  getUserInfo($w("#sendToken").value)
    .then(usInfo => {
      ($w("#result").text) 
              });
}
//BACKEND CODE
import {fetch} from 'wix-fetch';


export function getUserInfo(token) {
    let atoken = token;
    let url = "https://api.pushbullet.com/v2/users/me";
      console.log("Retrieving information for  " + atoken);


   return fetch("https://api.pushbullet.comm/v2/users/me", {
  headers: {
    "Access-Token": atoken,
    "Content-Type": "application/json"
  }

  .then(response => response.json())
})}

Thanks in advance for your help! Greatly appreciated! -Malc


Solution

  • your Access-Token value is double quoted, try without.