Last active
November 21, 2019 11:23
-
-
Save zoetrope69/79e352c794795119d99c17586de623bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("dotenv").config(); | |
const fetch = require("node-fetch"); | |
const { | |
SKIMLINKS_CLIENT_ID, | |
SKIMLINKS_CLIENT_SECRET, | |
SKIMLINKS_PUBLISHED_ID | |
} = process.env; | |
// const EXAMPLE_URL = "https://www.asos.com/women/?skimoffer=865358"; | |
const authenticateWithSkimlinks = () => { | |
return fetch("https://authentication.skimapis.com/access_token", { | |
method: "POST", | |
headers: { "Content-Type": "application/json" }, | |
body: JSON.stringify({ | |
client_id: SKIMLINKS_CLIENT_ID, | |
client_secret: SKIMLINKS_CLIENT_SECRET, | |
grant_type: "client_credentials" | |
}) | |
}) | |
.then(response => response.json()) | |
.then(response => response.access_token); | |
}; | |
const getOffers = access_token => { | |
console.log("access_token", access_token); | |
const params = { access_token, search: "asos.com", limit: 100 }; | |
const urlParams = new URLSearchParams(Object.entries(params)); | |
return fetch( | |
`https://merchants.skimapis.com/v4/publisher/${SKIMLINKS_PUBLISHED_ID}/offers?` + | |
urlParams | |
) | |
.then(response => response.json()) | |
.then(response => { | |
console.log(response.hasMore); | |
return response.offers || []; | |
}); | |
}; | |
authenticateWithSkimlinks() | |
.then(getOffers) | |
.then(offers => offers.map(offer => offer.url)) | |
.then(console.log) | |
.catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment