admin管理员组

文章数量:1303529

I am using flowroute api and need to fetch data but not sure how to add authentication credentials i.e can be seen when I pass the query url in the browser How can I pass it in the javascript. I am using wix platform and adding javascript code as given below

// For full API documentation, including code examples, visit 
import {fetch} from 'wix-fetch';
$w.onReady(function () {
    fetch(';limit=3?',{method: 'get',auth:{user:'28288282', pass:'099299292991'}})
      .then( (httpResponse) => {
       console.log(httpResponse.ok);
    if (httpResponse.ok) {

      return httpResponse.json();
    } else {
      return Promise.reject("Fetch did not succeed");



  }
  } )
  .then(json => console.log(json))
  .catch(err => console.log(err));

    //TODO: write your page related code here...



});

what is the correct method to pass username and password to the API so I can get a json response instead of current 401 Unauthorized response status

;limit=3

Updating my Answer to show you the Network Call Details Request & Response headers ae as given bwlow in the screenshot

I am using flowroute api and need to fetch data but not sure how to add authentication credentials i.e can be seen when I pass the query url in the browser How can I pass it in the javascript. I am using wix platform and adding javascript code as given below

// For full API documentation, including code examples, visit http://wix.to/94BuAAs
import {fetch} from 'wix-fetch';
$w.onReady(function () {
    fetch('https://api.flowroute./v2/numbers/available?starts_with=800&limit=3?',{method: 'get',auth:{user:'28288282', pass:'099299292991'}})
      .then( (httpResponse) => {
       console.log(httpResponse.ok);
    if (httpResponse.ok) {

      return httpResponse.json();
    } else {
      return Promise.reject("Fetch did not succeed");



  }
  } )
  .then(json => console.log(json))
  .catch(err => console.log(err));

    //TODO: write your page related code here...



});

what is the correct method to pass username and password to the API so I can get a json response instead of current 401 Unauthorized response status

https://api.flowroute./v2/numbers/available?starts_with=800&limit=3

Updating my Answer to show you the Network Call Details Request & Response headers ae as given bwlow in the screenshot

Share Improve this question edited Feb 21, 2018 at 7:49 harshal asked Feb 20, 2018 at 4:05 harshalharshal 10.9k3 gold badges19 silver badges23 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Try:

fetch('https://api.flowroute./v2/numbers/available?starts_with=800&limit=3?', {
  method: 'get',
  headers: {
    "Content-Type": "text/plain",
    'Authorization': 'Basic ' + btoa(username + ":" + password),
  },
})

本文标签: