Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Laravel: Token is invalid or not supported for this endpoint

Deleted user July 5, 2023

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

 

1 answer

0 votes
Aron Gombas _Midori_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 5, 2023

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.

Deleted user July 5, 2023

$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

Aron Gombas _Midori_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 5, 2023

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. 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events