INVALID_TARGET_URL when trying to get bitbucket user

I am trying to create my first Forge app. I use UI kit to offer a settings page which uses UserPicker to select a group of users, which returns account IDs. As other bitbucket REST APIs (for example the author field of /repositories/{workspace}/{repo_slug}/pullrequests/{pull_request_id}) do not include that, but only a uuid and I need to compare authors, I am trying to map the account ID to a UUID or vice-versa.

In the resolver of my app, I thus have this simple function:

const getUUID = async (id: AccountID): Promise<void | UUID> => {
	return api.asApp().requestBitbucket(route`/2.0/users/${id}`)
		.then((r) => r.json())
		.then((u: User) => u.uuid);
};

However, trying to use it throws an INVALID_TARGET_URL exception. I’ve tried logging the route including the id. If I use that to send a request using curl, it works as expected and returns the user data I am interested in.

I thought I might be missing permissions, but it seems that endpoint is just publicly readable.

What am I doing wrong?

I figured out what I was doing wrong. As the request does not require authentication, I need to remove the asApp(). This works as expected:

const getUUID = async (id: AccountID): Promise<undefined | UUID> => {
	return api.requestBitbucket(route`/2.0/users/${id}`)
		.then((r) => r.json())
		.then((u: User) => u ? u.uuid.slice(1,-1) as UUID : undefined);
};

The error message is pretty confusing. But at least my problem is solved now.

1 Like