-
Notifications
You must be signed in to change notification settings - Fork 25
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
Pascal Pickel
authored and
Pascal Pickel
committed
Apr 16, 2024
1 parent
6368b33
commit a6af456
Showing
8 changed files
with
554 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Binary file not shown.
Binary file not shown.
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
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,43 @@ | ||
/* | ||
* Copyright (c) 2023 Nordic Semiconductor ASA | ||
* | ||
* SPDX-License-Identifier: LicenseRef-Nordic-4-Clause | ||
*/ | ||
|
||
interface ImeiAllocationResource { | ||
createdAt: string; | ||
id: string; | ||
imeis: string; | ||
product: 'nRF9131' | 'nRF9151' | 'nRF9161'; | ||
scope: 'DEVELOPMENT' | 'PRODUCTION'; | ||
} | ||
|
||
export default async ( | ||
product: 'nRF9131' | 'nRF9151' | 'nRF9161', | ||
scope: 'DEVELOPMENT' | 'PRODUCTION', | ||
apiKey: string | ||
) => { | ||
const response = await fetch( | ||
'https://api.imei.nrfcloud.com/v1/imei-management/allocations', | ||
{ | ||
method: 'POST', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${apiKey}`, | ||
}, | ||
body: JSON.stringify({ scope, product, count: 1 }), | ||
} | ||
); | ||
|
||
if (response.status !== 200) { | ||
throw new Error( | ||
`Error fetching IMEI: ${response.status}.${ | ||
response.statusText ? `statusText: ${response.statusText}` : '' | ||
}. Make sure the API key is valid.` | ||
); | ||
} | ||
|
||
const imei = ((await response.json()) as ImeiAllocationResource).imeis[0]; | ||
return imei; | ||
}; |
Oops, something went wrong.