Personalized checkout and custom promotions with Shopify Scripts
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
Hi I am creating a private app for our business that reads company information then uses that to see how much credit the person has available. However we first need to know if the company is on payment terms. I can't find any way to query whether a company has payment terms attached to it. COuld you let me know how to query a company to find out if they have payment terms.
We are currently querying:
$cid = $_GET['company_id'];
if(is_numeric($cid)){
$cid = 'gid://shopify/Company/'. $cid;
}
$query = <<<GQL
{
company(id: "$cid"){
name
metafield(namespace: "custom", key: "credit_limit") {
id
namespace
key
value
}
contacts(first: 250){
edges{
node{
customer {
id
}
}
}
}
}
}
GQL;
Solved! Go to the solution
This is an accepted solution.
Received the following email from Shopify regarding this. I have not tested it but they have.
Hi Robert,
X here from the Shopify Developer Support team, I understand you've been trying to check a companies payment terms via the API but haven't been able to get there to then check other information about the company.
What we are looking for here I believe is the buyerExperienceConfiguration which is something that lives in the CompanyLocation as opposed to the company itself. If we check the B2B payment terms docs it tells us that you set payment terms for a company location which is how I found that it is there and not in the main company object.
So if you use the company ID to get specific companyLocation ID's you can then query the companyLocation and check the buyerExperienceConfiguration. I did a simple test on a store myself with the below query and two companies, one with and one without payment terms. If we try to get the ID of the paymentTermsTemplate being used it will give an ID if the company has terms and will return null it's if not, so you can tell from there whether they have any set or not. Its a little bit of a roundabout to get there depending on what data you're starting with but its not too many steps really.
Example Query:
query { companyLocation (id: "gid://shopify/CompanyLocation/123456") { buyerExperienceConfiguration { paymentTermsTemplate { id } } } }
If CompanyLocation has terms, returns with something like gid://shopify/PaymentTermsTemplate/3 but if not it will return null.
You can also grab other info about their terms in this same step if needed such as the amount of due days they get or the type of terms. If you need any more help with that feel free to let us know any time.
Have a great day,
Developer Support
This is an accepted solution.
Received the following email from Shopify regarding this. I have not tested it but they have.
Hi Robert,
X here from the Shopify Developer Support team, I understand you've been trying to check a companies payment terms via the API but haven't been able to get there to then check other information about the company.
What we are looking for here I believe is the buyerExperienceConfiguration which is something that lives in the CompanyLocation as opposed to the company itself. If we check the B2B payment terms docs it tells us that you set payment terms for a company location which is how I found that it is there and not in the main company object.
So if you use the company ID to get specific companyLocation ID's you can then query the companyLocation and check the buyerExperienceConfiguration. I did a simple test on a store myself with the below query and two companies, one with and one without payment terms. If we try to get the ID of the paymentTermsTemplate being used it will give an ID if the company has terms and will return null it's if not, so you can tell from there whether they have any set or not. Its a little bit of a roundabout to get there depending on what data you're starting with but its not too many steps really.
Example Query:
query { companyLocation (id: "gid://shopify/CompanyLocation/123456") { buyerExperienceConfiguration { paymentTermsTemplate { id } } } }
If CompanyLocation has terms, returns with something like gid://shopify/PaymentTermsTemplate/3 but if not it will return null.
You can also grab other info about their terms in this same step if needed such as the amount of due days they get or the type of terms. If you need any more help with that feel free to let us know any time.
Have a great day,
Developer Support
Using the answer above I managed to solve the issue, this was the GQL.
$query = <<<GQL
{
company(id: "$cid"){
name
metafield(namespace: "custom", key: "credit_limit") {
id
namespace
key
value
}
locations(first: 250){
edges{
node {
buyerExperienceConfiguration {
paymentTermsTemplate {
id
}
}
}
}
}
contacts(first: 250){
edges{
node{
customer {
id
tags
}
}
}
}
}
}
GQL;
and the PHP to read it:
foreach($data['data']['company']['locations']['edges'] as $location){
if($location['node']['buyerExperienceConfiguration']['paymentTermsTemplate'] !== null) {
$is_on_credit = true;
}
}