This hook is deprecated. For more information, see Migrating from sdk-react.
The useWixFetchWithAuth()
hook returns a function for making requests to the Wix REST API and external endpoints that require a Wix access token. The access token is generated using authentication details from the enclosing WixProvider
and is automatically included in requests as an Authorization
header.
Note: Only use this function to call a Wix REST API if the needed functionality isn't available in the JavaScript SDK. Otherwise, use the SDK version.
import { useWixFetchWithAuth } from "@wix/sdk-react";
//...
const fetchWithAuth = useWixFetchWithAuth();
//...
const response = await fetchWithAuth(
"https://www.wixapis.com/stores/v1/products/query",
{
method: "POST",
headers: {
"Content-Type": "app/json",
},
body: JSON.stringify({}),
},
);