I'm developing a headless Forge app (id is ari:cloud:ecosystem::app/e2584630-808f-4334-b7af-6ae832fdbacc) that serves as a serverless endpoint to interact with the Bitbucket API. The app's purpose is to update design tokens in a specific repository. It doesn't have a UI component; instead, it's designed to be triggered externally and perform operations directly on the repository.
Key characteristics of my app:
I'm encountering persistent issues with my Bitbucket API calls, receiving INVALID_TARGET_URL and 400 errors. Here's my current setup:
import api, { route } from "@forge/api";
const WORKSPACE = 'my-workspace';
const REPO_SLUG = 'my-repo';
const BRANCH = 'main';
const FILE_PATH = 'input/design-tokens.json';
export const designTokensHandler = async (req, context) => {
// ... (request parsing code) ...
try {
// Get the current file (if it exists)
const getFileUrl = route`/2.0/repositories/${WORKSPACE}/${REPO_SLUG}/src/${BRANCH}/${FILE_PATH}`;
let currentFile;
try {
const response = await api.asApp().requestBitbucket(getFileUrl);
if (response.status === 200) {
currentFile = await response.json();
}
} catch (error) {
console.log('Error fetching current file:', error);
if (error.response && error.response.status !== 404) throw error;
}
// Prepare the commit
const message = commitMessage || 'Update design tokens';
// Create or update the file
const updateFileUrl = route`/2.0/repositories/${WORKSPACE}/${REPO_SLUG}/src`;
const response = await api.asApp().requestBitbucket(
updateFileUrl,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
message: message,
branch: BRANCH,
files: [
{
path: FILE_PATH,
contents: JSON.stringify(parsedTokens, null, 2)
}
],
...(currentFile && { parents: [currentFile.commit.hash] })
})
}
);
if (!response.ok) {
const errorBody = await response.text();
throw new Error(`HTTP error! status: ${response.status}, body: ${errorBody}`);
}
// ... (success response handling) ...
} catch (error) {
console.error('Error updating design tokens:', error);
// ... (error response handling) ...
}
};
My manifest.yml
includes:
modules:
webtrigger:
- key: design-tokens-trigger
function: designTokensHandler
permissions:
scopes:
- read:repository:bitbucket
- write:repository:bitbucket
I've tried:
route
template literalDespite these attempts, I'm still receiving errors. Initially, I got "Disallowing path manipulation attempt" errors. After addressing those by hardcoding the URLs, I'm now getting 400 Bad Request errors.
Questions:
Any help or guidance would be greatly appreciated. Thank you!
@Clay Bailey You can't just call an arbitrary external URL from your Forge layer.
What you should examine here is Forge Remote, because it seems to me that it fits the architecture you are trying to build (Forge with an external AWS backend) very well.
Howdy @Clay Bailey
Best to ask this type of question the the Developer's Community in the Forge section.
Make sure to add the following information to your question:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.