Links
⛑

How to Fetch Safely from Savvy

Why can't I just do a regular fetch? Two main reasons:
  • Fetching from the Front-End exposes private information like API keys. An experienced developer could retrieve that token or secret key and access more information than what you wanted to share.
  • Some APIs don't allow fetch requests from the Front-End due to CORS

Step 1: Copy and Paste

  • Copy this code and paste it in the Computed Field, Custom Data Output, or Custom Code for Button where you need it to fetch. The secure key can be in different formats inside the header -it will not always be "Authorization: Bearer {{key}}"
return fetch(`https://savvy-api-proxy-secure.heysavvy.workers.dev/?url=${encodeURIComponent('https://api.example-address.io/api/v2')}`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer {{group_name-service-key_type}}'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(response => console.log('response', response))

Step 2: Change the URL

  • Change the URL inside of the encodeURIComponent function to the actual URL where you're going to be fetching from

Step 3: Generate a Key for the Key

  • Send your key to a Savvy Engineer, they will save it and give you a different key for you to paste in line 6 instead of group_name-service-key_type