Prerequisites
- A workspace in Amplication
- An API token for the workspace
Amplication + GraphQL
Amplication is built with GraphQL in mind. This means that you can easily integrate Amplication with any IDP using by calling the GraphQL API.Authentication
Your calls to the Amplication GraphQL API will need to be authenticated. You should use the API token to authenticate your calls. This is done by sending the token in theAuthorization header of your request:
Copy
{
Authorization: "Bearer YOUR_API_TOKEN"
Content-Type: "application/json"
}
Requests
Since we’re working with GraphQL, you’ll need to make requests to the GraphQL endpoint. The endpoint ishttps://server.amplication.com/graphql and it will accept POST requests for queries and mutations.
This is a sample query:
Copy
const query = `
query searchCatalog($where: ResourceWhereInputWithPropertiesFilter) {
catalog(where: $where) {
totalCount
data {
id
name
}
}
}
`;
const variables = {
take: 100,
skip: 0,
where: {
resourceType: { in: ["ServiceTemplate"] }
}
};
fetch('https://server.amplication.com/graphql', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_TOKEN',
'Content-Type': 'application/json',
},
body: JSON.stringify({
query,
variables
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
Get Requests
- Templates
- Resources
- Alerts
This is how you fetch templates.
Query
Query
Copy
query searchCatalog($where: ResourceWhereInputWithPropertiesFilter, $take: Int, $skip: Int) {
catalog(where: $where, take: $take, skip: $skip) {
totalCount
data {
id
name
description
resourceType
project {
id
name
}
blueprint {
id
name
}
}
__typename
}
}
Variables
Variables
Copy
{
"take": 100,
"skip": 0,
"where": {"resourceType": {"in": ["ServiceTemplate"]}},
}
Response
Response
Copy
{
data: {
catalog: {
data: {
{
"id": "cm6zln01a0209utjtlorazri1",
"name": "Node.js Template",
"description": "Template created from an existing resource",
"resourceType": "ServiceTemplate",
"project": {
"id": "cm6zlfk2o01liutjtdw8xj7f0",
"name": "Base Project"
},
"blueprint": {
"id": "cm6gb3j00000p14gz2n11otq4",
"name": "Node.js Service (Amplication's Standard)"
}
},
{
"id": "u1z6ijno0lrzmlra1ta9c200t",
"name": ".Net Template",
...
}
}
}
}
}
This is how you fetch resources.
Query
Query
Copy
query searchCatalog($where: ResourceWhereInputWithPropertiesFilter, $take: Int, $skip: Int) {
catalog(where: $where, take: $take, skip: $skip) {
totalCount
data {
id
name
description
resourceType
project {
id
name
}
blueprint {
id
name
}
serviceTemplate {
id
name
projectId
}
gitRepository {
name
gitOrganization {
name
provider
}
}
}
__typename
}
}
Variables
Variables
Copy
{
"take": 100,
"skip": 0,
"where": {"resourceType": {"in": ["Service", "Component"]}},
}
Response
Response
Copy
{
data: {
catalog: {
data: {
"id": "cm6gr9t4s0000jx5t8l8prvik",
"name": "Sample Resource Name",
"description": "General description for the resource",
"resourceType": "Service",
"project": {
"id": "cm6gb3j0a000q14gzlq9m7h1o",
"name": "Sample Project"
},
"blueprint": {
"id": "cm6gb3j00000p14gz2n11otq4",
"name": ".Net Service (Amplication's Standard)"
},
"serviceTemplate": null,
"gitRepository": {
"name": "example-repo",
"gitOrganization": {
"name": "example-company",
"provider": "Github"
}
},
{
"id": "9i0rc6km088vr0j0gt4lst5xp",
"name": "Another Sample Resource",
...
}
}
}
}
}
This is how to fetch outdated version alertsThe returned
type could be one of the three:- CodeEngineVersion
- PluginVersion
- TemplateVersion
Query
Query
Copy
fragment OutdatedVersionAlertFields on OutdatedVersionAlert {
id
createdAt
updatedAt
resourceId
blockId
block {
id
displayName
}
type
outdatedVersion
latestVersion
status
}
query getOutdatedVersionAlerts(
$where: OutdatedVersionAlertWhereInput
$orderBy: OutdatedVersionAlertOrderByInput
$take: Int
$skip: Int
) {
outdatedVersionAlerts(
where: $where
orderBy: $orderBy
take: $take
skip: $skip
) {
...OutdatedVersionAlertFields
}
_outdatedVersionAlertsMeta(where: $where) {
count
}
}
Variables
Variables
Copy
{
"take": 100,
"skip": 0,
"orderBy": {"createdAt": "Desc"}
}
Response
Response
Copy
{
data: {
outdatedVersionAlerts: {
{
"id": "cm71nzqfh00lftp1dh9bslk0n",
"createdAt": "2025-02-18T10:07:00.022Z",
"updatedAt": "2025-02-18T10:07:00.022Z",
"resourceId": "cm71nzdyn00kltp1dyoe4abpu",
"blockId": "cm67mln9k004k55uul3j4ywww",
"block": {
"id": "cm67mln9k004k55uul3j4ywww",
"displayName": "Resource Template Version"
},
"type": "TemplateVersion",
"outdatedVersion": "0.1.0",
"latestVersion": "0.2.0",
"status": "New"
},
{
"id": "90pdh0t1fmk0lqnsh7nblcz1f",
...
}
}
}
}
Post Requests
- Scaffold Resource
- Code Re-build
Scaffolding a resource from an existing template is something we can do often.
Query
Query
Copy
mutation createServiceFromTemplate($data: ResourceFromTemplateCreateInput!) {
createResourceFromTemplate(data: $data) {
id
name
description
__typename
}
}
Variables
Variables
Copy
{
"data": {
"name": "Resource Name",
"description": "Resource Description",
"project": {
"connect": {
"id": "cm6zlfk2o01liutjtdw8xj7f0"
}
},
"serviceTemplate": {
"id": "cm6zln01a0209utjtlorazri1"
}
}
}
Response
Response
Copy
{
"data": {
"createResourceFromTemplate": {
"id": "cm7hf6bd20000r00ucwlkads3",
"name": "Resource Name",
"description": "Resource Description",
"__typename": "Resource"
}
}
}
Trigger a resource to re-build and commit its code to git.
Query
Query
Copy
mutation commit($data: CommitCreateInput!) {
commit(data: $data) {
id
builds {
id
resourceId
status
__typename
}
__typename
}
}
Variables
Variables
Copy
{
"data": {
"message": "feat(server): work in progress",
"project": {
"connect": {
"id": "cm6zlfk2o01liutjtdw8xj7f0"
}
},
"resourceIds": [
"cm7hf6bd20000r00ucwlkads3"
],
"bypassLimitations": true,
"commitStrategy": "Specific",
"resourceTypeGroup": "Services"
}
}
Response
Response
Copy
{
"data": {
"commit": {
"id": "cm7hfbv0g000nr00u61tlp735",
"builds": null,
"__typename": "Commit"
}
}
}