Anchor to section titled 'undefined'

appPurchaseOneTimeCreate
mutation

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.


The name of the one-time purchase from the app.

The amount to be charged to the store for the app one-time purchase.

Anchor to returnUrl
returnUrl
required

The URL where the merchant is redirected after approving the app one-time purchase.

Anchor to test
test
default:false

Whether the app one-time purchase is a test transaction.


Was this section helpful?

The newly created app one-time purchase.

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 to active.

You get paid after the charge is activated.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

Hide code
DescriptionCopy
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();
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)
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"
      }
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$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]);
Hide code
Input variables
Copy
{
  "name": "1000 imported orders.",
  "returnUrl": "http://super-duper.shopifyapps.com/",
  "price": {
    "amount": 10,
    "currencyCode": "USD"
  }
}
Hide code
Response
JSON
{
  "appPurchaseOneTimeCreate": {
    "userErrors": [],
    "appPurchaseOneTime": {
      "createdAt": "2024-09-12T01:06:28Z",
      "id": "gid://shopify/AppPurchaseOneTime/1017262347"
    },
    "confirmationUrl": "https://billingshop.myshopify.com/admin/charges/193172482/1017262347/ApplicationCharge/confirm_application_charge?signature=BAh7BzoHaWRpBAsxojw6EmF1dG9fYWN0aXZhdGVU--aeb4a428c6bc3d3759488f6ec246fe61dc15a422"
  }
}