Get and update account info
Short answer
This page has 2 commands: Get account info (GET /v2/account) and Update account info (POST /v2/account). Each call needs a bearer token and counts towards your hourly API limit. Below are the parameters, sample code in 9 languages and a sample answer.
After reading this you will know
- How to get and update account info
- Which parameters each of the 2 commands takes
- Sample code in 9 languages and a sample answer
Every command on this page needs a bearer token and counts towards your hourly limit.
Get account info
Section titled “Get account info”https://api.sirv.com/v2/account
Use this API method to get information about the account, including its CDN URL; account name; additional domains; remote fetching status; date created and more.
Example request
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst res = await fetch('https://api.sirv.com/v2/account', { method: 'GET', headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}` },});console.log(res.status, await res.text());import requests
res = requests.get( 'https://api.sirv.com/v2/account', headers={'authorization': 'Bearer BEARER_TOKEN'},)print(res.status_code, res.text)curl --request GET \ --url 'https://api.sirv.com/v2/account' \ --header 'authorization: Bearer BEARER_TOKEN'import java.net.URI;import java.net.http.HttpClient;import java.net.http.HttpRequest;import java.net.http.HttpResponse;
HttpClient client = HttpClient.newHttpClient();HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.sirv.com/v2/account")) .header("authorization", "Bearer BEARER_TOKEN") .method("GET", HttpRequest.BodyPublishers.noBody()) .build();HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());System.out.println(response.statusCode() + " " + response.body());using System.Net.Http.Headers;
using var client = new HttpClient();var request = new HttpRequestMessage(new HttpMethod("GET"), "https://api.sirv.com/v2/account");request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");var response = await client.SendAsync(request);Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");<?php$ch = curl_init('https://api.sirv.com/v2/account');curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN'], CURLOPT_RETURNTRANSFER => true,]);echo curl_exec($ch);package main
import ( "fmt" "io" "net/http")
func main() { req, _ := http.NewRequest("GET", "https://api.sirv.com/v2/account", nil) req.Header.Set("authorization", "Bearer BEARER_TOKEN") res, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer res.Body.Close() out, _ := io.ReadAll(res.Body) fmt.Println(res.Status, string(out))}require 'net/http'
uri = URI('https://api.sirv.com/v2/account')req = Net::HTTP::Get.new(uri)req['authorization'] = 'Bearer BEARER_TOKEN'res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }puts res.code, res.bodyimport Foundation
var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/account")!)request.httpMethod = "GET"request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")let (data, response) = try await URLSession.shared.data(for: request)print((response as! HTTPURLResponse).statusCode, String(decoding: data, as: UTF8.self))Example response
{ "dateCreated": "2014-10-14T14:15:18.580Z", "alias": "demo", "fileSizeLimit": 50000000, "fetching": { "enabled": false, "type": "http", "http": { "auth": { "enabled": false, "password": "", "username": "" }, "url": "https://somesite.com/folder/" }, "maxFilesize": 2097152 }, "minify": { "enabled": true }, "cdnTempURL": "demo.sirv.com", "cdnURL": "demo.sirv.com", "aliases": { "demo": { "prefix": "/", "cdn": true }, "anotherdemo": { "prefix": "/", "cdn": true }, "demo-cdntest": { "prefix": "/" }, "demo-jwt": { "prefix": "/", "cdn": true } }, "status": { "status": "active", "details": {} }}Update account info
Section titled “Update account info”https://api.sirv.com/v2/account
Use this method to change the account options. You can enable or disable JS/CSS file minification.
You can also enable/disable automatic fetching via HTTP or S3 from a remote location.
Request body (JSON)
| Field | Type | Required | Example | Description |
|---|---|---|---|---|
minify | object | No | Minification of JS and CSS files served from your account. | |
minify.enabled | boolean | Yes | true | Enable or disable automatic minification of JS/CSS files |
fetching | object | No | Fetching: Sirv copies a file from your own server or S3 bucket the first time someone requests it. | |
fetching.enabled | boolean | Yes | false | true to turn fetching on, false to turn it off. |
fetching.type | string | Yes | http | One of: http, s3. |
fetching.http | object | Yes | Where to fetch from when the type is http: the address of your server. | |
fetching.s3 | object | Yes | Where to fetch from when the type is s3: the bucket, its access keys and an optional endpoint and prefix. | |
aliases | object | No | Settings for each account name (alias), with the alias as the key. | |
aliases.<alias> | object | No | Settings for one alias: cdn (true to serve it through the CDN), prefix and defaultProfile. |
Example request
// Your bearer token, from POST /v2/token, in the SIRV_TOKEN environment variableconst res = await fetch('https://api.sirv.com/v2/account', { method: 'POST', headers: { authorization: `Bearer ${process.env.SIRV_TOKEN}`, 'content-type': 'application/json' }, body: JSON.stringify({ "fetching": { "enabled": false } }),});console.log(res.status, await res.text());import requests
res = requests.post( 'https://api.sirv.com/v2/account', headers={'authorization': 'Bearer BEARER_TOKEN', 'content-type': 'application/json'}, json={ "fetching": { "enabled": False } },)print(res.status_code, res.text)curl --request POST \ --url 'https://api.sirv.com/v2/account' \ --header 'authorization: Bearer BEARER_TOKEN' \ --header 'content-type: application/json' \ --data '{"fetching":{"enabled":false}}'import java.net.URI;import java.net.http.HttpClient;import java.net.http.HttpRequest;import java.net.http.HttpResponse;
HttpClient client = HttpClient.newHttpClient();HttpRequest request = HttpRequest.newBuilder(URI.create("https://api.sirv.com/v2/account")) .header("authorization", "Bearer BEARER_TOKEN") .header("content-type", "application/json") .method("POST", HttpRequest.BodyPublishers.ofString(""" { "fetching": { "enabled": false } } """)) .build();HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());System.out.println(response.statusCode() + " " + response.body());using System.Net.Http.Headers;
using var client = new HttpClient();var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.sirv.com/v2/account");request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "BEARER_TOKEN");request.Content = new StringContent("""{ "fetching": { "enabled": false }}""", System.Text.Encoding.UTF8, "application/json");var response = await client.SendAsync(request);Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");<?php$ch = curl_init('https://api.sirv.com/v2/account');curl_setopt_array($ch, [ CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => ['authorization: Bearer BEARER_TOKEN', 'content-type: application/json'], CURLOPT_POSTFIELDS => json_encode([ 'fetching' => [ 'enabled' => false ] ]), CURLOPT_RETURNTRANSFER => true,]);echo curl_exec($ch);package main
import ( "fmt" "io" "net/http" "strings")
func main() { body := strings.NewReader(`{ "fetching": { "enabled": false } }`) req, _ := http.NewRequest("POST", "https://api.sirv.com/v2/account", body) req.Header.Set("authorization", "Bearer BEARER_TOKEN") req.Header.Set("content-type", "application/json") res, err := http.DefaultClient.Do(req) if err != nil { panic(err) } defer res.Body.Close() out, _ := io.ReadAll(res.Body) fmt.Println(res.Status, string(out))}require 'net/http'
uri = URI('https://api.sirv.com/v2/account')req = Net::HTTP::Post.new(uri)req['authorization'] = 'Bearer BEARER_TOKEN'req['content-type'] = 'application/json'req.body = <<~'JSON' { "fetching": { "enabled": false } }JSONres = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(req) }puts res.code, res.bodyimport Foundation
var request = URLRequest(url: URL(string: "https://api.sirv.com/v2/account")!)request.httpMethod = "POST"request.setValue("Bearer BEARER_TOKEN", forHTTPHeaderField: "authorization")request.setValue("application/json", forHTTPHeaderField: "content-type")request.httpBody = #"""{ "fetching": { "enabled": false }}"""#.data(using: .utf8)let (data, response) = try await URLSession.shared.data(for: request)print((response as! HTTPURLResponse).statusCode, String(decoding: data, as: UTF8.self))Response
HTTP 200 with an empty body when the command succeeds.