Created
April 10, 2019 14:26
-
-
Save MuddyBootsCode/bb942cc18ee84d1fec698b6bd20d0b32 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
const axios = require('axios'); | |
const base64 = require('base-64'); | |
const utf8 = require('utf8'); | |
require('dotenv').config(); | |
const clientId = process.env.CLIENT_ID; | |
const clientSecret = process.env.CLIENT_SECRET; | |
const apiKey = process.env.API_KEY; | |
const clientCreds = base64.encode(utf8.encode(`${clientId}:${clientSecret}`)); | |
const tokenConfig = { | |
headers: { | |
'Authorization': `Basic ${clientCreds}`, | |
'Content-type': 'application/x-www-form-urlencoded', | |
'X-API-KEY': `${apiKey}`, | |
} | |
}; | |
const data = 'grant_type=client_credentials'; | |
const getAccessToken = async () => { | |
try { | |
const response = await axios.post(process.env.DI_URL, 'grant_type=client_credentials', tokenConfig); | |
const token = response.data.access_token; | |
console.log(response.data); | |
return token; | |
} catch (error) { | |
console.log(error.status, error.message) | |
} | |
}; | |
let api = ''; | |
const getWellInfo = async (accessToken) => { | |
const wellConfig = { | |
headers: { | |
'Authorization': `Bearer ${accessToken}`, | |
'X-API-KEY': `${apiKey}`, | |
} | |
}; | |
try { | |
const response = await axios.get(`https://di-api.drillinginfo.com/v2/direct-access/producing-entities?state=TX&apiNo=42475367700000&pagesize=10000`, wellConfig); | |
console.log(response.data) | |
} catch { | |
console.log(error.status, error.message) | |
} | |
}; | |
async function getInfo () { | |
try { | |
const accessToken = await getAccessToken(); | |
await getWellInfo(accessToken) | |
} catch { | |
console.log(error) | |
} | |
} | |
getInfo(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment