Skip to content

Instantly share code, notes, and snippets.

@dev-w3
Last active July 21, 2021 09:09
Show Gist options
  • Save dev-w3/44ba8f920740642ad68b58375dfbc114 to your computer and use it in GitHub Desktop.
Save dev-w3/44ba8f920740642ad68b58375dfbc114 to your computer and use it in GitHub Desktop.
Wix - Velo: Accessing 3rd-Party Services with the Fetch API
// API Reference: https://www.wix.com/velo/reference/api-overview/introduction
// “Hello, World!” Example: https://learn-code.wix.com/en/article/1-hello-world
import wixData from 'wix-data';
import { getJSON } from 'wix-fetch';
import {local} from 'wix-storage';
export function getrentallistings () {
const mySecret = 'key_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
/*
https://api.domain.com.au/v1/listings/residential/_search
{
"listingType": "Sale"
}
curl -X POST "https://api.domain.com.au/v1/listings/residential/_search" -H "accept: application/json" -H "Content-Type: application/json" -H "X-Api-Key: key_91ce84fffc725f5e1416f52c73cb7da4" -d "{\"listingType\":\"Sale\"}"
second Method:
curl -X POST "https://api.domain.com.au/v1/listings/residential/_search" -H "accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer e9c54d4c48200885d486e849a21a5244" -d "{ \"listingType\": \"Sale\",}"
*/
/*
return fetch("https://api.domain.com.au/v1/listings/residential/_search", {
body: '{"listingType":"Sale"}',
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"X-Api-Key": "key_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
},
method: "POST"
})
*/
return fetch("https://api.domain.com.au/v1/agencies/13566/listings?listingStatusFilter=live", {
headers: {
Accept: "application/json",
Authorization: "Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
}
})
.then( (httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
} else {
return Promise.reject("Fetch did not succeed");
}
} )
.then( (json) => {
return json;
} )
.catch(err => console.log(err));
}
async function renderUsers() {
let pro = await getrentallistings();
let htmls = '';
pro.forEach((property, index) => {
console.log(property);
// property.listings.forEach((prop, i) => {
let htmlSegment = `<div class="itemslisting" style="width:33%;float:left">
<div class="innerlist" style="width:100%;float:left;padding: 10px 20px;background: #f1f1f1;">
<a href="${property.seoUrl}" target="_blank">
<h2 class="font_3" style="font-size: 22px;margin-bottom: 10px;font-weight: bold;color: #002040;">${property.headline} </h3>
<img src="${property.media[0].url}" width="100%" >
<p class="price" style="margin:10px 0;font-weight:bold;">Price: ${property.priceDetails.displayPrice} </p>
<p class="price" style="margin:0;font-weight:bold;"> Address: ${property.addressParts.displayAddress} </p>
<div class="" style="margin:10px 0;"><p>${property.description} </p> </div>
</a>
<a href="${property.seoUrl}" target="_blank" style="padding: 15px;background: #002040;float: left;width: 102px;text-align: center;color: #fff;font-size: 13px;border-radius: 6px;">Full Detail</a>
</div>
</div>`;
htmls += htmlSegment;
// });
});
$w('#text11').html = htmls;
}
$w.onReady(function () {
var data = getrentallistings();
console.log(data);
renderUsers();
});
@dev-w3
Copy link
Author

dev-w3 commented Jul 21, 2021

Third Party API Integration in Wix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment