【发布时间】:2018-03-01 18:55:40
【问题描述】:
更新:我有这个私有 API 请求来获取向 shopify 管理员发送请求的客户元字段数据。
const {getAccessToken} = require('./auth')
const request = require('request')
const {shopFromPermanentDomain} = require('./helpers')
const getCustomerMetafields = ({accessToken, id, shop}) => new Promise((resolve, reject) => {
request({
url:`https://${shop}.myshopify.com/admin/customers/${id}/metafields.json',
headers: {
'X-Shopify-Access-Token': accessToken
}
}, (error, response, body) => {
const {errors} = JSON.parse(body)
if (response.statusCode === 200) {
const { metafields } = JSON.parse(body)
resolve(metafields)
}
reject({error: errors, status: 500})
})
})
const getCustomerMetafieldsResponse = (req, res) => {
const {id, permanentDomain} = req.body
if (id && permanentDomain) {
const shop = shopFromPermanentDomain(permanentDomain)
getAccessToken({shop})
.then(accessToken => getCustomerMetafields({accessToken, id, shop})
.then(meta => res.json({
meta,
status: 200
}))
)
.catch(({error, status}) => res.json({error, status}))
} else {
res.json({error: 'Missing params', status: 500})
}
}
module.exports = getCustomerMetafieldsResponse
我使用以下请求从前端向我的 API 发出此请求。
const getCustomerMeta = ({
id,
permanentDomain
}) => new Promise((resolve, reject) => {
post({
params: { email, permanentDomain, task: 'get-customer-meta' },
then: ({ error, id, state, status }) => {
if (status === 200) {
resolve({ id, state })
}
reject(error)
},
url: '/apps/spoke'
})
})
getCustomerMeta({
id, // 98303739294 (Customer ID)
permanentDomain // "store.myshopify.com"
})
发出此请求时,我收到以下请求错误:
500 (Internal Server Error)
VM706781:8 Uncaught SyntaxError: Unexpected token < in JSON at position 7
at JSON.parse (<anonymous>)
at XMLHttpRequest.l.onload
然后我想获取客户元字段数据,以便我可以使用收集的数据填充前端。
谢谢!
【问题讨论】:
标签: shopify shopify-app