Campaigns API
The Campaigns API is an integral component of the core
service. As a result, all requests should be directed to: https://api.subsbase.io/core/v2/graphql
.
The core service expects 2 headers, the X-SITE-ID
and Authorization
so the request would be:
POST https://api.subsbase.io/core/v2/graphql
Authorization: Bearer {server token}
X-SITE-ID: {your site id}
Consuming the Campaigns API requires that a server token is used to authenticate the request. The server token is expected in the Authorization header.
Queries
Campaigns Query
query GetCampaigns($siteId: null,$filter: FilterGQLInputType,$pagination: PaginationGQLInputType,$sorting: [SortingGQLInputType]) {
campaigns (siteId: $siteId,filter: $filter,pagination: $pagination,sorting: $sorting) {
isSuccess
pagination
data{
id
#All properties are found in the CampaignGQLType
}
message
}
}
- Request Variables Sample:
{"siteId":"","filter":"","pagination":"","sorting":""}
- Returns an array of campaigns.
- You can specify any of the fields detailed in the Campaign Type Definition.
- For details about Pagination, Sorting, and Filtering Input Types, please check out PaginationGQLInputType, SortingGQLInputType, FilteringGQLInputType.
Campaign Query
query GetCampaign($siteId: String!,$campaignId: String!) {
campaign (siteId: $siteId,campaignId: $campaignId) {
siteId
id
name
value
#All properties are found in the CampaignGQLType
}
- Request Variables Sample:
{"siteId":"","campaignId":""}
- Returns a specific campaigns.
- You can specify any of the fields detailed in the Campaign Type Definition.
Campaign Mutations/Operations
Create Campaign
- To create a campaign, you need to use the following Mutation, it is advisable to use
variables
in this case since the input types are more complex than just strings:
mutation CreateCampaign(
$siteId: String!
$campaign: CampaignGQLInputType!
$promoCode: String!
$quantity: Int!
) {
campaigns(siteId: $siteId) {
create(campaign: $campaign) {
withCodes(promoCode: $promoCode, quantity: $quantity) {
isSuccess
message
}
}
}
}
### variables
{
"siteId": "test-site",
"campaign": {
"name": "John",
"value": 50,
"status": "Active",
"type": "Percentage"
},
"promoCode": "Empty-spaces-1575",
"quantity": 5
}
- You can specify any of the fields detailed in the Campaign Type Definition.
Update Campaign
- To update a campaign, you need to use the following Mutation:
mutation UpdateCampaign(
$siteId: String!
$campaign: CampaignGQLInputType!
$campaignId: String!
) {
campaign(siteId: $siteId, campaignId: $campaignId) {
update(campaign: $campaign) {
isSuccess
message
}
}
}
### variables
{
"siteId": "test-site",
"ccampaignId": "9a8386cd-23e2-48cf-a0b8-e3fee1b22174",
"campaign": {
"type": "percentage",
"name": "new-name"
}
}
- You can specify any of the fields detailed in the Campaign Type Definition.
Delete Campaign
- To delete a campaign, you need to use the following Mutation:
mutation DeleteCampaign($siteId: String!, $campaignId: String!) {
campaign(siteId: $siteId, campaignId: $campaignId) {
delete {
isSuccess
message
}
}
}
### variables
{
"siteId": "test-site",
"campaignId": "9a8386cd-23e2-48cf-a0b8-e3fee1b22174"
}
Delete Promo Codes
- To delete promo codes, you need to use the following Mutation:
mutation DeleteCodes($siteId: String!, $ids: [String]!) {
campaign(siteId: $siteId) {
promoCodes(ids: $ids) {
delete {
isSuccess
message
}
}
}
}
### variables
{
"siteId": "test-site",
"ids": [
"1d7f4491-1773-45c7-8a77-1e80b929e242",
"26c3f75c-35e1-49a9-8f1f-fec76c709fc3",
"cdcf338c-30b1-4656-804b-a0637c1b2bfd",
"e986e2e0-c771-425d-b7ea-872153785e21",
"efaf8b55-d9e7-4481-8b49-7ab63e148811"
]
}
Apply Promo Code on Subscription
- To apply a promo code on a subscription, you need to use the following Mutation:
mutation ApplyPromoCodeOnSubscription(
$siteId: String!
$customerId: String!
$planSubscriptionId: String!
$promoCode: String!
) {
customer(siteId: $siteId, customerId: $customerId) {
subscription(planSubscriptionId: $planSubscriptionId) {
applyPromoCode(promoCode: $promoCode) {
isSuccess
message
}
}
}
}
### variables
{
"siteId": "test-site",
"customerId": "477a9b74-f959-4cd7-92e5-b978dfb62726",
"planSubscriptionId": "2d9e18c6-2ca7-4c06-b30a-666a2695e75d",
"promoCode": "testing-promocode2"
}