{
    "info": {
        "name": "Publicasta Publishing API",
        "description": "Create or update articles through the publishing API.",
        "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
    },
    "variable": [
        {
            "key": "base_url",
            "value": "https://publicasta.com",
            "type": "string"
        },
        {
            "key": "project_slug",
            "value": "demo_project",
            "type": "string"
        },
        {
            "key": "api_key",
            "value": "PASTE_API_KEY_HERE",
            "type": "secret"
        },
        {
            "key": "image_path",
            "value": "/absolute/path/to/illustration.png",
            "type": "string"
        },
        {
            "key": "image_url",
            "value": "PASTE_UPLOADED_IMAGE_URL_HERE",
            "type": "string"
        }
    ],
    "item": [
        {
            "name": "Upload image",
            "request": {
                "method": "POST",
                "header": [
                    {
                        "key": "Accept",
                        "value": "application/json"
                    }
                ],
                "auth": {
                    "type": "bearer",
                    "bearer": [
                        {
                            "key": "token",
                            "value": "{{api_key}}",
                            "type": "string"
                        }
                    ]
                },
                "url": {
                    "raw": "{{base_url}}/api/v1/projects/{{project_slug}}/media",
                    "host": [
                        "{{base_url}}"
                    ],
                    "path": [
                        "api",
                        "v1",
                        "projects",
                        "{{project_slug}}",
                        "media"
                    ]
                },
                "body": {
                    "mode": "formdata",
                    "formdata": [
                        {
                            "key": "image",
                            "type": "file",
                            "src": "{{image_path}}"
                        },
                        {
                            "key": "alt",
                            "value": "Generated illustration",
                            "type": "text"
                        }
                    ]
                },
                "description": "Set api_key, project_slug, and image_path collection variables before sending. Copy markdown or html from the response into the article request."
            },
            "event": [
                {
                    "listen": "test",
                    "script": {
                        "type": "text/javascript",
                        "exec": [
                            "pm.test('Image uploaded', function () {",
                            "  pm.expect(pm.response.code).to.eql(201);",
                            "});",
                            "",
                            "pm.test('Response has markdown snippet', function () {",
                            "  const json = pm.response.json();",
                            "  pm.expect(json).to.have.property('markdown');",
                            "});"
                        ]
                    }
                }
            ]
        },
        {
            "name": "Publish article",
            "request": {
                "method": "POST",
                "header": [
                    {
                        "key": "Accept",
                        "value": "application/json"
                    },
                    {
                        "key": "Content-Type",
                        "value": "application/json"
                    }
                ],
                "auth": {
                    "type": "bearer",
                    "bearer": [
                        {
                            "key": "token",
                            "value": "{{api_key}}",
                            "type": "string"
                        }
                    ]
                },
                "url": {
                    "raw": "{{base_url}}/api/v1/projects/{{project_slug}}/pages",
                    "host": [
                        "{{base_url}}"
                    ],
                    "path": [
                        "api",
                        "v1",
                        "projects",
                        "{{project_slug}}",
                        "pages"
                    ]
                },
                "body": {
                    "mode": "raw",
                    "raw": "{\n    \"slug\": \"agent_post\",\n    \"default_language\": \"en\",\n    \"status\": \"published\",\n    \"scheduled_at\": null,\n    \"translations\": [\n        {\n            \"language\": \"en\",\n            \"title\": \"Agent post\",\n            \"excerpt\": \"Short intro\",\n            \"content_markdown\": \"# Hello\\n\\nBody from **agent**.\\n\\n![Generated illustration]({{image_url}})\"\n        },\n        {\n            \"language\": \"ru\",\n            \"title\": \"Post agenta\",\n            \"excerpt\": \"Korotkoe opisanie\",\n            \"content_markdown\": \"# Privet\\n\\nTekst ot **agenta**.\"\n        }\n    ]\n}",
                    "options": {
                        "raw": {
                            "language": "json"
                        }
                    }
                },
                "description": "Set api_key and project_slug collection variables before sending."
            },
            "event": [
                {
                    "listen": "test",
                    "script": {
                        "type": "text/javascript",
                        "exec": [
                            "pm.test('Request succeeded', function () {",
                            "  pm.expect(pm.response.code).to.be.oneOf([200, 201]);",
                            "});",
                            "",
                            "pm.test('Response has public URL', function () {",
                            "  const json = pm.response.json();",
                            "  pm.expect(json).to.have.property('url');",
                            "});"
                        ]
                    }
                }
            ]
        },
        {
            "name": "Get article status",
            "request": {
                "method": "GET",
                "header": [
                    {
                        "key": "Accept",
                        "value": "application/json"
                    }
                ],
                "auth": {
                    "type": "bearer",
                    "bearer": [
                        {
                            "key": "token",
                            "value": "{{api_key}}",
                            "type": "string"
                        }
                    ]
                },
                "url": {
                    "raw": "{{base_url}}/api/v1/projects/{{project_slug}}/pages/agent_post",
                    "host": [
                        "{{base_url}}"
                    ],
                    "path": [
                        "api",
                        "v1",
                        "projects",
                        "{{project_slug}}",
                        "pages",
                        "agent_post"
                    ]
                },
                "description": "Returns current article status, scheduled_at, published_at, and translation statuses."
            }
        }
    ]
}