Examples
The following examples provide a foundation to begin using the search route. Remember that you can always change the content of the rules
array to the search query that fits your search.
United States region
The examples below use the EU region API.
If you wish to use the US region API, replace https://api.getport.io
with https://api.us.getport.io
.
- Python
- Javascript
- cURL
# Dependencies to install:
# $ python -m pip install requests
import json
import requests
CLIENT_ID = "YOUR_CLIENT_ID"
CLIENT_SECRET = "YOUR_CLIENT_SECRET"
API_URL = "https://api.getport.io/v1"
credentials = {"clientId": CLIENT_ID, "clientSecret": CLIENT_SECRET}
token_response = requests.post(f"{API_URL}/auth/access_token", json=credentials)
access_token = f"Bearer {token_response.json()['accessToken']}"
# You can now use the value in access_token when making further requests
headers = {
'Authorization': access_token
}
query = {
"combinator": "or",
"rules": [
{
"property": "$title",
"operator": "=",
"value": "admin-prod"
},
{
"property": "$title",
"operator": "=",
"value": "admin-test"
}
]
}
search_req = requests.post(f"{API_URL}/entities/search", headers=headers, json=query)
search_entities = search_req.json()['entities']
for entity in search_entities:
print(json.dumps(entity))
// Dependencies to install:
// $ npm install axios --save
const axios = require("axios").default;
const CLIENT_ID = "YOUR_CLIENT_ID";
const CLIENT_SECRET = "YOUR_CLIENT_SECRET";
const API_URL = "https://api.getport.io/v1";
(async () => {
const tokenResp = await axios.post(`${API_URL}/auth/access_token`, {
clientId: CLIENT_ID,
clientSecret: CLIENT_SECRET,
});
const accessToken = tokenResp.data.accessToken;
// You can now use the value in accessToken when making further requests
const config = {
headers: {
Authorization: `Bearer ${accessToken}`,
},
};
const query = {
combinator: "or",
rules: [
{
property: "$title",
operator: "=",
value: "admin-prod",
},
{
property: "$title",
operator: "=",
value: "admin-test",
},
],
};
const response = await axios.post(
`${API_URL}/entities/search`,
query,
config
);
console.log(response.data["entities"]);
})();
#!/bin/bash
# Dependencies to install:
# For apt:
# $ sudo apt-get install jq
# For yum:
# $ sudo yum install jq
access_token=$(curl --location --request POST 'https://api.getport.io/v1/auth/access_token' \
--header 'Content-Type: application/json' \
--data-raw '{
"clientId": "CLIENT_ID",
"clientSecret": "CLIENT_SECRET"
}' | jq '.accessToken' | sed 's/"//g')
# The token will be available in the access_token variable
curl --location --request POST 'https://api.getport.io/v1/entities/search?attach_title_to_relation=true&exclude_calculated_properties=false' \
--header "Authorization: Bearer $access_token" \
--header 'Content-Type: application/json' \
--data-raw '{
"combinator": "or",
"rules": [
{
"property": "$title",
"operator": "=",
"value": "admin-prod"
},
{
"property": "$title",
"operator": "=",
"value": "admin-test"
}
]
}'