I’m having trouble with
I am trying to import product data from ssactivewear.com via their API. I am new to API’s but i
Working in
e.g. Wix Studio Editor, Wix Editor, Dev Mode
Site link
dev mode wix
What I’m trying to do
Trying to import product data from ss to create products/attributes in wix cms or store.
What I’ve tried so far
When i run a test i get a 500 error in dev mode. This is my .js backend file:
import { fetch } from ‘wix-fetch’; // Import the fetch API
import {getSecret} from ‘wix-secrets-backend’;
export const getApiKey = async ()=>{
const privateKey = await getSecret(“SSactivewearKey”);
return privateKey
}
// Import secrets manager if needed
export async function getExternalData() {
// Use the external API endpoint URL
const url = ‘https://api.ssactivewear.com/v2/brands/’;
// Example of adding headers (including authentication if needed)
const headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + getApiKey() // Access secret here
};
try {
**const** response = **await** fetch(url, { method: 'GET', headers: headers });
**if** (!response.ok) {
**throw** **new** Error(\`HTTP error! status: ${response.status}\`);
}
**const** data = **await** response.json(); // Parse the JSON response
**return** data; // Return the data to the frontend
} catch (error) {
console.error("API call failed:", error);
**return** { error: error.message };
}
}