Javascript list_pop 在 Zapier 存储上
Javascript list_pop on Zapier Storage
我是代码块中 Zapier Store 的重度用户 (Javascript)。
最近发送到存储的数据突然增加,有时我存储满了(每天清理它没有帮助)。
我想采用先进先出的方法,如果存储中的记录数> 450,我会删除存储中创建的第一条记录。
我一直在尝试以下方法:
let secret = "mySuperSecret";
let store = StoreClient(secret);
// Get the amount of data included in the Storage
let res = await fetch("https://store.zapier.com/api/records?secret=" + secret);
let body = await res.json();
let length= Object.keys(body).length;
console.log(length);
let value = await store.get(inputData.importantInfo);
if (value == "published"){
found = true;
callback(null, {result:"Store Record already found"});
} else {
// Check if the number of records is higher than the limit
if (length>450){
// Delete the first record in the Storage (FIFO)
store.list_pop('userMail', location='head') // Does not work
}
// Set the new storage value
store.list_push(inputData.importantInfo, "published");
callback(null, {result:"Storage value (" + inputData.importantInfo + ") set to 'published'"});
}
但是我没有成功。我想 list_pop 方法仅适用于 Python。
有没有人尝试过类似的方法并找到了解决方案?
有人有更好的主意吗?
非常感谢!
我解决了: 问题出在存储设置的方式和需要 PATCH 请求上。
添加元素:
let url = "https://store.zapier.com/api/records";
let headers = {
"Content-Type":"application/json",
"X-Secret": secret
}
body = {
"action":"list_push",
"data":
{
"key":key,
"value":value
}
};
let options = {
"method": "PATCH",
"headers": headers,
"body": JSON.stringify(body)
}
let response = await fetch(url, options);
您将获得如下所示的存储库:
{"group": {"list": ["value1", "value2", "value3"...]}}
从列表顶部弹出个元素:
let url = "https://store.zapier.com/api/records";
let headers = {
"Content-Type":"application/json",
"X-Secret": secret
}
body = {
"action":"list_pop",
"data":
{
"key":key,
"location":"head"
}
};
let options = {
"method": "PATCH",
"headers": headers,
"body": JSON.stringify(body)
}
let response = await fetch(url, options);
谢谢!
我是代码块中 Zapier Store 的重度用户 (Javascript)。
最近发送到存储的数据突然增加,有时我存储满了(每天清理它没有帮助)。
我想采用先进先出的方法,如果存储中的记录数> 450,我会删除存储中创建的第一条记录。
我一直在尝试以下方法:
let secret = "mySuperSecret";
let store = StoreClient(secret);
// Get the amount of data included in the Storage
let res = await fetch("https://store.zapier.com/api/records?secret=" + secret);
let body = await res.json();
let length= Object.keys(body).length;
console.log(length);
let value = await store.get(inputData.importantInfo);
if (value == "published"){
found = true;
callback(null, {result:"Store Record already found"});
} else {
// Check if the number of records is higher than the limit
if (length>450){
// Delete the first record in the Storage (FIFO)
store.list_pop('userMail', location='head') // Does not work
}
// Set the new storage value
store.list_push(inputData.importantInfo, "published");
callback(null, {result:"Storage value (" + inputData.importantInfo + ") set to 'published'"});
}
但是我没有成功。我想 list_pop 方法仅适用于 Python。
有没有人尝试过类似的方法并找到了解决方案?
有人有更好的主意吗?
非常感谢!
我解决了: 问题出在存储设置的方式和需要 PATCH 请求上。
添加元素:
let url = "https://store.zapier.com/api/records";
let headers = {
"Content-Type":"application/json",
"X-Secret": secret
}
body = {
"action":"list_push",
"data":
{
"key":key,
"value":value
}
};
let options = {
"method": "PATCH",
"headers": headers,
"body": JSON.stringify(body)
}
let response = await fetch(url, options);
您将获得如下所示的存储库:
{"group": {"list": ["value1", "value2", "value3"...]}}
从列表顶部弹出个元素:
let url = "https://store.zapier.com/api/records";
let headers = {
"Content-Type":"application/json",
"X-Secret": secret
}
body = {
"action":"list_pop",
"data":
{
"key":key,
"location":"head"
}
};
let options = {
"method": "PATCH",
"headers": headers,
"body": JSON.stringify(body)
}
let response = await fetch(url, options);
谢谢!