API Request Setup
Code examples on how to set up your requests after retrieving a token
Last updated
Code examples on how to set up your requests after retrieving a token
Last updated
You can find the nutrition-api route documentation at: Nutrition-API Docs
These examples assume you have followed the steps from and have received a response from that route.
import requests
response = {
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImupZCI6InNab1FMT3oxMkRreHVLNVVVRUJBSCJ9...",
"scope": "read:search read:products",
"expires_in": 86155.034762118,
"token_type": "Bearer",
"customer_id": "0d8bb889-36e1-11ee-b9e9-92e504c243a4"
}
headers = {
"Authorization": f"Bearer {response['access_token']}",
"Passio-ID": response['customer_id']
}
url = "https://api.passiolife.com/v2/products/napi/food/search/advanced?term=pepperoni%20pizza"
r = requests.get(url, headers=headers)
print(r.json())
package main
import (
"io/ioutil"
"net/http"
)
func main() {
response := map[string]interface{}{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImupZCI6InNab1FMT3oxMkRreHVLNVVVRUJBSCJ9...",
"scope": "read:search read:products",
"expires_in": 86155.034762118,
"token_type": "Bearer",
"customer_id": "0d8bb889-36e1-11ee-b9e9-92e504c243a4",
}
client := &http.Client{}
req, _ := http.NewRequest("GET", "https://api.passiolife.com/v2/products/napi/food/search/advanced?term=pepperoni%20pizza", nil)
req.Header.Add("Authorization", "Bearer "+response["access_token"].(string))
req.Header.Add("Passio-ID", response["customer_id"].(string))
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
println(string(body))
}
import axios from 'axios';
import React, { useEffect } from 'react';
const response = {
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImupZCI6InNab1FMT3oxMkRreHVLNVVVRUJBSCJ9...",
"scope": "read:search read:products",
"expires_in": 86155.034762118,
"token_type": "Bearer",
"customer_id": "0d8bb889-36e1-11ee-b9e9-92e504c243a4"
};
const fetchData = async () => {
const headers = {
Authorization: `Bearer ${response.access_token}`,
'Passio-ID': response.customer_id
};
try {
const result = await axios.get('https://api.passiolife.com/v2/products/napi/food/search/advanced?term=pepperoni%20pizza', { headers });
console.log(result.data);
} catch (error) {
console.error(error);
}
};
function App() {
useEffect(() => {
fetchData();
}, []);
return <div>App Component</div>;
}
export default App;
import Foundation
let response = [
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImupZCI6InNab1FMT3oxMkRreHVLNVVVRUJBSCJ9...",
"scope": "read:search read:products",
"expires_in": 86155.034762118,
"token_type": "Bearer",
"customer_id": "0d8bb889-36e1-11ee-b9e9-92e504c243a4"
]
guard let url = URL(string: "https://api.passiolife.com/v2/products/napi/food/search/advanced?term=pepperoni%20pizza") else { return }
var request = URLRequest(url: url)
request.addValue("Bearer \(response["access_token"]!)", forHTTPHeaderField: "Authorization")
request.addValue(response["customer_id"]!, forHTTPHeaderField: "Passio-ID")
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data, error == nil else {
print(error?.localizedDescription ?? "No data")
return
}
if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 {
print("HTTP Status Code: \(httpStatus.statusCode)")
return
}
if let responseString = String(data: data, encoding: .utf8) {
print(responseString)
}
}
task.resume()
curl -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImupZCI6InNab1FMT3oxMkRreHVLNVVVRUJBSCJ9..." \
-H "Passio-ID: 0d8bb889-36e1-11ee-b9e9-92e504c243a4" \
"https://api.passiolife.com/v2/products/napi/food/search/advanced?term=pepperoni%20pizza"