Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
freeall committed Nov 10, 2021
0 parents commit a636c34
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
26 changes: 26 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const express = require('express')
const axios = require('axios')

const API_KEY = process.env.API_KEY
const TAG_ID = process.env.TAG_ID

const app = express()

axios.defaults.baseURL = 'https://api.onomondo.com'
axios.defaults.headers.common['authorization'] = API_KEY

app.post('/imei_lock', express.json(), async (req, res) => {
const simId = req.body.sim_id
const imei = req.body.imei

console.log(`Received webhook request: ${JSON.stringify(req.body)}`)

// Set the IMEI Lock
await axios.patch(`/sims/${simId}`, { imei_lock: imei })

// Remove the tag from the sim, ensuring that this webhook is not called again
await axios.delete(`/sims/${simId}/tags/${TAG_ID}`)

console.log(`Done setting IMEI lock for ${simId}`)
})
app.listen(process.env.PORT || 8145)
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "automatic-imei-lock-service",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"axios": "^0.24.0",
"express": "^4.17.1"
},
"description": "Example code of how to create a webhooks service that automatically will set the IMEI lock the first time a SIM comes online",
"scripts": {
"start": "node index.js"
}
}
11 changes: 11 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# automatic-imei-lock-service

This is example code of how to create a webhooks service that automatically will set the IMEI lock the first time a SIM comes online.

## Deploy to Heroku

The repository serves as an example, but can actually be deployed as-is to Heroku and used without changing the code.

All you have to do is set to `Environment Variables`:
* Set `API_KEY` to the api key you received from Onomondo
* Set `TAG_ID` to the tag id of the "Never Used" tag you created

0 comments on commit a636c34

Please sign in to comment.