What I’m trying to do
I created a user script roughly based on the Book and Movies scripts that asks the user for a PLace Name and UK postcode then sends that to a web API to get lat-long in JSON format that would go into the new template.
Things I have tried
I followed the macro examples and used this as my user script:
/**
* Truncated utility functions
* /
let QuickAdd;
/**
* User script that does the stuff
*
* @param {*} params
*/
module.exports = async (params) => {
QuickAdd = params;
// Get place name from user
let placeName = await QuickAdd.quickAddApi.inputPrompt("\ud83c\udfe0 Place name?");
// Get postcode name from user
let postCode = await QuickAdd.quickAddApi.inputPrompt("\ud83c\udfe0 Post Code?");
let query = encodeURIComponent(postCode);
const resultJson = await apiGet(query);
QuickAdd.variables = {
...resultJson.result[0],
title: placeName,
authors: "postcodes.io",
category: "Place",
region: resultJson.result[0].region,
lat: resultJson.result[0].latitude,
long: resultJson.result[0].longitude,
fileName: replaceIllegalFileNameCharactersInString(placeName),
};
console.log(QuickAdd.variables);
};
The macro calls the API and console logs the result showing it gets the data. But then I get asked for all the data variables I defined in the macro? See images:
Config page:
My Javascript is VERY rusty so I’m not sure if I misconfigured, missed, broke something or even discovered a bug.
Can anyone see any problems?