When sending a request to Chainlink Functions 'DON' from a functions consumer contract, my transaction is successful and the subscription is charged, however I do not receive the data requested from the API. When reviewing the subscription manager 'Recent Fulfillments' the status of the fulfilment is 'Fulfilled with error'.
It also appears that the API call is not being made by the DON, there are no new API calls registered at the API end.
I have tried reducing the gas usage on the returning contract, this did not work. I expected this was not the problem due to the fact that I have this same contract working on the original BETA version of Chainlink Functions contracts from about 6 months ago.
I have encoded the secret API key as per instructions using the secrets manager and also the source code is correct.
Below Links to the subscription and verified contract.
Chainlink Functions Subscription
Functions Consumer contract on Polygonscan Mumbai
JS script for the functions request:
const plot = args[0];
var verifiedString = "";
var regex = /^\/{0,}(?:[^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+|[^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+([\u0020\u00A0][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+){1,3}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+([\u0020\u00A0][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+){1,3}[.。。・・︒។։။۔።।][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+([\u0020\u00A0][^0-9`~!@#$%^&*()+\-_=[{\]}\\|'<,.>?/";:£§º©®\s]+){1,3})$/;
if (plot.length > 64) {
throw Error(`Request Failed: Too many characters in request`)
}
// Check for regular expressions
if (!regex.test(plot)) {
throw Error(`Request Failed: Not a correctly formatted plot name`)
}
// build HTTP request objects
// API call to GET the words address location info using the supplied words address in any language.
// If the supplied words address is incorrect the API will revert with an error.
const request = Functions.makeHttpRequest({
url: `https://api.what3words.com/v3/convert-to-coordinates`,
headers: { "X-Api-Key": secrets.apiKey },
params: {
words: plot,
},
})
// Wait for all requests to finish
const response = await request;
// Verify if there are any errors in responses
if (response.error || response.Response === "Error") {
throw Error(`Request Failed: Code: ${response.code} Message: ${response.message}`);
}
else if (response["data"]["language"] != "en") {
const lat = response["data"]["coordinates"]["lat"]
const lng = response["data"]["coordinates"]["lng"]
const coordinates = `${lat},${lng}`
const enRequest = Functions.makeHttpRequest({
url: `https://api.what3words.com/v3/convert-to-3wa`,
// Get a free API key from https://accounts.what3words.com/create-api-key/
headers: { "X-Api-Key": secrets.apiKey },
params: {
coordinates: coordinates,
language: "en",
},
})
const enResponse = await enRequest;
if (enResponse.error || enResponse.Response === "Error") {
throw Error(`Request Failed: Code: ${enResponse.code} Message: ${enResponse.message}`);
}
else if (enResponse["data"]["language"] != "en") {
throw Error(`Request Failed: Code: 400 Message: BadLanguage`);
}
else {
verifiedString = enResponse.data.words;
}
}
else {
verifiedString = response.data.words;
}
// throw an error if verifiedString is empty
if (verifiedString.length == 0) {
throw Error(`Request Failed: API result empty.`)
}
return Functions.encodeString(`${verifiedString}`)