Tags
Note: The internal API is not intended as the primary way to fetch content for your front-end application or website. To fetch the content of your documents, the first place to look should be the external GraphQL API. Only if you need something beyond its scope, such as writing automatic migrations or handling imports and exports of project data, should you use the internal API.
We provide a TypeScript SDK that covers all the functions we use in the caisy front-end itself, and it can also be used by external projects. This SDK is automatically generated from a GraphQL API that we provide and use internally. Furthermore, you can use the GraphQL API in any other language.
You can try it under the following URL → https://cloud.caisy.io/caisy/graphql
in any GraphQL playground you like
To use the SDK, you must install it with: yarn add @caisy/sdk
First, you need to set up the SDK with a token. The best way to do this is to create a permanent personal access token:
To init the SDK:
import { initSdk } from "@caisy/sdk";
const sdk = initSdk({
token: token,
});
In an IDE with Typescript autocomplete support, like in Visual Studio Code, you can see all the possible queries you can make directly with the SDK.
Suppose you want to retrieve all the blueprints of your project. The code is as follows:
const getManyBlueprintsResult = await sdk.GetManyBlueprints({ input: { projectId: "aa0943f2-af8e-4920-afe5-96e7c6fb7b01" } });
Or you could duplicate a project using the SDK as follows:
await sdk.DuplicateToProject({
input: {
projectId: "b85f60bc-26c6-41cd-9a30-69f64a8ec3c3",
source: {
projectId: "41fcf4c7-b04b-4715-80fb-ebccfa70ac11",
},
selection: {
blueprint: true,
},
},
});
Side note → The same could be don with a GraphQL mutation as follows:
mutation {
DuplicateToProject(
input: {
projectId: "b85f60bc-26c6-41cd-9a30-69f64a8ec3c3"
source: { projectId: "41fcf4c7-b04b-4715-80fb-ebccfa70ac11" }
selection: { blueprint: true }
}
) {
portId
}
}
Here is a more complete code example how you could use just the fetch api in Javascript to run a graphql query against the internal API Graphql Endpoint. Keep in mind, to test this, you need to replace both the PROJECT_ID
and the PERSONAL_ACCESS_TOKEN
with your own values.
const PERSONAL_ACCESS_TOKEN = "aoL4xC1HoL1SZGQsBBr0ycsdFh5XdCXd";
const PROJECT_ID = "593065a4-0e27-4c4b-b1e3-25e3fd1ebfb1";
fetch("https://cloud.caisy.io/caisy/graphql", {
method: "POST",
headers: {
"accept": "*/*",
"cache-control": "no-cache",
"content-type": "application/json",
"x-caisy-token": PERSONAL_ACCESS_TOKEN
},
body: JSON.stringify({
operationName: "GetManyDocuments",
variables: {
input: {
projectId: PROJECT_ID,
metaFilter: {
status: {
statusId: "1"
},
variant: {
variant: "BLUEPRINT_VARIANT_DOCUMENT"
}
}
}
},
query: `
query GetManyDocuments($input: GetManyDocumentsRequestInput) {
GetManyDocuments(input: $input) {
connection {
edges {
cursor
node {
blueprintBranch
archivedAt
blueprintId
createdAt
createdByUserId
documentId
environmentId
previewImageUrl
projectId
publishedAt
statusId
title
updatedAt
lastUpdatedByUserId
__typename
}
__typename
}
pageInfo {
endCursor
hasNextPage
hasPreviousPage
startCursor
__typename
}
totalCount
__typename
}
__typename
}
}
`
})
})
.then(response => response.json())
.then(data => console.log(JSON.stringify(data, null, 2)));
All queries can be found exploring the playground on https://cloud.caisy.io/caisy/graphql - where you can add your personal access token in the "headers" tab with x-caisy-token
too, for testing.
Tags