EQTY LabDocs

Convert policy Excel to JSON

Parses an uploaded Excel workbook and returns structured JSON policy data

posthttps://localhost:10001/api/v1/policies/convert
bash
curl --request POST \
  --url 'https://localhost:10001/api/v1/policies/convert' \
  --header 'Authorization: Bearer <token>' \
  --form 'file=@<file>'
javascript
const form = new FormData();
form.append("file", file); // a File or Blob

const response = await fetch("https://localhost:10001/api/v1/policies/convert", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <token>"
  },
  body: form
});

const data = await response.json();
typescript
declare const file: Blob;

interface ConvertedPolicyResponse {
  controls?: Record<string, unknown>[];
  description?: string;
  iconUrl?: string;
  name?: string;
  type?: string;
  version?: string;
}

const form = new FormData();
form.append("file", file); // a File or Blob

const response = await fetch("https://localhost:10001/api/v1/policies/convert", {
  method: "POST",
  headers: {
    "Authorization": "Bearer <token>"
  },
  body: form
});
if (!response.ok) throw new Error(`${response.status} ${response.statusText}`);

const data: ConvertedPolicyResponse = await response.json();
python
import requests

response = requests.post(
    "https://localhost:10001/api/v1/policies/convert",
    headers={
        "Authorization": "Bearer <token>",
    },
    files={"file": open("<file>", "rb")},
)
response.raise_for_status()
print(response.json())
go
package main

import (
	"bytes"
	"fmt"
	"io"
	"mime/multipart"
	"net/http"
	"os"
	"path/filepath"
)

func main() {
	var body bytes.Buffer
	form := multipart.NewWriter(&body)
	file, err := os.Open("<file>")
	if err != nil {
		panic(err)
	}
	defer file.Close()
	part, err := form.CreateFormFile("file", filepath.Base(file.Name()))
	if err != nil {
		panic(err)
	}
	if _, err := io.Copy(part, file); err != nil {
		panic(err)
	}
	if err := form.Close(); err != nil {
		panic(err)
	}

	req, err := http.NewRequest(http.MethodPost, "https://localhost:10001/api/v1/policies/convert", &body)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Authorization", "Bearer <token>")
	req.Header.Set("Content-Type", form.FormDataContentType())

	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()

	data, err := io.ReadAll(res.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(res.Status, string(data))
}
java
import java.io.ByteArrayOutputStream;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

public class Example {
    public static void main(String[] args) throws Exception {
        String boundary = "GuardianBoundary" + System.nanoTime();
        ByteArrayOutputStream form = new ByteArrayOutputStream();
        Path file = Path.of("<file>");
        form.writeBytes(("--" + boundary + "\r\nContent-Disposition: form-data; name=\"file\"; filename=\"" + file.getFileName() + "\"\r\n\r\n").getBytes(StandardCharsets.UTF_8));
        form.writeBytes(Files.readAllBytes(file));
        form.writeBytes("\r\n".getBytes(StandardCharsets.UTF_8));
        form.writeBytes(("--" + boundary + "--\r\n").getBytes(StandardCharsets.UTF_8));

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://localhost:10001/api/v1/policies/convert"))
            .header("Authorization", "Bearer <token>")
            .header("Content-Type", "multipart/form-data; boundary=" + boundary)
            .method("POST", HttpRequest.BodyPublishers.ofByteArray(form.toByteArray()))
            .build();

        HttpResponse<String> response = HttpClient.newHttpClient()
            .send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode() + " " + response.body());
    }
}
csharp
using System.Net.Http.Headers;

using var client = new HttpClient();
using var request = new HttpRequestMessage(HttpMethod.Post, "https://localhost:10001/api/v1/policies/convert");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "<token>");
using var form = new MultipartFormDataContent();
form.Add(new StreamContent(File.OpenRead("<file>")), "file", Path.GetFileName("<file>"));
request.Content = form;

using var response = await client.SendAsync(request);
Console.WriteLine($"{(int)response.StatusCode} {await response.Content.ReadAsStringAsync()}");
php
<?php

$ch = curl_init('https://localhost:10001/api/v1/policies/convert');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => [
        'Authorization: Bearer <token>',
    ],
    CURLOPT_POSTFIELDS => [
        'file' => new CURLFile('<file>'),
    ],
    CURLOPT_RETURNTRANSFER => true,
]);

$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
echo $status . " " . $response . PHP_EOL;
ruby
require "net/http"

uri = URI("https://localhost:10001/api/v1/policies/convert")
request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer <token>"
request.set_form([
  ["file", File.open("<file>")],
], "multipart/form-data")

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
  http.request(request)
end
puts "#{response.code} #{response.body}"
rust
// Cargo.toml dependencies: reqwest (features "multipart"), tokio (features "full")

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let form = reqwest::multipart::Form::new()
        .part("file", reqwest::multipart::Part::bytes(std::fs::read("<file>")?).file_name("<file>"));

    let response = reqwest::Client::new()
        .post("https://localhost:10001/api/v1/policies/convert")
        .header("Authorization", "Bearer <token>")
        .multipart(form)
        .send()
        .await?;

    println!("{} {}", response.status(), response.text().await?);
    Ok(())
}

Authorizations

  • BearerAuth · API key in header "Authorization" — Type "Bearer" followed by a space and JWT token.

Parameters

Form parameters

NameTypeDescription
file
required
file

Excel file (.xlsx or .xls)

Responses

200Converted policy data

application/json
  • controlshandlers.ConvertedPolicyControl[]
    Show properties

    Array of handlers.ConvertedPolicyControl

    • citationscore.Citation[]

      Empty unless the workbook has a Citations sheet

      Show properties

      Array of core.Citation

      • titlestring

        Up to 255 characters; trimmed

      • urlstring

        An absolute http or https URL with a hostname, up to 2048 bytes; trimmed

    • controlCodestring
    • descriptionstring
    • titlestring
  • descriptionstring
  • iconUrlstring
  • namestring
  • typestring
  • versionstring
Examplejson
{
  "controls": [
    {
      "citations": [
        {
          "title": "string",
          "url": "string"
        }
      ],
      "controlCode": "string",
      "description": "string",
      "title": "string"
    }
  ],
  "description": "string",
  "iconUrl": "string",
  "name": "string",
  "type": "string",
  "version": "string"
}

400Bad request - Invalid or malformed Excel file

application/json
  • codestring
  • detailsstring
  • messagestring
Examplejson
{
  "code": "INVALID_REQUEST",
  "details": "unexpected end of JSON input",
  "message": "Invalid request body"
}

401Unauthorized - Authentication required

application/json
  • codestring
  • detailsstring
  • messagestring
Examplejson
{
  "code": "INVALID_REQUEST",
  "details": "unexpected end of JSON input",
  "message": "Invalid request body"
}

403Forbidden - Insufficient permissions

application/json
  • codestring
  • detailsstring
  • messagestring
Examplejson
{
  "code": "INVALID_REQUEST",
  "details": "unexpected end of JSON input",
  "message": "Invalid request body"
}

500Internal server error

application/json
  • codestring
  • detailsstring
  • messagestring
Examplejson
{
  "code": "INVALID_REQUEST",
  "details": "unexpected end of JSON input",
  "message": "Invalid request body"
}