Setting payment terms using draftOrderCreate

https://shopify.dev/api/admin-graphql/2021-10/mutations/draftOrderCreate

I’m trying to set a “Due Date” while creating a Draft Order.

I’ve tried using the “Shopify GraphiQL App” to try executing the query but I get “Access denied” in return.

I’ve selected all the permission from “Admin API” while installing the “Shopify GraphiQL App”, so I’m pretty sure I’ve got all the permissions.

The query and variables below works if I remove the “paymentTerms”. Any idea what I’ve done wrong?

Thanks.

mutation draftOrderCreate($input: DraftOrderInput!) {
  draftOrderCreate(input: $input) {
    draftOrder {
      id
    }
    userErrors {
      field
      message
    }
  }
}

------------------

{
  "input": {
    "customerId": "gid://shopify/Customer/XXXX",
    "lineItems": [
      {
        "variantId": "gid://shopify/ProductVariant/YYYYY",
        "quantity": 1
      }
    ],
    "paymentTerms": {
      "paymentSchedules": {
        "dueAt": "2021-12-31T00:00:00Z"
      }
    }
  }
}

Hey @kmatsumo

That specific field requires access to the payment_terms scope. It’s available for private apps, but not currently for the GraphiQL admin app, which is why you would receive an error when performing this operation through that interface.

You can manually apply the necessary permission to a private app and run your GraphQL query that way while we work on making this scope available to the GraphiQL app.

I hope this helps!

Best,

@GrahamS

Hey, sorry for the late reply!

Thank you, it is not giving me the error after adding the scope.

(Although I’m encountering another error, I’ll try figure it out my self for now)

Would be nice if the documents were a bit more clearer so I know which scopes are needed.

Or I might have not reading it properly…

Thanks once again.

@GrahamS or @kmatsumo

Do either of you know if this is the suggested way to accomplish Net-30 terms? Like, just calculate the 30 days, and assign that date as the dueAt property?

I believe this is currently the only way to manage it.

Thanks @kmatsumo . I am trying to do this by following your query exactly, but it is giving me the following error:

{"data":{"draftOrderCreate":{"draftOrder":null,"userErrors":[{"field":null,"message":"Payment terms template id can not be empty."}]}}

Did you not run into this?

@bbarr Yes I did. Unfortunately I could not solve the problem in time. I currently am not working on that project anymore so I did not do further research to fix it. Sorry I couldn’t help.

If you manage to solve it, it would be nice if you shared it :slightly_smiling_face:

@kmatsumo This is classic Shopify, they hid a bunch of data that you have to eventually guess exists and go looking for it. No documentation for it, no references in how-to or post.

{
  paymentTermsTemplates {
    id
    dueInDays
  }
}

This will give you a list of various “templates” to use. This has been yet another terrible developer experience.

@bbarr I agree. The only solution now you have is to create a question and hope one of the devs or someone that knows the answer will answer…

Or do some grinding and figure it out your self… :disappointed_face:

For reference here’s a sample query

query orderPaymentTerms
query orderPaymentTerms {
  order(id:"gid://shopify/Order/5786833027118"){
    id
    paymentTerms {
      id
      due
      dueInDays
      overdue
      paymentTermsName
      paymentTermsType
      paymentSchedules(first:5) {
        edges {
          node {
            due
            dueAt
            issuedAt
            completedAt
            balanceDue { amount }
            totalBalance { amount }
          }
        }
      }
    }
    netPaymentSet {
      shopMoney {
        amount
      }
    }
  }
}

Then a mutation w/ variables

mutation PaymentTermsUpdate
mutation PaymentTermsUpdate($input: PaymentTermsUpdateInput!) {
  paymentTermsUpdate(input: $input) {
    paymentTerms {
      id
    }
    userErrors {
      code
      field
      message
    }
  }
}

Note the variables below are using the Net15 template, template found through the paymentTermsTemplates query shown above by another poster or in the api docs.
:warning: This means the issuedAt and dueAt DateTime must be that difference

PaymentTermsUpdateInput variables
{
  "input": {
    "paymentTermsId": "gid://shopify/PaymentTerms/1234567890",
    "paymentTermsAttributes": {
      "paymentTermsTemplateId": "gid://shopify/PaymentTermsTemplate/3",
      "paymentSchedules": [
        {
          "dueAt": "2030-11-16T00:00:00Z",
          "issuedAt": "2030-11-01T00:00:00Z"
        }
      ]
    }
  }
}