# REST API

# Introduction

The PHP-Prefixer API allows you to create and interact with projects and builds on PHP-Prefixer through a simple REST API.

It’s quick and easy to get a project up and running. The PHP-Prefixer API supports the same use cases presented in our guides (opens new window). Essentially, the prefixing workflow has the following steps:

  1. Sign up (opens new window),
  2. Create your PHP-Prefixer project,
  3. Create a ZIP file to be prefixed, and upload it,
  4. Download and review the prefixed codebase, and
  5. Review the prefixed PHP project

# Authentication

In order to use the API, you should authenticate your request by including your API key as a bearer token value:

Authorization: Bearer API_KEY_HERE

# Headers

Make sure you have the following content-type headers are set on every request:

Accept: application/json
Content-Type: application/json

# URI

PHP-Prefixer API is hosted on the following base URI:

https://php-prefixer.com/api/v1

# Errors

PHP-Prefixer uses conventional HTTP response codes to indicate the success or failure of an API request. The table below contains a summary of the typical response codes:

Code Description
200 Everything is ok.
400 Valid data was given but the request has failed.
401 No valid API Key was given.
404 The request resource could not be found.
422 The payload has missing required parameters or invalid data was given.
429 Too many attempts.
500 Request failed due to an internal error in PHP-Prefixer.
503 PHP-Prefixer is offline for maintenance.

# User

# Get User

# HTTP Request

GET /api/v1/user

# Response

{
  "user": {
    "id": 5299,
    "name": "Aníbal Sánchez",
    "company": "Extly CB"
  }
}

# Project

# Create Project

# HTTP Request

POST /api/v1/projects
{
  "name": "My Project",
  "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
  "source_type": "project_file"
}

# Parameters

Key Description
name * The project name.
description An optional description of the project.
source_type * The type of project to create. Valid values are: project_file.

# Response

HTTP/1.1 201 Created
{
  "project": {
    "id": 5399,
    "name": "My Project",
    "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
    "source_type": "project_file",
    "updated_at": "2021-04-19T17:56:34.000000Z",
    "created_at": "2021-04-19T17:56:34.000000Z"
  }
}

# List Projects

# HTTP Request

GET /api/v1/projects

# Response

HTTP/1.1 200 OK
{
  "projects": [
    {
      "id": 5394,
      "name": "XT Laravel Starter for Joomla",
      "source_type": "project_file",
      "created_at": "2020-12-07T14:27:49.000000Z",
      "updated_at": "2020-12-07T14:27:49.000000Z"
    },
    {
      "id": 5398,
      "name": "My Project",
      "description": "Quisque sit amet tincidunt libero.",
      "source_type": "project_file",
      "created_at": "2021-04-15T15:45:19.000000Z",
      "updated_at": "2021-04-15T15:46:05.000000Z"
    }
  ]
}

# Get Project

# HTTP Request

GET /api/v1/projects/{projectId}

# Response

HTTP/1.1 200 OK
{
  "project": {
    "id": 5399,
    "name": "My Project",
    "description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
    "source_type": "project_file",
    "updated_at": "2021-04-19T17:56:34.000000Z",
    "created_at": "2021-04-19T17:56:34.000000Z"
  }
}

# Update Project

# HTTP Request

PUT /api/v1/projects/{projectId}
{
  "description": "Quisque sit amet tincidunt libero."
}

# Response

HTTP/1.1 200 OK
{
  "project": {
    "id": 5398,
    "name": "My Project",
    "description": "Quisque sit amet tincidunt libero.",
    "source_type": "project_file",
    "created_at": "2021-04-15T15:45:19.000000Z",
    "updated_at": "2021-04-15T15:46:05.000000Z"
  }
}

# Delete Project

# HTTP Request

DELETE /api/v1/projects/{projectId}

# Response

HTTP/1.1 204 No Content

# Build

# Create Build

# HTTP Request

POST /api/v1/projects/{projectId}/builds
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Accept: application/json, text/plain, */*
Authorization: Bearer {{PERSONAL_ACCESS_TOKEN}}

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="uploaded_source_file"; filename="MyProjectSource.zip"
Content-Type: application/x-zip

< /home/user/.../MockSourceProject.zip
------WebKitFormBoundary7MA4YWxkTrZu0gW--

# Parameters

Key Description
uploaded_source_file * The field must have the project source code package, the ZIP file that contains the complete source code of the project. It must include the ´composer.json´ file in the root folder.
github_access_token An optional GitHub token to access ´composer.json´ dependencies that are managed in private repositories.

# Response

HTTP/1.1 201 Created
{
  "build": {
    "id": 1448,
    "state": "initial-state",
    "project_id": 5398,
    "updated_at": "2021-04-20T08:02:58.000000Z",
    "created_at": "2021-04-20T08:02:58.000000Z"
  }
}

# List Builds

# HTTP Request

GET /api/v1/projects/{projectId}/builds

# Response

HTTP/1.1 200 OK
{
  "builds": [
    {
      "id": 1448,
      "state": "prefixing",
      "build_uuid": "ea59d7d5-b648-4b8f-8f17-1438f6a776ea",
      "package_name": "project\/mock",
      "project_id": 5398,
      "created_at": "2021-04-20T08:02:58.000000Z",
      "updated_at": "2021-04-20T08:03:05.000000Z"
    },
    {
      "id": 1446,
      "state": "success",
      "build_uuid": "810b6220-d64f-4879-ab80-e0a3eaf20316",
      "package_name": "project\/mock",
      "project_id": 5398,
      "created_at": "2021-04-19T14:02:20.000000Z",
      "updated_at": "2021-04-19T14:03:51.000000Z"
    }
  ]
}

# Get Build

# HTTP Request

GET /api/v1/projects/{projectId}/builds/{buildId}

# Response

HTTP/1.1 200 OK
{
  "build": {
    "id": 1448,
    "state": "success",
    "build_uuid": "ea59d7d5-b648-4b8f-8f17-1438f6a776ea",
    "package_name": "project\/mock",
    "project_id": 5398,
    "created_at": "2021-04-20T08:02:58.000000Z",
    "updated_at": "2021-04-20T08:04:16.000000Z"
  }
}

# Download Build

# HTTP Request

GET /api/v1/projects/{projectId}/builds/{buildId}/download

# Response

HTTP/1.1 200 OK
Content-Disposition: attachment; filename=ea59d7d5-b648-4b8f-8f17-1438f6a776ea.processed.zip
Content-Type: application/x-zip
...

# Download Build Log

# HTTP Request

GET /api/v1/projects/{projectId}/builds/{buildId}/downloadLog

# Response

HTTP/1.1 200 OK
Content-Type: application/x-zip
Content-Disposition: attachment; filename=ea59d7d5-b648-4b8f-8f17-1438f6a776ea.log.zip
...

# Cancel Build

# HTTP Request

POST /api/v1/projects/{projectId}/builds/{buildId}/cancel

# Response

HTTP/1.1 202 Accepted
{
  "build": {
    "id": 1449,
    "state": "user-cancelled",
    "build_uuid": "3660939c-73e2-450f-9d5c-e52f69c06992",
    "package_name": "project\/mock",
    "project_id": 5398,
    "created_at": "2021-04-20T08:13:52.000000Z",
    "updated_at": "2021-04-20T08:14:05.000000Z"
  }
}

# Delete Build

# HTTP Request

DELETE /api/v1/projects/{projectId}/builds/{buildId}

# Response

HTTP/1.1 204 No Content
Last Updated: 12/19/2023, 9:07:55 AM