### Install emnify Python SDK Source: https://docs.emnify.com/developers/sdks/python/quickstart Methods to install the emnify SDK, including standard pip installation and building from source for local development environments. ```shell pip install emnify-sdk ``` ```shell git clone https://github.com/emnify/emnify-sdk-python.git cd emnify-sdk-python python -m build --sdist --wheel ``` -------------------------------- ### Manually install emnify Java SDK Source: https://docs.emnify.com/developers/sdks/java/quickstart Clone the emnify Java SDK repository from GitHub and build it locally using Maven. This method is useful if you need to compile the SDK yourself or contribute to its development. After cloning, run 'mvn install' to build and install the SDK. ```shell git clone git@github.com:emnify/emnify-sdk-java.git cd emnify-sdk-java mvn install # Requires Maven ``` ```shell mvn package ``` -------------------------------- ### Retrieve network coverage collection SDK examples Source: https://docs.emnify.com/developers/mno-and-resellers/api-reference/network-coverage/network-coverage-get Implementation examples for fetching network coverage data across various programming languages. Each example demonstrates how to set the Authorization header with a Bearer token and execute the GET request. ```python import requests url = "https://cdn.emnify.net/api/v1/network_coverage" headers = {"Authorization": "Bearer "} response = requests.get(url, headers=headers) print(response.json()) ``` ```javascript const url = 'https://cdn.emnify.net/api/v1/network_coverage'; const options = {method: 'GET', headers: {Authorization: 'Bearer '}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://cdn.emnify.net/api/v1/network_coverage" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://cdn.emnify.net/api/v1/network_coverage") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = 'Bearer ' response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.get("https://cdn.emnify.net/api/v1/network_coverage") .header("Authorization", "Bearer ") .asString(); ``` ```php request('GET', 'https://cdn.emnify.net/api/v1/network_coverage', [ 'headers' => [ 'Authorization' => 'Bearer ', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://cdn.emnify.net/api/v1/network_coverage"); var request = new RestRequest(Method.GET); request.AddHeader("Authorization", "Bearer "); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = ["Authorization": "Bearer "] let request = NSMutableURLRequest(url: NSURL(string: "https://cdn.emnify.net/api/v1/network_coverage")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Fetch Daily Stats with Start Date Filter (Python, JavaScript, Go, Ruby, Java, PHP) Source: https://docs.emnify.com/developers/api/endpoint/endpoint-stats-daily-by-id-get Shows how to filter daily statistics by a specific start date using the emnify API. These examples demonstrate adding a query parameter to the GET request, alongside the required authentication header. ```python import requests url = "https://cdn.emnify.net/api/v1/endpoint/123/stats/daily" querystring = {"start_date":"2023-03-01"} headers = {"Authorization": "Bearer "} response = requests.get(url, headers=headers, params=querystring) print(response.json()) ``` ```javascript const url = 'https://cdn.emnify.net/api/v1/endpoint/123/stats/daily?start_date=2023-03-01'; const options = {method: 'GET', headers: {Authorization: 'Bearer '}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://cdn.emnify.net/api/v1/endpoint/123/stats/daily?start_date=2023-03-01" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://cdn.emnify.net/api/v1/endpoint/123/stats/daily?start_date=2023-03-01") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = 'Bearer ' response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.get("https://cdn.emnify.net/api/v1/endpoint/123/stats/daily?start_date=2023-03-01") .header("Authorization", "Bearer ") .asString(); ``` ```php request('GET', 'https://cdn.emnify.net/api/v1/endpoint/123/stats/daily?start_date=2023-03-01', [ 'headers' => [ ``` -------------------------------- ### Fetch Daily Stats with Start Date Filter (C#) Source: https://docs.emnify.com/developers/api/endpoint/endpoint-stats-daily-by-id-get This C# example demonstrates fetching daily statistics from the Emnify API using RestSharp, filtering by a start date. It requires the RestSharp NuGet package. ```csharp using RestSharp; var client = new RestClient("https://cdn.emnify.net/api/v1/endpoint/123/stats/daily?start_date=2023-03-01"); var request = new RestRequest(Method.GET); request.AddHeader("Authorization", "Bearer "); IRestResponse response = client.Execute(request); ``` -------------------------------- ### Fetch Data with Default Settings (C#) Source: https://docs.emnify.com/developers/api/cloud-connect/get-cloud-connect-attachments An example in C# using the RestSharp library to make a GET request to the emnify API's breakout endpoint. It demonstrates configuring the RestClient, creating a GET request, adding the authorization header, and executing the request. ```csharp using RestSharp; var client = new RestClient("https://cdn.emnify.net/api/v1/cnc/breakout"); var request = new RestRequest(Method.GET); request.AddHeader("Authorization", "Bearer "); IRestResponse response = client.Execute(request); ``` -------------------------------- ### Fetch Hourly Stats with Start Date Filter (PHP) Source: https://docs.emnify.com/developers/api/organization/get-organisation-hourly-stats Retrieves hourly statistics from the Emnify API, filtered by a specified start date. This example uses the Guzzle HTTP client and requires the Guzzle library to be installed via Composer. It sends a GET request with an Authorization header. ```php request('GET', 'https://cdn.emnify.net/api/v1/organisation/my/stats/hourly?start_date=2020-02-01T00%3A00%3A00.000Z', [ 'headers' => [ 'Authorization' => 'Bearer ', ], ]); echo $response->getBody(); ?> ``` -------------------------------- ### Initialize and use emnify SDK Source: https://docs.emnify.com/developers/sdks/python/quickstart Demonstrates how to authenticate the SDK using an environment variable and retrieve a list of devices from the emnify platform. ```python import os from emnify import EMnify # Initiate the SDK instance using your application token emnify = EMnify(os.environ["EMNIFY_TOKEN"]) # Execute a command against the desired API devices = emnify.devices.get_devices_list() # Show all the devices print([device for device in devices]) ``` -------------------------------- ### Fetch Data with Default Settings (Go) Source: https://docs.emnify.com/developers/api/cloud-connect/get-cloud-connect-attachments Provides a Go example for making a GET request to the emnify API's breakout endpoint. It demonstrates creating an HTTP request, setting headers, sending the request, and reading the response body. Includes printing the response status and body. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://cdn.emnify.net/api/v1/cnc/breakout" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Configure Automation - Go SDK Source: https://docs.emnify.com/developers/api/automations/get-automation This Go code example illustrates fetching automation data from the emnify API. It constructs an HTTP GET request, sets the necessary authorization header, sends the request, and then prints the response status and body. Ensure to replace '' with your actual API token. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://cdn.emnify.net/api/v1/automation/id" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Retrieve Tariff Profile Coverage (Go) Source: https://docs.emnify.com/developers/api/tariff-profiles/tariff-profile-coverage-by-tp-id-get Fetches tariff profile coverage data using Go's standard net/http package. This example demonstrates creating an HTTP GET request, setting the Authorization header, sending the request, and printing the response body. It includes basic error handling for the request and reading the body. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://cdn.emnify.net/api/v1/tariff_profile/1.1/coverage" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Fetch Daily Stats with Date Range Filter (Python) Source: https://docs.emnify.com/developers/api/endpoint/endpoint-stats-daily-by-id-get This Python example uses the requests library to fetch daily statistics from the Emnify API, filtering by both a start and end date. Ensure the 'requests' library is installed. ```python import requests url = "https://cdn.emnify.net/api/v1/endpoint/123/stats/daily" querystring = {"start_date":"2023-03-01","end_date":"2023-03-07"} headers = {"Authorization": "Bearer "} response = requests.get(url, headers=headers, params=querystring) print(response.json()) ``` -------------------------------- ### Fetch Hourly Stats with Start Date Filter (Swift) Source: https://docs.emnify.com/developers/api/organization/get-organisation-hourly-stats Retrieves hourly statistics from the Emnify API, filtered by a start date. This Swift example utilizes Foundation's URLSession for network requests. It sets the HTTP method to GET and includes an Authorization header. ```swift import Foundation let headers = ["Authorization": "Bearer "] let request = NSMutableURLRequest(url: NSURL(string: "https://cdn.emnify.net/api/v1/organisation/my/stats/hourly?start_date=2020-02-01T00%3A00%3A00.000Z")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Create User via emnify API (Python, JavaScript, Go, Ruby, Java, PHP, C#, Swift) Source: https://docs.emnify.com/developers/api/user-management/user-per-page-sort-by-q-and-page-post Demonstrates how to create a new user in the emnify platform by sending a POST request to the /user endpoint. This involves setting the correct URL, headers (including authorization token and content type), and a JSON payload containing user details. Each example uses a different language's standard HTTP client library or a popular third-party library. ```python import requests url = "https://cdn.emnify.net/api/v1/user" payload = { "username": "eabbot@flatland.org", "name": "Edwin Abbott", "organisation": { "id": 123 }, "roles": [{ "id": 1 }, { "id": 2 }] } headers = { "Authorization": "Bearer ", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://cdn.emnify.net/api/v1/user'; const options = { method: 'POST', headers: {Authorization: 'Bearer ', 'Content-Type': 'application/json'}, body: '{"username":"eabbot@flatland.org","name":"Edwin Abbott","organisation":{"id":123},"roles":[{"id":1},{"id":2}]}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://cdn.emnify.net/api/v1/user" payload := strings.NewReader("{\n \"username\": \"eabbot@flatland.org\",\n \"name\": \"Edwin Abbott\",\n \"organisation\": {\n \"id\": 123\n },\n \"roles\": [\n {\n \"id\": 1\n },\n {\n \"id\": 2\n }\n ]\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://cdn.emnify.net/api/v1/user") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{\n \"username\": \"eabbot@flatland.org\",\n \"name\": \"Edwin Abbott\",\n \"organisation\": {\n \"id\": 123\n },\n \"roles\": [\n {\n \"id\": 1\n },\n {\n \"id\": 2\n }\n ]\n}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://cdn.emnify.net/api/v1/user") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{\n \"username\": \"eabbot@flatland.org\",\n \"name\": \"Edwin Abbott\",\n \"organisation\": {\n \"id\": 123\n },\n \"roles\": [\n {\n \"id\": 1\n },\n {\n \"id\": 2\n }\n ]\n}") .asString(); ``` ```php request('POST', 'https://cdn.emnify.net/api/v1/user', [ 'body' => '{\n "username": "eabbot@flatland.org",\n "name": "Edwin Abbott",\n "organisation": {\n "id": 123\n },\n "roles": [\n {\n "id": 1\n },\n {\n "id": 2\n }\n ]\n}', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ?> ``` ```csharp using RestSharp; var client = new RestClient("https://cdn.emnify.net/api/v1/user"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"username\": \"eabbot@flatland.org\",\n \"name\": \"Edwin Abbott\",\n \"organisation\": {\n \"id\": 123\n },\n \"roles\": [\n {\n \"id\": 1\n },\n {\n \"id\": 2\n }\n ]\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = [ "username": "eabbot@flatland.org", "name": "Edwin Abbott", "organisation": ["id": 123], "roles": [["id": 1], ["id": 2]] ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://cdn.emnify.net/api/v1/user")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Install emnify Java SDK with Gradle Source: https://docs.emnify.com/developers/sdks/java/quickstart Include the emnify Java SDK dependency in your Gradle project. Ensure you replace 'SDK_VERSION' with the correct version number. Gradle will then handle the dependency resolution and inclusion. ```gradle implementation group: "com.emnify.sdk", name: "emnify", version: "SDK_VERSION" ``` -------------------------------- ### Install emnify Java SDK with Maven Source: https://docs.emnify.com/developers/sdks/java/quickstart Add the emnify Java SDK dependency to your Maven project. Replace 'SDK_VERSION' with the specific version you are using. This allows Maven to manage the SDK as a project dependency. ```xml com.emnify.sdk emnify SDK_VERSION ``` -------------------------------- ### Retrieve Service Info using emnify SDK (Python, JavaScript, Go, Ruby, Java, PHP, C#, Swift) Source: https://docs.emnify.com/developers/api/service-lookups-and-configuration/service-get These examples show how to make a GET request to the emnify API's /service endpoint to retrieve service information. They require an authorization token and demonstrate common HTTP client libraries for each language. The output is typically the JSON response body. ```python import requests url = "https://cdn.emnify.net/api/v1/service" headers = {"Authorization": "Bearer "} response = requests.get(url, headers=headers) print(response.json()) ``` ```javascript const url = 'https://cdn.emnify.net/api/v1/service'; const options = {method: 'GET', headers: {Authorization: 'Bearer '}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://cdn.emnify.net/api/v1/service" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://cdn.emnify.net/api/v1/service") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = 'Bearer ' response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.get("https://cdn.emnify.net/api/v1/service") .header("Authorization", "Bearer ") .asString(); ``` ```php request('GET', 'https://cdn.emnify.net/api/v1/service', [ 'headers' => [ 'Authorization' => 'Bearer ', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://cdn.emnify.net/api/v1/service"); var request = new RestRequest(Method.GET); request.AddHeader("Authorization", "Bearer "); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = ["Authorization": "Bearer "] let request = NSMutableURLRequest(url: NSURL(string: "https://cdn.emnify.net/api/v1/service")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Fetch Data with Default Settings (Java) Source: https://docs.emnify.com/developers/api/cloud-connect/get-cloud-connect-attachments A Java example using the Unirest library to make a GET request to the emnify API's breakout endpoint. It demonstrates setting the URL and the authorization header, then executing the request and retrieving the response as a string. ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.get("https://cdn.emnify.net/api/v1/cnc/breakout") .header("Authorization", "Bearer ") .asString(); ``` -------------------------------- ### Fetch Emnify Connectivity Info (PHP) Source: https://docs.emnify.com/developers/api/endpoint/get-connectivity-info-by-endpoint-id Fetches connectivity information from the Emnify API using the Guzzle HTTP client in PHP. This example requires the Guzzle library to be installed via Composer. It makes a GET request with the specified headers and echoes the response body. ```php request('GET', 'https://cdn.emnify.net/api/v1/endpoint/12345/connectivity_info?subscriber=true', [ 'headers' => [ 'Authorization' => 'Bearer ', ], ]); echo $response->getBody(); ``` -------------------------------- ### Fetch Data with Default Settings (Ruby) Source: https://docs.emnify.com/developers/api/cloud-connect/get-cloud-connect-attachments Illustrates how to perform a GET request to the emnify API's breakout endpoint using Ruby's Net::HTTP library. It shows setting up the URI, making the request with SSL, adding the authorization header, and printing the response body. ```ruby require 'uri' require 'net/http' url = URI("https://cdn.emnify.net/api/v1/cnc/breakout") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = 'Bearer ' response = http.request(request) puts response.read_body ``` -------------------------------- ### Retrieve Tariff Profile Coverage (PHP) Source: https://docs.emnify.com/developers/api/tariff-profiles/tariff-profile-coverage-by-tp-id-get Retrieves tariff profile coverage data using the Guzzle HTTP client in PHP. This example requires the Guzzle library to be installed via Composer. It sends a GET request to the emnify API with the specified authorization header and outputs the response body. ```php request('GET', 'https://cdn.emnify.net/api/v1/tariff_profile/1.1/coverage', [ 'headers' => [ 'Authorization' => 'Bearer ', ], ]); echo $response->getBody(); ``` -------------------------------- ### Create KeenIO Data Stream Source: https://docs.emnify.com/developers/api/integrations/create-data-streamer Configures a new data stream with a KeenIO destination. Requires project ID and write key credentials. ```python import requests url = "https://cdn.emnify.net/api/v2/data_stream" payload = { "name": "My KeenIO Stream", "destination": { "connection_type": "KeenIO", "format": "Json", "credentials": { "project_id": "1234567890abcdef12345678", "write_key": "...", "collection_name": "MyDataStream", "size": 3000 } }, "data_stream_type": { "id": 1 } } headers = {"Authorization": "Bearer ", "Content-Type": "application/json"} response = requests.post(url, json=payload, headers=headers) ``` ```javascript const url = 'https://cdn.emnify.net/api/v2/data_stream'; const options = { method: 'POST', headers: {Authorization: 'Bearer ', 'Content-Type': 'application/json'}, body: '{"name":"My KeenIO Stream","destination":{"connection_type":"KeenIO","format":"Json","credentials":{"project_id":"1234567890abcdef12345678","write_key":"...","collection_name":"MyDataStream","size":3000}},"data_stream_type":{"id":1}}' }; const response = await fetch(url, options); ``` -------------------------------- ### Fetch Hourly Stats with Date Range Filter (Swift) Source: https://docs.emnify.com/developers/api/organization/get-organisation-hourly-stats Fetches hourly statistics from the Emnify API, filtered by a date range. This Swift example uses URLSession to perform the GET request, setting the Authorization header and the URL with start and end date parameters. ```swift import Foundation let headers = ["Authorization": "Bearer "] let request = NSMutableURLRequest(url: NSURL(string: "https://cdn.emnify.net/api/v1/organisation/123/stats/hourly?start_date=2020-02-01T00%3A00%3A00.000Z&end_date=2020-02-15T00%3A00%3A00.000Z")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Fetch Endpoint Quota Data using Ruby Source: https://docs.emnify.com/developers/api/endpoint/endpoint-quota-data-by-endpoint-id-get This Ruby script fetches endpoint quota data from the emnify API using the `net/http` library. It constructs a GET request, sets the Authorization header, and sends it over HTTPS. The response body is then printed to standard output. This example assumes basic Ruby environment setup. ```ruby require 'uri' require 'net/http' url = URI("https://cdn.emnify.net/api/v1/endpoint/endpoint_id/quota/data") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = 'Bearer ' response = http.request(request) puts response.read_body ``` -------------------------------- ### Default Assignment SDK Examples (Python, JavaScript, Go, Ruby, Java, PHP, C#, Swift) Source: https://docs.emnify.com/developers/api/organization/assign-ratezone-inclusive-volume Demonstrates how to perform a default assignment using the emnify SDK. This involves making a PUT request to the inclusive volume endpoint with an empty JSON body. It requires authentication via a Bearer token and specifies the content type as application/json. ```python import requests url = "https://cdn.emnify.net/api/v1/organisation/1234/inclusive_volume/5678" payload = {} headers = { "Authorization": "Bearer ", "Content-Type": "application/json" } response = requests.put(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://cdn.emnify.net/api/v1/organisation/1234/inclusive_volume/5678'; const options = { method: 'PUT', headers: {Authorization: 'Bearer ', 'Content-Type': 'application/json'}, body: '{}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://cdn.emnify.net/api/v1/organisation/1234/inclusive_volume/5678" payload := strings.NewReader("{}") req, _ := http.NewRequest("PUT", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://cdn.emnify.net/api/v1/organisation/1234/inclusive_volume/5678") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Put.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.put("https://cdn.emnify.net/api/v1/organisation/1234/inclusive_volume/5678") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{}") .asString(); ``` ```php request('PUT', 'https://cdn.emnify.net/api/v1/organisation/1234/inclusive_volume/5678', [ 'body' => '{}', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ?> ``` ```csharp using RestSharp; var client = new RestClient("https://cdn.emnify.net/api/v1/organisation/1234/inclusive_volume/5678"); var request = new RestRequest(Method.PUT); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = [] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://cdn.emnify.net/api/v1/organisation/1234/inclusive_volume/5678")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "PUT" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### GET /api/v1/endpoint Source: https://docs.emnify.com/developers Example of an authenticated request using the JWT obtained from the authentication endpoint. ```APIDOC ## GET /api/v1/endpoint ### Description Retrieves data from the API using the JWT in the Authorization header. ### Method GET ### Endpoint https://cdn.emnify.net/api/v1/endpoint ### Parameters #### Headers - **Authorization** (string) - Required - Bearer ### Request Example GET /api/v1/endpoint Authorization: Bearer ### Response #### Success Response (200) - **data** (object) - The requested resource data. #### Response Example { "status": "success", "data": { ... } } ``` -------------------------------- ### Get a Single Order Source: https://docs.emnify.com/developers/mno-and-resellers/api-reference/sim-order-management/shop-get-order Demonstrates how to retrieve a single order from the emnify API. This requires an API token for authentication. The examples show making a GET request to the specified URL and handling the response. ```python import requests url = "https://cdn.emnify.net/api/v1/shop/order/1.1" headers = {"Authorization": "Bearer "} response = requests.get(url, headers=headers) print(response.json()) ``` ```javascript const url = 'https://cdn.emnify.net/api/v1/shop/order/1.1'; const options = {method: 'GET', headers: {Authorization: 'Bearer '}}; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://cdn.emnify.net/api/v1/shop/order/1.1" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://cdn.emnify.net/api/v1/shop/order/1.1") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Get.new(url) request["Authorization"] = 'Bearer ' response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.get("https://cdn.emnify.net/api/v1/shop/order/1.1") .header("Authorization", "Bearer ") .asString(); ``` ```php request('GET', 'https://cdn.emnify.net/api/v1/shop/order/1.1', [ 'headers' => [ 'Authorization' => 'Bearer ', ], ]); echo $response->getBody(); ?> ``` ```csharp using RestSharp; var client = new RestClient("https://cdn.emnify.net/api/v1/shop/order/1.1"); var request = new RestRequest(Method.GET); request.AddHeader("Authorization", "Bearer "); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = ["Authorization": "Bearer "] let request = NSMutableURLRequest(url: NSURL(string: "https://cdn.emnify.net/api/v1/shop/order/1.1")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "GET" request.allHTTPHeaderFields = headers let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Create Service Profile with DNS Object (Python, JavaScript, Go, Ruby, Java, PHP, C#, Swift) Source: https://docs.emnify.com/developers/api/service-profiles/service-profile-post Demonstrates how to create a service profile and apply DNS configurations using the emnify API. This snippet requires an API token for authentication and sends a JSON payload specifying the service profile name and DNS settings. It's compatible with Python, JavaScript, Go, Ruby, Java, PHP, C#, and Swift. ```python import requests url = "https://cdn.emnify.net/api/v1/service_profile" payload = { "name": "DNS config applied", "dns": { "id": 3 } } headers = { "Authorization": "Bearer ", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://cdn.emnify.net/api/v1/service_profile'; const options = { method: 'POST', headers: {Authorization: 'Bearer ', 'Content-Type': 'application/json'}, body: '{"name":"DNS config applied","dns":{"id":3}}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://cdn.emnify.net/api/v1/service_profile" payload := strings.NewReader("{\n \"name\": \"DNS config applied\",\n \"dns\": {\n \"id\": 3\n }\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://cdn.emnify.net/api/v1/service_profile") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{\n \"name\": \"DNS config applied\",\n \"dns\": {\n \"id\": 3\n }\n}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://cdn.emnify.net/api/v1/service_profile") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{\n \"name\": \"DNS config applied\",\n \"dns\": {\n \"id\": 3\n }\n}") .asString(); ``` ```php request('POST', 'https://cdn.emnify.net/api/v1/service_profile', [ 'body' => '{ "name": "DNS config applied", "dns": { "id": 3 } }', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ?> ``` ```csharp using RestSharp; var client = new RestClient("https://cdn.emnify.net/api/v1/service_profile"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"name\": \"DNS config applied\",\n \"dns\": {\n \"id\": 3\n }\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = [ "name": "DNS config applied", "dns": ["id": 3] ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://cdn.emnify.net/api/v1/service_profile")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ``` -------------------------------- ### Configure Custom Event Threshold via API (Go) Source: https://docs.emnify.com/developers/api/custom-events/create-custom-event-instance This Go program demonstrates how to make a POST request to the emnify API to set up custom event configurations. It uses the standard `net/http` package and `strings.NewReader` for the payload. Ensure you replace `` with your actual API token. ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://cdn.emnify.net/api/v1/event/custom/configuration" payload := strings.NewReader("{ \n \"organisation\": { \n \"id\": 200 \n }, \n \"template\": { \n \"id\": 1 \n }, \n \"configuration_properties\": [ \n { \n \"property\": \"count_of_pdp\", \n \"value\": \"10\", \n \"value_array\": [ \n \"string\" \n ] \n }, \n { \n \"property\": \"duration\", \n \"value\": \"1w\", \n \"value_array\": [ \n \"string\" \n ] \n } \n ], \n \"name\": \"PDP Threshold 50 Over One Week\" \n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### Get Callback Secret by ID - Go SDK Example Source: https://docs.emnify.com/developers/api/integrations/get-callback-secretby-id This Go code snippet illustrates how to make an HTTP GET request to retrieve a callback secret by ID. It shows how to set the Authorization header and read the response body. ```go package main import ( "fmt" "net/http" "io" ) func main() { url := "https://cdn.emnify.net/api/v1/api_secret/1" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` -------------------------------- ### API Paging Example (Bash) Source: https://docs.emnify.com/developers/api-guidelines/collections-pagination Demonstrates how to make a paginated API request using curl. It specifies the desired page number and the number of items per page. The response headers provide navigation links and dataset metadata. ```bash curl -v -H "Authorization: Bearer AUTH_TOKEN" "https://cdn.emnify.net/api/v1/endpoint?page=3&per_page=100" ```