Trouble with GET in script

I’m dipping my toe into scripting in automations and I’m having trouble with a simple script. I can’t seem to get a response even though the script works fine in postman. What am I doing wrong?

const http = context.getService(‘http’);

try {
// GET request to auth endpoint
const response = await http.getAsync(‘https://readwise.io/api/v2/auth/’, {
headers: {
‘Authorization’: ‘Token XXX’
}
});

// Throw an error with the response status to check if the request was successful
throw new Error("Readwise API response status: " + response.status);

} catch (error) {
// If there’s an error, throw it to display in the Fibery app
throw new Error(error);
}

Here’s the error: Failed to execute Action “Script”: Error: Readwise API response status: undefined

Don’t tell everyone, but we will shortly release a readwise integration :wink:

2 Likes

:eyes::eyes::eyes: :star_struck:

In the meantime, any advice on what I’m doing wrong? For my other projects.

Basic script debugging tip: Start by creating a BUTTON for your script, because you’ll be able to see console.log outputs in your browser’s DevTools console.

When it’s working, move it to a Rule.