Importing JSON data from 3rd party API

Hi,

I think this platform does exactly what I need but need a little guidance please ?

Problem: Import the JSON response from a 3rd party API. I must be able to set the headers. eg
Key: I understand I have to use my API key
Authorization: Basic >>>insert my auth string<<<
Accept: application/json
Transaction-id (my own custom transaction id)

I have all the above

After reading up I understand I will need to use wix-fetch (I read that here wix-fetch - Velo API Reference - Wix.com so I can set the API endpoint)

After reading this WixHttpFunctionResponse - Velo API Reference - Wix.com I think I would set my response headers here but please correct me if I am wrong.

Finally I am not sure how I would combine all that eg

I would use;
import {fetch} from ‘wix-fetch’; // … fetch(‘3rd partys api endpoinyt url here’, {method: ‘get’}) but how or where would I insert this

// In http-functions.js export function use_myFunction(request) { const headers = { key": “my api key”, “Authorization”: “Basic (my base64 auth string)” }; response.headers = headers; }

and is the http-functions.js just the name of javascript file ? The data will be displayed to users on the front end but they need not interact with it

I have not yet started creating the site yet, as I want to be certain it can be done. Can anybody give me a path to solution. Thank you in advance

Hi,

Wix fetch is what you want to use.
HTTP functions allow you to expose site functionality to third party tools (which is kinda the opposite of what you are trying to achieve)

See how to add headers to a fetch request below:

var headers = {
	"Accept": "application/json",
	"transactionId": "someId",
	"key": "4k2j4kj234fkaksdjkd"
};

var options = {
	method: 'GET',
	headers: headers
};

fetch(azure, options);
//...

Thank you Ido for such a speedy and easy to understand response. I will begin working on this tomorrow