kunwsk
1
Graphql >> discountCodeBasicCreate
指定用户部分
customerSelection: {
"customers": {
"add": "gid://shopify/Customer/xxx"
}
}
我尝试过 "add": ["gid://shopify/Customer/xxx"]
都是错误 {“message”:"Parse error on "customers" (STRING) at [9, 7]
这个地方应该怎么写啊
你们用什么语言和工具?
瞎猜,试试把Content-Type定位application/json
kunwsk
3
Content-Type 这个应该是没有问题的
customerSelection: {
"customers": {
"add": "gid://shopify/Customer/xxx"
}
}
改成全部
customerSelection: {
all: true
}
是可以成功的
只是我有一个需求是这个折扣码需要指定客户使用
Tim_Mak
4
我看了些帖子类似的问题就是把content-type从application/graphql改成application/json后是可以成功的
然后你们是用什么工具和语言测试?这个也很重要
kunwsk
5
content-type 还是这个application/graphql 这个没有改~~
是shopify-cli 下载的PHP
我说的改是 query 里面 那一个小部分修改
不是修改 content-type
意思就是我如果里面的内容是应用于全部客户, 可以成功返回, 但是如果我指定特定用户使用就错误,
我在想是不是我的query 指定特定用户得那一小段内容有问题~~正确的格式应该是什么样子的
正确格式是
"add": ["gid://shopify/Customer/xxx"]
你们试试上面的这个格式并且把 content-type改为application/json
kunwsk
7
是参数使用方式错误
$graphQL = <<<Query
mutation ($input: CustomerInput!) {
customerCreate(input: $input)
{
customer {
id
displayName
}
userErrors {
field
message
}
}
}
Query;
$variables = [
"input" => [
"firstName" => "Greg",
"lastName" => "Variables",
"email" => "gregvariables@teleworm.us"
]
]
$shopify->GraphQL->post($graphQL, null, null, $variables);
类似找各种参数方式就可以了