I try to make a pull request from a private repositorie. I have set up a password on personal settings -> apps password and set every permission on. (I uses this for bitbucketApiToken )
This is the script below i used:
use Illuminate\Support\Facades\Http;
$bitbucketApiToken = 'your_bitbucket_api_token';
$pullRequestTitle = 'Your Pull Request Title';
$sourceBranch = 'source_branch_name';
$sourceRepositoryFullName = 'workspace/source_repository_slug';
$destinationBranch = 'destination_branch_name';
$destinationRepositorySlug = 'destination_repository_slug';
$response = Http::withToken($bitbucketApiToken) ->post("https://api.bitbucket.org/2.0/repositories/$destinationRepositorySlug/pullrequests", [ 'title' => $pullRequestTitle, 'source' => [ 'branch' => [ 'name' => $sourceBranch, ], 'repository' => [ 'full_name' => $sourceRepositoryFullName, ], ], 'destination' => [ 'branch' => [ 'name' => $destinationBranch, ], 'repository' => [ 'full_name' => $destinationRepositorySlug, ], ], ]);
$responseBody = $response->json();
I get the message: Token is invalid or not supported for this endpoint
Do you realize that you should assign a value to the variables (starting with '$') in the top of your script?
Their values in your your script are just placeholders.
$username = $encrypter->decryptString(env('BIT_USERNAME'));
$password = $encrypter->decryptString(env('BIT_PASSWORD'));
$repo = Str::lower($name);
$bitbucketApiToken = env('BIT_KEY');
$pullRequestTitle = 'Pull';
$sourceBranch = 'https://leeuwenkasteel@bitbucket.org/'.$username.'/'.$repo.'.git';
$sourceRepositoryFullName = $username.'/'.$repo;
$destinationBranch = base_path('Modules');
$destinationRepositorySlug = $repo;
I had already changed it
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
While I cannot know if all these are configured properly, I will assume they are, and the error message also suggests that your code cannot even authenticate.
This is the doc of the corresponding REST API endpoint: https://developer.atlassian.com/cloud/bitbucket/rest/api-group-pullrequests/#api-repositories-workspace-repo-slug-pullrequests-post
What I noticed is that the "Authorization" header is expected to be like this:
Authorization: Bearer <access_token>
I see that you are calling the "withToken" method and based on the documentation it should be correct.
So as next, if I were you I'd just try that request with Curl.
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.