Using artifacts of another project

I have a project (A) which depends on another project (B).
When building project A I want to use the latest artifacts of project B to build.

I identified two solutions:

  1. Use needs:project `.gitlab-ci.yml` keyword reference | GitLab
  2. Use the API to download the artifacts

1. needs:project solution
I configured the needs correctly:

needs:
  - project: xy
    job: build_job
    ref: main
    artifacts: true

But in the running pipeline I saw that the job it was dependent on was the same job that was just triggered. Even though project xy is no the same project as this pipeline run at.

So I figured it must be a bug in Gitlab and tried solution 2.

2. Use API
I used /api/v4/projects/3/jobs/artifacts/main/download?job=build_job to download the artifacts.
It works when I use my personal access token with the PRIVATE_TOKEN header. But when I try it with JOB_TOKEN an CI_JOB_TOKEN it doesnt work.
I configured Token Access accordingly.

Any ideas here?
I’d prefer solution one, but two would work as well.

Versions:
GitLab self hosted: v16.0.7-ee
Runner: 16.0.2 shell powershell

needs:
  - project

is only available on paid plans/subscriptions. Do you have Premium or Ultimate sub?

The user running the pipeline must have at least the Reporter role for the group or project, or the group/project must have public visibility.

CI_JOB_TOKEN should have access to the other project if you as user have access there, check that job token permissions are not limited as described in docs

Thanks for your answer!

I missed that a license is needed for this feature. But I will get one and solve it this way.

I still cant get it to work with the CI_JOB_TOKEN. As I said it works with my personal access token. Which means my user has the correct rights. I also checked manually, I have maintainer everywhere.
I also configured Token Access on both of the projects so that the other project has access. Nothing worked.