-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a636c34
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
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
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) |
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
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" | ||
} | ||
} |
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
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 |