Smart Carrier | Code Examples

Smart Carrier | Code Examples





C# (HttpClient)

Below, you will find a sample C# (HttpClient) request for STI-AS.  You will need to replace the following values with yours (values are in curly braces):


Code Sample:

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "https://api.smartcarrier.io/v2/ai-numbers?ToNumber={ToNumber}&FromNumber={FromNumber}");
request.Headers.Add(
"x-api-key", {API Key});
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(
await response.Content.ReadAsStringAsync());


C# RestSharp

Below, you will find a sample C# (RestSharp) request for STI-AS.  You will need to replace the following values with yours (values are in curly braces):


Code Sample:

var options = new RestClientOptions("https://api.smartcarrier.io")
{
  MaxTimeout =
-1,
};
var client = new RestClient(options);
var request = new RestRequest("/v2/ai-numbers?ToNumber={ToNumber}&FromNumber={FromNumber}", Method.Get);
request.AddHeader(
"x-api-key", "{API Key}");
RestResponse response =
await client.ExecuteAsync(request);
Console.WriteLine(response.Content);


cURL

Below, you will find a sample cURL request for STI-AS.  You will need to replace the following values with yours (values are in curly braces):

Code Sample:


Javascript -Fetch

Below, you will find a sample Javascript (Fetch) request for STI-AS.  You will need to replace the following values with yours (values are in curly braces):

Code Sample:

var myHeaders = new Headers();
myHeaders.append(
"x-api-key", "{API Key}");

var requestOptions = {
 
method: 'GET',
 
headers: myHeaders,
 
redirect: 'follow'
};

fetch(
"https://api.smartcarrier.io/v2/ai-numbers?ToNumber={ToNumber}&FromNumber={FromNumber}", requestOptions)
  .then(response => response.text())
  .then(result =>
console.log(result))
  .catch(error =>
console.log('error', error));


C# (HttpClient)

Below, you will find a sample C# (HttpClient) request for STI-AS.  You will need to replace the following values with yours (values are in curly braces):


Code Sample:

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "https://api.smartcarrier.io/v2/ai-numbers?ToNumber={ToNumber}&FromNumber={FromNumber}");
request.Headers.Add(
"x-api-key", {API Key});
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(
await response.Content.ReadAsStringAsync());


C# RestSharp

Below, you will find a sample C# (RestSharp) request for STI-AS.  You will need to replace the following values with yours (values are in curly braces):


Code Sample:

var options = new RestClientOptions("https://api.smartcarrier.io")
{
  MaxTimeout =
-1,
};
var client = new RestClient(options);
var request = new RestRequest("/v2/ai-numbers?ToNumber={ToNumber}&FromNumber={FromNumber}", Method.Get);
request.AddHeader(
"x-api-key", "{API Key}");
RestResponse response =
await client.ExecuteAsync(request);
Console.WriteLine(response.Content);


cURL

Below, you will find a sample cURL request for STI-AS.  You will need to replace the following values with yours (values are in curly braces):


Code Sample:

curl --location 'https://api.smartcarrier.io/v2/ai-numbers?ToNumber={ToNumber}&FromNumber={FromNumber}' \
--header 'x-api-key: {API Key}'


Javascript -Fetch

Below, you will find a sample Javascript (Fetch) request for STI-AS.  You will need to replace the following values with yours (values are in curly braces):


Code Sample:

var myHeaders = new Headers();
myHeaders.append(
"x-api-key", "{API Key}");

var requestOptions = {
 
method: 'GET',
 
headers: myHeaders,
 
redirect: 'follow'
};

fetch(
"https://api.smartcarrier.io/v2/ai-numbers?ToNumber={ToNumber}&FromNumber={FromNumber}", requestOptions)
  .then(response => response.text())
  .then(result =>
console.log(result))
  .catch(error =>
console.log('error', error));


JQuery

Below, you will find a sample Javascript (jQuery) request for STI-AS.  You will need to replace the following values with yours (values are in curly braces):


Code Sample:

var settings = {
 
"url": "https://api.smartcarrier.io/v2/ai-numbers?ToNumber={ToNumber}&FromNumber={FromNumber}",
 
"method": "GET",
 
"timeout": 0,
 
"headers": {
   
"x-api-key": "{API Key}"
  },
};

$.ajax(settings).done(
function (response) {
 
console.log(response);
});


XHR

Below, you will find a sample Javascript (XHR) request for STI-AS.  You will need to replace the following values with yours (values are in curly braces):


Code Sample:

// WARNING: For GET requests, body is set to null by browsers.

var xhr = new XMLHttpRequest();
xhr.withCredentials =
true;

xhr.addEventListener(
"readystatechange", function() {
 
if(this.readyState === 4) {
   
console.log(this.responseText);
  }
});

xhr.open(
"GET", "https://api.smartcarrier.io/v2/ai-numbers?ToNumber={ToNumber}&FromNumber={FromNumber}");
xhr.setRequestHeader(
"x-api-key", "{API Key}");

xhr.send();


NodeJS Axios

Below, you will find a sample NodeJS (Axios) request for STI-AS.  You will need to replace the following values with yours (values are in curly braces):


Code Sample:

const axios = require('axios');

let config = {
 
method: 'get',
 
maxBodyLength: Infinity,
 
url: 'https://api.smartcarrier.io/v2/ai-numbers?ToNumber={ToNumber}&FromNumber={FromNumber}',
 
headers: {
   
'x-api-key': '{API Key}'
  }
};

axios.request(config)
.then((response) => {
 
console.log(JSON.stringify(response.data));
})
.catch((error) => {
 
console.log(error);
});


NodeJS- Native

Below, you will find a sample NodeJS (Native) request for STI-AS.  You will need to replace the following values with yours (values are in curly braces):


Code Sample:

var https = require('follow-redirects').https;
var fs = require('fs');

var options = {
 
'method': 'GET',
 
'hostname': 'api.smartcarrier.io',
 
'path': '/v2/ai-numbers?ToNumber={ToNumber}&FromNumber={FromNumber}',
 
'headers': {
   
'x-api-key': '{API Key}'
  },
 
'maxRedirects': 20
};

var req = https.request(options, function (res) {
 
var chunks = [];

  res.on(
"data", function (chunk) {
    chunks.push(chunk);
  });

  res.on(
"end", function (chunk) {
   
var body = Buffer.concat(chunks);
   
console.log(body.toString());
  });

  res.on(
"error", function (error) {
   
console.error(error);
  });
});

req.end();



NodeJS-Request

Below, you will find a sample NodeJS (Request) request for STI-AS.  You will need to replace the following values with yours (values are in curly braces):


Code Sample:

var request = require('request');
var options = {
 
'method': 'GET',
 
'url': 'https://api.smartcarrier.io/v2/ai-numbers?ToNumber={ToNumber}&FromNumber={FromNumber}',
 
'headers': {
   
'x-api-key': '{API Key}'
  }
};
request(options,
function (error, response) {
 
if (error) throw new Error(error);
 
console.log(response.body);
});


NodeJS- Unirest

Below, you will find a sample NodeJS (Unirest) request for STI-AS.  You will need to replace the following values with yours (values are in curly braces):


Code Sample:

var unirest = require('unirest');
var req = unirest('GET', 'https://api.smartcarrier.io/v2/ai-numbers?ToNumber={ToNumber}&FromNumber={FromNumber}')
  .headers({
   
'x-api-key': '{API Key}'
  })
  .end(
function (res) {
   
if (res.error) throw new Error(res.error);
   
console.log(res.raw_body);
  });


PHP -cURL

Below, you will find a sample PHP (cURL) request for STI-AS.  You will need to replace the following values with yours (values are in curly braces):


Code Sample:

<?php

$curl = curl_init();

curl_setopt_array($curl,
array(
  CURLOPT_URL =>
'https://api.smartcarrier.io/v2/ai-numbers?ToNumber={ToNumber}&FromNumber={FromNumber}',
  CURLOPT_RETURNTRANSFER =>
true,
  CURLOPT_ENCODING =>
'',
  CURLOPT_MAXREDIRS =>
10,
  CURLOPT_TIMEOUT =>
0,
  CURLOPT_FOLLOWLOCATION =>
true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST =>
'GET',
  CURLOPT_HTTPHEADER =>
array(
   
'x-api-key: {API Key}'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

PHP - HTTP Request 2

Below, you will find a sample PHP (HTTP Request 2) request for STI-AS.  You will need to replace the following values with yours (values are in curly braces):


Code Sample:

<?php
require_once 'HTTP/Request2.php';
$request =
new HTTP_Request2();
$request->setUrl(
'https://api.smartcarrier.io/v2/ai-numbers?ToNumber={ToNumber}&FromNumber={FromNumber}');
$request->setMethod(HTTP_Request2::METHOD_GET);
$request->setConfig(
array(
 
'follow_redirects' => TRUE
));
$request->setHeader(
array(
 
'x-api-key' => '{API Key}'
));
try {
  $response = $request->send();
 
if ($response->getStatus() == 200) {
   
echo $response->getBody();
  }
 
else {
   
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
    $response->getReasonPhrase();
  }
}
catch(HTTP_Request2_Exception $e) {
 
echo 'Error: ' . $e->getMessage();
}


Python - http.client

Below, you will find a sample Python (http.client) request for STI-AS.  You will need to replace the following values with yours (values are in curly braces):


Code Sample:

import http.client

conn = http.client.HTTPSConnection(
"api.smartcarrier.io")
payload =
''
headers = {
 
'x-api-key': '{API Key}'
}
conn.request(
"GET", "/v2/ai-numbers?ToNumber={ToNumber}&FromNumber={FromNumber}", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode(
"utf-8"))



REQUESTS

Below, you will find a sample Python (Requests) request for STI-AS.  You will need to replace the following values with yours (values are in curly braces):


Code Sample:

import requests

url =
"https://api.smartcarrier.io/v2/ai-numbers?ToNumber={ToNumber}&FromNumber={FromNumber}"

payload = {}
headers = {
 
'x-api-key': '{API Key}'
}

response = requests.request(
"GET", url, headers=headers, data=payload)

print(response.text)



Ruby - Net::HTTP
Below, you will find a sample Ruby (Net::HTTP) request for STI-AS.  You will need to replace the following values with yours (values are in curly braces):


Code Sample:

require "uri"
require "net/http"

url = URI(
"https://api.smartcarrier.io/v2/ai-numbers?ToNumber={ToNumber}&FromNumber={FromNumber}")

https = Net::HTTP.new(url.host, url.port)
https.use_ssl =
true

request = Net::HTTP::Get.new(url)
request[
"x-api-key"] = "{API Key}"

response = https.request(request)
puts response.read_body