Yay.com loading

Loading

Call us on (917) 9001 YAY

Login to Yay.com

VoIP API Code Examples - C# and PHP

Back to latest posts
VoIP API Code Examples - C# and PHP

The two code snippets below show how to send a basic GET request to the Yay.com API using C# and PHP, the C# snippet has been tested using .NET Core and will work across all supported .NET platforms

C# Example

var dict = new Dictionary<string, string> {
    {"X-Auth-Reseller", "yay"},
    {"X-Auth-User", "admin"},
    {"X-Auth-Password", "password"}
};

var client = new HttpClient {
    BaseAddress = new Uri("https://api.yay.com/authenticated"),
    DefaultRequestHeaders = {
        UserAgent = {
            new ProductInfoHeaderValue("ApiExample", "1.0")
        }
    }
};

foreach (var key in dict.Keys) {
    client.DefaultRequestHeaders.Add(key, dict[key]);
}

var response = client.GetAsync("").Result;
if (!response.IsSuccessStatusCode) return;

var jsonResponse = response.Content.ReadAsStringAsync().Result;

PHP Example

The example below uses the Httpful library for ease of integration

// We use the httpful library for ease
include('httpful.phar');

try {

    $response = \Httpful\Request::get('https://api.yay.com/authenticated')
        ->addHeaders(
            array(
                'X-Auth-Reseller' => 'yay',
                'X-Auth-User' => 'admin',
                'X-Auth-Password' => 'password'
            )
        )
        ->send();

    printf($response->body);

} catch (\Httpful\Exception\ConnectionErrorException $e) {
    printf($e);
}
Geoff

Posted by Geoff

Senior Analyst Developer at Yay.com

Back to latest posts

Blog Archive