Home > Back-end >  fetch() is adding local host to the URL when I include a variable
fetch() is adding local host to the URL when I include a variable

Time:10-31

Fetch is adding local host and IP address of the Vue app in front of the url when I include a variable for a project ID in API request. If the projectId is hard coded the endpoint works. How do I eliminate the local part of the url?

I have tried to add the variable as ${projectId} or be concatenation projectId the result is the same. The url sent looks like

const projectId = ref('')
const uri = `"https://developer.api.autodesk.com/bim360/admin/v1/projects/b.${ projectId.value}/users"`

function getUsers() {
 fetch
 (uri, requestOptions)
  .then(response => response.json())
  .then((response) => {
    res.value = response
  })
  .catch(error => console.log('error', error))
}

Looking in the network the url that is sent looks like this

http://127.0.0.1:5173/"https://developer.api.autodesk.com/bim360/admin/v1/projects/b.bfca3830-79e5-45c3-8ebe-0c3ba17273eb/users"

Not a real projectID by the way. Thanks for any suggestions!

CodePudding user response:

It looks like you're using extra quotations (""). When you're using string interpolation you don't need to use quotations (""). Declare your URI like example given bellow.

const uri = `https://developer.api.autodesk.com/bim360/admin/v1/projects/b.${ projectId.value}/users`
  • Related