Contact Us

cancel
Showing results for 
Search instead for 
Did you mean: 
Moderator
Moderator

How to create multiple endpoints via API?

The SAP IoT Connect 365 API documentation describes how to create one endpoint. By using Postman we will explain how to create x number of endpoints at once. Let's first take a look at the information we need to gather about an endpoint in order to create one (point 1). We'll then send two APIs requests to create multiple endpoints (point 2) at once and we will finally create them (point 3).

 

1. Necessary information to create an endpoint

According to the API documentation, the POST API used to create one endpoint on the SAP IoT Connect 365 platform, needs to have the following information:

  • Name of the endpoint (required);
  • Tags (optional) - You have the possibility to add specific information for each endpoint.
  • Status: activate or not (required) - is the endpoint activated or disable.
  • Service profile (required) - ID of the Service Profile assigned to the endpoint. To find this information, navigate to the "Service Profiles" tab in the UI or run this API.
  • Tariff profile (required) - ID of the tariff Profile assigned to the endpoint. To find this information, navigate to the "Tariff Profiles" tab in the UI or run this API.
  • SIM (optional) - if we want to directly assign a SIM to the created endpoint, we need to enter here the SIM ID.  To find this information, navigate to the SIMs tab in the UI.

For each endpoint we want to create, the information detailed above must be entered. In order to create several of them at once, we can use the "Runner" option in Postman. To do so, create a .csv file (separated with comma) and enter the information as follow:

 

sim_id

 endpointname 

tag

 serviceprofile 

 tariffprofile 

233622

JEtest1

 customerA 

129069

128197

333339

JEtest2

customerB

121168

1299

 

The numbers of rows you have should be equal to the number of endpoints you wish to create i.e. you need one row for each endpoint.

 

2. Preparing the APIs to run

To run any API on our platform, you need to authenticate (point 2.1) and then run the endpoint creation API (point 2.2)

 

 2.1 Authentication

POST https://sapiotconnect365.sapmobileservices.com/api/doc/SAP-API-collapsible.html#authentication

Click here to learn more about the API authentication methods available.

 

 2.2 Creating the endpoints based on these information

POST https://sapiotconnect365.sapmobileservices.com/api/doc/SAP-API-collapsible.html#endpoint

 

Header :
Content-type: application/json
Authorization: Bearer {{auth_token}}

 

Body

{
"name": "{{endpointname}}",
"tags": "{{tag}}",
"status": {
 "id": 0
},
"service_profile": {
 "id": {{serviceprofile}}
},
"tariff_profile": {
 "id": {{tariffprofile}}
},
"sim": {
 "id": {{sim_id}},
 "activate": true
}
}

 

The {{variables}} need to be created based on the information in our .csv file before the API is called. For this, we use the "Pre-request Script" option available in Postman.

 

Pre-request Script (in Postman this is used to create these variables based on the .csv file we created before running the API):

 

console.log("sim_id" + data.sim_id)
console.log("endpointname" + data.endpointname)
console.log("tag" + data.tag)
console.log("serviceprofile" + data.serviceprofile)
console.log("tariffprofile" + data.tariffprofile) 

 

3. Running the different APIs at once

We are now ready to run the APIs multiple times and create several endpoints at once. In Postman, click Runner, select a collection, an environment, and your '.csv' file. The number of iterations should then automatically be detected. You can preview your file to be sure that everything is fine before clicking start run. This is how the preview should look like: 

 

How to create multiple endpoints via API copy.png

 

3.1 Responses if everything went fine

Authentication post API: 200 OK
Create endpoint post API: 201 Created

 

3.2 Responses when you have an issue

If your authentication API failed, nothing will work.

If the endpoint creation API failed, check the following:

  • Is your .csv file comma delimited (excel can be a bit messy sometimes, you can try another program like notepad++);
  • Check the spelling of your variables: they should be written exactly the same way in the .csv file and in Postman;
  • Check the format of the API body where it is easy to forget a character.

 

John Candish Product Manager, SAP IoT Connect 365
Labels (2)
Tags (1)
0 Kudos