Javascript 无效的\u请求\u错误-版本\u不匹配-对象版本与最新数据库版本不匹配
我正在尝试使用节点的Javascript 无效的\u请求\u错误-版本\u不匹配-对象版本与最新数据库版本不匹配,javascript,firebase,request,square,square-connect,Javascript,Firebase,Request,Square,Square Connect,我正在尝试使用节点的square connect包更新square资源清册中的一些数据,如下所示: 9:02:19.367 AM updateItem Function execution started 9:02:21.309 AM updateItem Function execution took 1944 ms, finished with status: 'ok' 9:02:31.834 AM updateItem API called successfully in searchFo
square connect
包更新square资源清册中的一些数据,如下所示:
9:02:19.367 AM
updateItem
Function execution started
9:02:21.309 AM
updateItem
Function execution took 1944 ms, finished with status: 'ok'
9:02:31.834 AM
updateItem
API called successfully in searchFor IDS. Returned data: {"objects":[{"type":"ITEM_VARIATION","id":"6WNRO7PULPW7Z4QL73FEVITU","updated_at":"2018-08-14T00:53:50.645Z","version":1534208030645,"is_deleted":false,"present_at_all_locations":true,"item_variation_data":{"item_id":"SUW2HSXCNSERMTGERY4Y54TD","name":"Regular","sku":"0637792505002","ordinal":0,"pricing_type":"FIXED_PRICING","price_money":{"amount":100,"currency":"USD"},"location_overrides":[{"location_id":"JN6S37JH6M1Z2","track_inventory":true}],"track_inventory":true}}]}
9:02:47.035 AM
updateItem
{ Error: Bad Request
at Request.callback (/user_code/node_modules/square-connect/node_modules/superagent/lib/node/index.js:675:11)
at /user_code/node_modules/square-connect/node_modules/superagent/lib/node/index.js:883:18
at Stream.<anonymous> (/user_code/node_modules/square-connect/node_modules/superagent/lib/node/parsers/json.js:16:7)
at emitNone (events.js:86:13)
at Stream.emit (events.js:185:7)
at Unzip.<anonymous> (/user_code/node_modules/square-connect/node_modules/superagent/lib/node/unzip.js:53:12)
at emitNone (events.js:91:20)
at Unzip.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
status: 400,
response:
Response {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
res:
IncomingMessage {
_readableState: [Object],
readable: false,
domain: null,
_events: [Object],
_eventsCount: 3,
_maxListeners: undefined,
socket: [Object],
connection: [Object],
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: true,
headers: [Object],
rawHeaders: [Object],
trailers: {},
rawTrailers: [],
upgrade: false,
url: '',
method: null,
statusCode: 400,
statusMessage: 'Bad Request',
client: [Object],
_consuming: true,
_dumped: false,
req: [Object],
setEncoding: [Function],
on: [Function],
text: '{"errors":[{"category":"INVALID_REQUEST_ERROR","code":"VERSION_MISMATCH","detail":"Object version does not match latest database version.","field":"version"}]}',
read: [Function] },
request:
Request {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
_agent: false,
_formData: null,
method: 'POST',
url: 'https://connect.squareup.com/v2/catalog/batch-upsert',
_header: [Object],
header: [Object],
writable: true,
_redirects: 0,
_maxRedirects: 5,
cookies: '',
qs: {},
qsRaw: [],
_redirectList: [],
_streamRequest: false,
_timeout: 60000,
_responseTimeout: 0,
_data: [Object],
req: [Object],
protocol: 'https:',
host: 'connect.squareup.com',
_endCalled: true,
_callback: [Function],
res: [Object],
response: [Circular],
called: true },
req:
ClientRequest {
domain: null,
_events: [Object],
_eventsCount: 3,
_maxListeners: undefined,
output: [],
outputEncodings: [],
outputCallbacks: [],
outputSize: 0,
writable: true,
_last: true,
upgrading: false,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedHeader: [Object],
_contentLength: 526,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: [Object],
connection: [Object],
_header: 'POST /v2/catalog/batch-upsert HTTP/1.1\r\nHost: connect.squareup.com\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: Square-Connect-Javascript/2.20180712.1\r\nAuthorization: Bearer sq0atp-on5KcHDr0dhlbefU0EwVwg\r\nSquare-Version: 2018-07-12\r\nContent-Type: application/json\r\nAccept: application/json\r\nContent-Length: 526\r\nConnection: close\r\n\r\n',
_headers: [Object],
_headerNames: [Object],
_onPendingData: null,
agent: [Object],
socketPath: undefined,
timeout: undefined,
method: 'POST',
path: '/v2/catalog/batch-upsert',
_ended: true,
parser: null,
res: [Object] },
text: '{"errors":[{"category":"INVALID_REQUEST_ERROR","code":"VERSION_MISMATCH","detail":"Object version does not match latest database version.","field":"version"}]}',
body: { errors: [Object] },
files: undefined,
buffered: true,
headers:
{ 'content-encoding': 'gzip',
'content-type': 'application/json',
'square-version': '2018-07-12',
vary: 'Origin, Accept-Encoding',
'x-content-type-options': 'nosniff',
'x-download-options': 'noopen',
'x-frame-options': 'SAMEORIGIN',
'x-permitted-cross-domain-policies': 'none',
'x-xss-protection': '1; mode=block',
date: 'Tue, 14 Aug 2018 13:02:39 GMT',
'keep-alive': 'timeout=60',
'strict-transport-security': 'max-age=631152000',
'content-length': '159',
connection: 'close' },
header:
{ 'content-encoding': 'gzip',
'content-type': 'application/json',
'square-version': '2018-07-12',
vary: 'Origin, Accept-Enco
我正在使用一个firebase函数
函数,该函数在firebase数据库更新时执行代码(这就是export.updateItem
的作用,它是执行的函数,并返回更新数据的快照):
firebase函数日志如下所示:
9:02:19.367 AM
updateItem
Function execution started
9:02:21.309 AM
updateItem
Function execution took 1944 ms, finished with status: 'ok'
9:02:31.834 AM
updateItem
API called successfully in searchFor IDS. Returned data: {"objects":[{"type":"ITEM_VARIATION","id":"6WNRO7PULPW7Z4QL73FEVITU","updated_at":"2018-08-14T00:53:50.645Z","version":1534208030645,"is_deleted":false,"present_at_all_locations":true,"item_variation_data":{"item_id":"SUW2HSXCNSERMTGERY4Y54TD","name":"Regular","sku":"0637792505002","ordinal":0,"pricing_type":"FIXED_PRICING","price_money":{"amount":100,"currency":"USD"},"location_overrides":[{"location_id":"JN6S37JH6M1Z2","track_inventory":true}],"track_inventory":true}}]}
9:02:47.035 AM
updateItem
{ Error: Bad Request
at Request.callback (/user_code/node_modules/square-connect/node_modules/superagent/lib/node/index.js:675:11)
at /user_code/node_modules/square-connect/node_modules/superagent/lib/node/index.js:883:18
at Stream.<anonymous> (/user_code/node_modules/square-connect/node_modules/superagent/lib/node/parsers/json.js:16:7)
at emitNone (events.js:86:13)
at Stream.emit (events.js:185:7)
at Unzip.<anonymous> (/user_code/node_modules/square-connect/node_modules/superagent/lib/node/unzip.js:53:12)
at emitNone (events.js:91:20)
at Unzip.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
status: 400,
response:
Response {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
res:
IncomingMessage {
_readableState: [Object],
readable: false,
domain: null,
_events: [Object],
_eventsCount: 3,
_maxListeners: undefined,
socket: [Object],
connection: [Object],
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: true,
headers: [Object],
rawHeaders: [Object],
trailers: {},
rawTrailers: [],
upgrade: false,
url: '',
method: null,
statusCode: 400,
statusMessage: 'Bad Request',
client: [Object],
_consuming: true,
_dumped: false,
req: [Object],
setEncoding: [Function],
on: [Function],
text: '{"errors":[{"category":"INVALID_REQUEST_ERROR","code":"VERSION_MISMATCH","detail":"Object version does not match latest database version.","field":"version"}]}',
read: [Function] },
request:
Request {
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
_agent: false,
_formData: null,
method: 'POST',
url: 'https://connect.squareup.com/v2/catalog/batch-upsert',
_header: [Object],
header: [Object],
writable: true,
_redirects: 0,
_maxRedirects: 5,
cookies: '',
qs: {},
qsRaw: [],
_redirectList: [],
_streamRequest: false,
_timeout: 60000,
_responseTimeout: 0,
_data: [Object],
req: [Object],
protocol: 'https:',
host: 'connect.squareup.com',
_endCalled: true,
_callback: [Function],
res: [Object],
response: [Circular],
called: true },
req:
ClientRequest {
domain: null,
_events: [Object],
_eventsCount: 3,
_maxListeners: undefined,
output: [],
outputEncodings: [],
outputCallbacks: [],
outputSize: 0,
writable: true,
_last: true,
upgrading: false,
chunkedEncoding: false,
shouldKeepAlive: false,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedHeader: [Object],
_contentLength: 526,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: [Object],
connection: [Object],
_header: 'POST /v2/catalog/batch-upsert HTTP/1.1\r\nHost: connect.squareup.com\r\nAccept-Encoding: gzip, deflate\r\nUser-Agent: Square-Connect-Javascript/2.20180712.1\r\nAuthorization: Bearer sq0atp-on5KcHDr0dhlbefU0EwVwg\r\nSquare-Version: 2018-07-12\r\nContent-Type: application/json\r\nAccept: application/json\r\nContent-Length: 526\r\nConnection: close\r\n\r\n',
_headers: [Object],
_headerNames: [Object],
_onPendingData: null,
agent: [Object],
socketPath: undefined,
timeout: undefined,
method: 'POST',
path: '/v2/catalog/batch-upsert',
_ended: true,
parser: null,
res: [Object] },
text: '{"errors":[{"category":"INVALID_REQUEST_ERROR","code":"VERSION_MISMATCH","detail":"Object version does not match latest database version.","field":"version"}]}',
body: { errors: [Object] },
files: undefined,
buffered: true,
headers:
{ 'content-encoding': 'gzip',
'content-type': 'application/json',
'square-version': '2018-07-12',
vary: 'Origin, Accept-Encoding',
'x-content-type-options': 'nosniff',
'x-download-options': 'noopen',
'x-frame-options': 'SAMEORIGIN',
'x-permitted-cross-domain-policies': 'none',
'x-xss-protection': '1; mode=block',
date: 'Tue, 14 Aug 2018 13:02:39 GMT',
'keep-alive': 'timeout=60',
'strict-transport-security': 'max-age=631152000',
'content-length': '159',
connection: 'close' },
header:
{ 'content-encoding': 'gzip',
'content-type': 'application/json',
'square-version': '2018-07-12',
vary: 'Origin, Accept-Enco
当我查找数据时,我会看到一个版本属性,该属性附带一个正方形项_变体
,如下所示:
"version":1534208030645
您可以在上面输出的文本后面的对象中看到它:
在搜索ID时成功调用API。返回的数据:
它出现在搜索项_变体时返回的数据中。我曾尝试将此字段和值放入batchUpsertCatalogObjects
请求中,但似乎没有帮助-我相信我在尝试这样做时收到了另一个错误(我记不起它是什么,或者现在在日志中找不到它)
任何帮助都将不胜感激
更新
我尝试将version:dat.objects[0].version
添加到项
对象,但没有帮助
更新
我试过这个:
var variationObj = dat.objects[0];
variationObj.item_variation_data.price_money = {amount: Number(newValue.price) * 100, currency: 'USD'};
var item = {
type: 'ITEM',
id: dat.objects[0].item_variation_data.item_id,
item_data: {
name: newValue.barcode,
description: newValue.description,
variations: [variationObj]
}
};
尽管如此,我仍然会遇到同样的错误——即使我使用的是从查询返回给我的同一个对象
更新
上面的更新是有效的-请参见答案。这个技巧似乎是直接从响应中获取我需要的对象,然后像responseObj.xxxxxxx=xxxxxxxx
-那样编辑它,而不是尝试使用{}
符号自己创建一个对象,然后将该对象作为必要的参数传递。此外,firebase部署
有时似乎需要重新运行,以使更改真正生效
似乎我还需要使用ussertcatalogobject
分别上传项目和项目变体
,而不是将项目变体
包含在项目变体
字段中,或者将batchUpsertCatalogObject
与batchs
数组中包含的ITEM
和ITEM\u变量一起使用-这似乎也不起作用。如何更新对象?您是否通过API检索它,然后更改返回对象中的字段?如果是-它应该已经有了与之关联的版本,因此您不应该收到此错误。我想我明白您的意思了,我现在正试图通过将响应变量项存储在变量中,然后编辑price\u money
字段(我需要为变量编辑的唯一字段)来实现您的建议直接在那个变量上,这样价格就改变了。@sjosey看到我的更新了吗……这就是你的意思吗?我只是想用它自己来更新项目的变化!如果你能找到答案,请告诉我:)
var variationObj = dat.objects[0];
variationObj.item_variation_data.price_money = {amount: Number(newValue.price) * 100, currency: 'USD'};
var item = {
type: 'ITEM',
id: dat.objects[0].item_variation_data.item_id,
item_data: {
name: newValue.barcode,
description: newValue.description,
variations: [variationObj]
}
};