Skip to content
中文

Create and follow a ticket

Create a bug ticket with the API, comment on it, find it with a filter, close it, and read back its state and timeline. Each step lists the expected result.

Prerequisites: an organization API key (see API keys) in the PRAXIS_API_KEY environment variable, plus curl and jq. Set PRAXIS_API_BASE to target another environment; the default is https://api.deepraxis.com. Titles below carry a docs-example prefix and a timestamp.

1. Create the ticket

终端窗口
export BASE="${PRAXIS_API_BASE:-https://api.deepraxis.com}"
export TAG=$(date +%s)
TICKET_JSON=$(curl --fail-with-body -sS -X POST "$BASE/ticket/v1/tickets" \
-H "Authorization: Bearer $PRAXIS_API_KEY" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg t "docs-example-checkout-bug-$TAG" '{title: $t, body: "Checkout returns 500 for carts with a coupon.", type: "bug", labels: ["bug"]}')")
export NUMBER=$(printf '%s' "$TICKET_JSON" | jq -er '.number')
printf '%s\n' "$TICKET_JSON" | jq '{number, state, type, labels, owner, author}'

Expected: HTTP 201, state is open, type is bug, owner is null. Label names must already exist; a new repository starts with a set of default labels including bug.

2. Comment

终端窗口
COMMENT_JSON=$(curl --fail-with-body -sS -X POST "$BASE/ticket/v1/tickets/$NUMBER/comments" \
-H "Authorization: Bearer $PRAXIS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"body": "Reproduced on develop."}')
export COMMENT_ID=$(printf '%s' "$COMMENT_JSON" | jq -er '.id')

Expected: HTTP 201 with a comment id starting tc_; ticket_number equals $NUMBER.

3. Query with a filter

终端窗口
curl --fail-with-body -sS -G "$BASE/ticket/v1/tickets" \
-H "Authorization: Bearer $PRAXIS_API_KEY" \
--data-urlencode "filter=is:open type:bug" \
--data-urlencode "page_size=5" | jq '{numbers: [.tickets[].number], total_size, next_page_token}'

Expected: numbers contains the new number and its comments count is 1. When next_page_token is not empty, pass it as page_token on the next request; empty means the end.

4. Close

终端窗口
curl --fail-with-body -sS -X PATCH "$BASE/ticket/v1/tickets/$NUMBER" \
-H "Authorization: Bearer $PRAXIS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"state": "closed", "state_reason": "completed"}' | jq '{state, state_reason, closed_by, close_time}'

Expected: HTTP 200, state is closed, state_reason is completed, and closed_by is the caller.

5. Read back

终端窗口
curl --fail-with-body -sS "$BASE/ticket/v1/tickets/$NUMBER/events" \
-H "Authorization: Bearer $PRAXIS_API_KEY" | jq '[.events[].event]'

Expected: the timeline records opened, type_added, labeled, commented, closed in order.

The same with the SDK

import { Praxis } from '@deepraxis/sdk';
const praxis = new Praxis({
apiKey: process.env.PRAXIS_API_KEY!,
baseUrl: process.env.PRAXIS_API_BASE ?? 'https://api.deepraxis.com',
});
const tag = Date.now().toString(36);
const ticket = await praxis.ticket.tickets.create({
body: { title: `docs-example-checkout-bug-${tag}`, body: 'Checkout returns 500 for carts with a coupon.', type: 'bug', labels: ['bug'] },
});
const comment = await praxis.ticket.tickets.comments.create({
path: { number: ticket.number },
body: { body: 'Reproduced on develop.' },
});
const open = await praxis.ticket.tickets.list({ query: { filter: 'is:open type:bug', page_size: 5 } });
console.log(ticket.number, open.tickets.map(t => t.number));
const closed = await praxis.ticket.tickets.update({
path: { number: ticket.number },
body: { state: 'closed', state_reason: 'completed' },
});
console.log(closed.state, closed.state_reason);
await praxis.ticket.comments.delete({ path: { id: comment.id } });

Clean up

Tickets cannot be deleted, only closed; comments can be deleted.

终端窗口
curl --fail-with-body -sS -X DELETE "$BASE/ticket/v1/comments/$COMMENT_ID" \
-H "Authorization: Bearer $PRAXIS_API_KEY"

Expected: HTTP 204.

Common failures

  • A filter written as is=open: 400 INVALID_PARAMS; write is:open.
  • A number that does not exist: 404. The number in the path is number, not the tk_ id.

Sub-tickets and dependencies → · Limits and errors →