app Purchase One Time Create
Charges a shop for features or services one time. This type of charge is recommended for apps that aren't billed on a recurring basis. Test and demo shops aren't charged.
Arguments
- Anchor to namename•String!required
The name of the one-time purchase from the app.
- Anchor to priceprice•Money
Input!required The amount to be charged to the store for the app one-time purchase.
- Anchor to returnUrlreturn•
Url URL!required The URL where the merchant is redirected after approving the app one-time purchase.
- Anchor to testtest•BooleanDefault:false
Whether the app one-time purchase is a test transaction.
- Anchor to appPurchaseOneTimeapp•
Purchase One Time The newly created app one-time purchase.
- Anchor to confirmationUrlconfirmation•
Url The URL that the merchant can access to approve or decline the newly created app one-time purchase.
If the merchant declines, then the merchant is redirected to the app and receives a notification message stating that the charge was declined. If the merchant approves and they're successfully invoiced, then the state of the charge changes from
pending
toactive
.You get paid after the charge is activated.
- Anchor to userErrorsuser•
Errors [UserError!]!non-null The list of errors that occurred from executing the mutation.
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation AppPurchaseOneTimeCreate($name: String!, $price: MoneyInput!, $returnUrl: URL!) {6 appPurchaseOneTimeCreate(name: $name, returnUrl: $returnUrl, price: $price) {7 userErrors {8 field9 message10 }11 appPurchaseOneTime {12 createdAt13 id14 }15 confirmationUrl16 }17 }`,18 {19 variables: {20 "name": "1000 imported orders.",21 "returnUrl": "http://super-duper.shopifyapps.com/",22 "price": {23 "amount": 10.0,24 "currencyCode": "USD"25 }26 },27 },28);2930const data = await response.json();31
mutation AppPurchaseOneTimeCreate($name: String!, $price: MoneyInput!, $returnUrl: URL!) {
appPurchaseOneTimeCreate(name: $name, returnUrl: $returnUrl, price: $price) {
userErrors {
field
message
}
appPurchaseOneTime {
createdAt
id
}
confirmationUrl
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation AppPurchaseOneTimeCreate($name: String!, $price: MoneyInput!, $returnUrl: URL!) { appPurchaseOneTimeCreate(name: $name, returnUrl: $returnUrl, price: $price) { userErrors { field message } appPurchaseOneTime { createdAt id } confirmationUrl } }",
"variables": {
"name": "1000 imported orders.",
"returnUrl": "http://super-duper.shopifyapps.com/",
"price": {
"amount": 10.0,
"currencyCode": "USD"
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation AppPurchaseOneTimeCreate($name: String!, $price: MoneyInput!, $returnUrl: URL!) {
appPurchaseOneTimeCreate(name: $name, returnUrl: $returnUrl, price: $price) {
userErrors {
field
message
}
appPurchaseOneTime {
createdAt
id
}
confirmationUrl
}
}`,
{
variables: {
"name": "1000 imported orders.",
"returnUrl": "http://super-duper.shopifyapps.com/",
"price": {
"amount": 10.0,
"currencyCode": "USD"
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation AppPurchaseOneTimeCreate($name: String!, $price: MoneyInput!, $returnUrl: URL!) {
appPurchaseOneTimeCreate(name: $name, returnUrl: $returnUrl, price: $price) {
userErrors {
field
message
}
appPurchaseOneTime {
createdAt
id
}
confirmationUrl
}
}`,
"variables": {
"name": "1000 imported orders.",
"returnUrl": "http://super-duper.shopifyapps.com/",
"price": {
"amount": 10.0,
"currencyCode": "USD"
}
},
},
});
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
mutation AppPurchaseOneTimeCreate($name: String!, $price: MoneyInput!, $returnUrl: URL!) {
appPurchaseOneTimeCreate(name: $name, returnUrl: $returnUrl, price: $price) {
userErrors {
field
message
}
appPurchaseOneTime {
createdAt
id
}
confirmationUrl
}
}
QUERY
variables = {
"name": "1000 imported orders.",
"returnUrl": "http://super-duper.shopifyapps.com/",
"price": {
"amount": 10.0,
"currencyCode": "USD"
}
}
response = client.query(query: query, variables: variables)
Input variables
JSON1{2 "name": "1000 imported orders.",3 "returnUrl": "http://super-duper.shopifyapps.com/",4 "price": {5 "amount": 10,6 "currencyCode": "USD"7 }8}
Response
JSON1{2 "appPurchaseOneTimeCreate": {3 "userErrors": [],4 "appPurchaseOneTime": {5 "createdAt": "2024-11-21T22:47:04Z",6 "id": "gid://shopify/AppPurchaseOneTime/1017262352"7 },8 "confirmationUrl": "https://billingshop.myshopify.com/admin/charges/193172482/1017262352/ApplicationCharge/confirm_application_charge?signature=BAh7BzoHaWRpBBAxojw6EmF1dG9fYWN0aXZhdGVU--a03eedf9ef12d714906af085ebc2aa3d97aa9466"9 }10}