Setting payment terms using draftOrderCreate

Solved

Setting payment terms using draftOrderCreate

kmatsumo
Shopify Partner
6 0 0

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"
      }
    }
  }
}
Accepted Solution (1)

GrahamS
Shopify Staff (Retired)
193 37 54

This is an accepted solution.

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,

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 8 (8)

GrahamS
Shopify Staff (Retired)
193 37 54

This is an accepted solution.

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,

To learn more visit the Shopify Help Center or the Community Blog.

kmatsumo
Shopify Partner
6 0 0

@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.

bbarr
Shopify Partner
32 4 10

@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?

kmatsumo
Shopify Partner
6 0 0

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

bbarr
Shopify Partner
32 4 10

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?

kmatsumo
Shopify Partner
6 0 0

@bbarrYes 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 🙂

bbarr
Shopify Partner
32 4 10

@kmatsumoThis 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.

kmatsumo
Shopify Partner
6 0 0

@bbarrI 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... 😞