Repository: penpot/penpot

Issue #3670: bug: cropped API response JSON body for huge Penpot files (>150000 lines)
Created: 2023-09-26T16:04:28Z
Steps To Reproduce

Generate an access token
Import the "Tutorial for beginners" .penpot file from https://penpot.app/libraries-templates
Make a HTTP POST call to the Penpot API for the get-file RPC specifying:

an Authorization: Token YOUR_ACCESS_TOKEN header
an Accept: application/json header
a Content-Type: application/json header
the correct id param in the body object



Expected behavior
Receive a response with 200 HTTP code and a properly formatted JSON body.
Actual behavior
The response has a 200 HTTP code and the body is a cropped, invalid JSON (mind the white-space):
					"187ee84f-c56d-8067-8002-5f0236eb7c6c": {
						"y": 1775.043,
						"rotation": 0,
						"name": "icon-keyboard (1)-1",
						"width": 18,
						"type": "group",
						"svgAttrs": {
							"width": "71.071",
							"height": "54.071",
							"style": {
								

Screenshots or video
No response
Desktop (please complete the following information)
No response
Smartphone (please complete the following information)
No response
Environment (please complete the following information)

Host: https://design.penpot.app
Penpot version: 1.19

Frontend Stack Trace
No response
Backend Stack Trace
No response
Additional context
Example call using curl and jq:
ACCESS_TOKEN="your-access-token-here"
FILE_ID="your-file-id-here"

curl --request POST \
  --url https://design.penpot.app/api/rpc/command/get-file \
  --header 'Accept: application/json' \
  --header "Authorization: Token $ACCESS_TOKEN" \
  --header 'Content-Type: application/json' \
  --data "{
        \"id\": \"$FILE_ID\"
}" | jq '.'


jq: parse error: Unfinished JSON term at EOF at line 155013, column 25

Duplicate issue #4826: bug: Truncated JSON response from Penpot API
Created: 2024-06-28T18:27:34Z
Steps To Reproduce
Run this python script
It's just a very simple project, nothing more on the account so i can provide you the token

import requests
import json

# Configuration
API_BASE_URL = "https://design.penpot.app/api/rpc/command"
TOKEN = "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.3xLdRfAi-0l1m3Re1IEB5WmtAsr8iTMBO6emTqjspUnxCJQsJv0s-A.WRPfJl2DDCVJbyy_.0fZxYXym2SeCj-dNc7XY1PLdmXzmAzDzPEBWyzZitd7w_BInkbV660TB7SyW7rzls-5m2hzdcbU_KFLnB_2-05gjJRFsw0Q_UummFBcuiI5cLuPypAFE69vwp2c5GduJWCA7ACff0vs.mLANtZfbiWQyi_HbedtDcg"

# ID du projet et du fichier (vous devez les remplacer par vos propres identifiants)
PROJECT_ID = "502c5b43-61ea-81d3-8004-9325c7e4979a"
FILE_ID = "502c5b43-61ea-81d3-8004-93266d27459e"
PAGE_ID = "912a6484-1204-8046-8004-4fefdf35c19f"
import requests
import json

headers = {
    "Authorization": f"Token {TOKEN}",
    "Content-Type": "application/json",
    "Accept": "application/json"
}

def get_page():
    url = f"{API_BASE_URL}/get-file"
    data = {
        "id": FILE_ID,
        "projectId": PROJECT_ID
    }
    
    print(f"Envoi de la requête à : {url}")
    print(f"FileId : {FILE_ID}")
    
    try:
        response = requests.post(url, headers=headers, json=data)
        print(f"\nCode de statut de la réponse : {response.status_code}")
        
        if response.status_code == 200:
            print("\nContenu de la réponse :")
            print(response.text)
        else:
            print(f"Erreur : {response.status_code}")
            print(f"Contenu de la réponse : {response.text}")
    except requests.exceptions.RequestException as e:
        print(f"Une erreur s'est produite lors de la requête : {e}")

# Exécution de la fonction
get_page()

Response is like :

{
  "features" : [ "layout/grid", "styles/v2", "components/v2", "fdata/shape-data-type" ],
  "permissions" : {
    "type" : "membership",
    "isOwner" : true,
    "isAdmin" : true,
    "canEdit" : true,
    "canRead" : true,
    "isLogged" : true
  },
  "hasMediaTrimmed" : false,
  "commentThreadSeqn" : 0,
  "name" : "prototype-examples",
  "revn" : 2014,
  "modifiedAt" : "2024-06-28T17:10:51.115096Z",
  "ignoreSyncUntil" : "2024-06-28T15:49:17.977335Z",
  "id" : "502c5b43-61ea-81d3-8004-93266d27459e",
  "isShared" : true,
  "version" : 48,
  "projectId" : "502c5b43-61ea-81d3-8004-9325c7e4979a",
  "createdAt" : "2024-06-28T15:49:12.977335Z",
  "data" : {
    "pages" : [ "3ebe2f66-ecd2-8082-8004-51397fd3242c", "68a1c0e6-b27c-807b-8004-4fe4de733449", "912a6484-1204-8046-8004-4fefdf35c19f", "912a6484-1204-8046-8004-4ff16a81cc31", "8ac84731-66ee-8057-8004-512070375fe5" ],
    "pagesIndex" : {
      "68a1c0e6-b27c-807b-8004-4fe4de733449" : {
        "options" : {
          "flows" : [ {
            "id" : "d63d11f1-ab91-80e1-8004-4fe506d13eba",
            "name" : "Button states",
            "startingFrame" : "d63d11f1-ab91-80e1-8004-4fe4fe5ce61d"
          } ],
          "background" : "#ebe7e4"
        },
        "objects" : {
          "00000000-0000-0000-0000-000000000000" : {
          

the json is truncated.
When i tried the penpot-export, i got this
FetchError: invalid json response body at https://design.penpot.app/api/rpc/command/get-file reason: Expected property name or '}' in JSON at position 1299
at C:\Users\K_ale\OneDrive\Source\NodeJS\PenPot\node_modules\node-fetch\lib\index.js:273:32
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
type: 'invalid-json'
}
Expected behavior
The API should return a complete and valid JSON response, allowing penpot-export to function correctly.
Actual behavior
The API returns a truncated JSON response, causing penpot-export to fail with a FetchError.
Screenshots or video
No response
Desktop (please complete the following information)
No response
Smartphone (please complete the following information)
No response
Environment (please complete the following information)
No response
Frontend Stack Trace
No response
Backend Stack Trace
FetchError: invalid json response body at https://design.penpot.app/api/rpc/command/get-file reason: Expected property name or '}' in JSON at position 1299
    at C:\Users\K_ale\OneDrive\Source\NodeJS\PenPot\node_modules\node-fetch\lib\index.js:273:32
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  type: 'invalid-json'
}
Additional context
No response

Closing comment (2024-07-08T11:07:37Z): Hi @Kalexand22,
I believe this issue is a duplicate of #3670, and it should be fixed by #4760!