Skip to main content

Authentication API Code Examples - Change API Key

Return to Authentication API Guide here.

cURL

curl -X POST  https://driver-vehicle-licensing.api.gov.uk/thirdparty-access/v1/new-api-key \
 -H 'Accept: application/json' 
 -H 'x-api-key: REPLACE WITH YOUR API KEY' 
 -H 'Authorization: REPLACE WITH YOUR JWT ID TOKEN'

PHP

<?php
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://driver-vehicle-licensing.api.gov.uk/thirdparty-access/v1/new-api-key",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_HTTPHEADER => array(
    "x-api-key: REPLACE WITH YOUR API KEY",
    "Authorization: REPLACE WITH YOUR JWT ID TOKEN",
    "Content-Type: application/json"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;
?>

C# (UsingRestSharp)

https://restsharp.dev

var client = new RestClient("https://driver-vehicle-licensing.api.gov.uk/thirdparty-access/v1/new-api-key");
var request = new RestRequest(Method.POST);

request.AddHeader("x-api-key", "REPLACE WITH YOUR API KEY");
request.AddHeader("Authorization", "REPLACE WITH YOUR JWT ID TOKEN");
request.AddHeader("Content-Type", "application/json");

IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

Ruby (Using HTTParty)

https://github.com/jnunemaker/httparty

require 'httparty'
require 'json'

api_path = 'https://driver-vehicle-licensing.api.gov.uk/thirdparty-access/v1/new-api-key'

headers = {"x-api-key" => "REPLACE WITH YOUR API KEY", "Authorization" => "REPLACE WITH YOUR JWT ID TOKEN", "Content-Type" => "application/json"}

response = HTTParty.post(api_path, headers: headers)

puts response

NodeJS (Native)

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

var options = {
  method: 'POST',
  hostname: 'driver-vehicle-licensing.api.gov.uk',
  path: '/thirdparty-access/v1/new-api-key',
  headers: {
    'x-api-key': 'REPLACE WITH YOUR API KEY',
    'Authorization': 'REPLACE WITH YOUR JWT ID TOKEN',
    'Content-Type': 'application/json',
  },
  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 (Using Axios)

https://github.com/axios/axios

var axios = require('axios');

var config = {
  method: 'post',
  url:
    'https://driver-vehicle-licensing.api.gov.uk/thirdparty-access/v1/new-api-key',
  headers: {
    'x-api-key': 'REPLACE WITH YOUR API KEY',
    'Authorization': 'REPLACE WITH YOUR JWT ID TOKEN'
    'Content-Type': 'application/json',
  },
};

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

Python (Using Requests)

https://requests.readthedocs.io/en/master/

import requests

url = "https://driver-vehicle-licensing.api.gov.uk/thirdparty-access/v1/new-api-key"

headers = {
  'x-api-key': 'REPLACE WITH YOUR API KEY',
  'Authorization': 'REPLACE WITH YOUR JWT ID TOKEN',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers)

print(response.text.encode('utf8'))

Java (Using HTTPClient)

https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/HttpClient.html

import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws IOException, InterruptedException {
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create("https://driver-vehicle-licensing.api.gov.uk/thirdparty-access/v1/new-api-key"))
                .header("x-api-key", "REPLACE WITH YOUR API KEY")
                .header("Authorization", "REPLACE WITH YOUR JWT ID TOKEN")
                .header("Content-Type", "application/json")
                .POST()
                .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}