Skip to content

Instantly share code, notes, and snippets.

@MuddyBootsCode
Created April 10, 2019 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MuddyBootsCode/231e4a7149289aa515a37e911c010d1a to your computer and use it in GitHub Desktop.
Save MuddyBootsCode/231e4a7149289aa515a37e911c010d1a to your computer and use it in GitHub Desktop.
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;
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();
/* Example Response
[ { Abstract: '1405',
AllocPlus: 'Y',
ApiNo: '42475367700000',
Basin: 'PERMIAN BASIN',
CommingleDate: null,
CommingleNo: '0',
CommonOperName: 'HALCON OPERATING COMPANY INC',
CompDate: '2015-03-13T00:00:00Z',
Country: 'USA',
County: 'WARD (TX)',
CountyId: '42475',
CreatedDate: '2017-04-24T19:07:53.08Z',
CurrOperId: 100335900,
CurrOperName: 'HALCON OPERATING COMPANY INC',
CurrOperNo: '344412',
DeletedDate: null,
District: '08',
DrillType: 'H',
Elevation: 2868,
ElevationType: 'GRD',
EntityId: 129019241,
Field: 'PHANTOM',
FieldNo: '71052900',
Formation: 'WOLFCAMP',
GasGrav: null,
Geom: '0101000020E61000002AB121EEA0D859C0B77AA93352A23F40',
IsDeleted: false,
Latitude: 31.6340668,
LatitudeBotm: null,
LatitudeEx1: 31.6340668,
LeaseId: 128256854,
LeaseNo: '42153',
LesseeAvail: '',
LiqGrav: 40,
LocRemark: '730 NE 000650 NW',
Location: '(N/A)',
Longitude: -103.3848224,
LongitudeBotm: null,
LongitudeEx1: -103.3848224,
LowerPerf: 15587,
MaxVertDepth: null,
Merid: '',
OcsArea: '(N/A)',
Offshore: 'U',
PdenName: 'MONROE 1-8 WRD',
PdenType: 'COM',
PerfIntervalLength: 3681,
PgcArea: 'P-440',
ProdType: 'OIL',
QtrQtr: '(N/A)',
QuadName: '',
ReportedOperName: 'HALCON OPERATING CO., INC.',
ResVertDepth: null,
Reservoir: 'WOLFCAMP',
RkbElev: null,
Rng: '0',
Section: '8',
SpudDate: '2014-09-17T00:00:00Z',
State: 'TX',
Status: 'ACTIVE',
SubSurvey: 'LEE, M',
Survey: 'W&NW RR CO',
TotalDepth: 16044,
Twp: '0',
TxBlock: '1',
TxScrap: '',
TxSec: '8',
UpdatedDate: '2019-01-09T16:00:03.84Z',
UpperPerf: 11906,
WaterDepth: null,
WellId: null,
WellNo: '3H' } ]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment