404 Not Found on Github API using github.rest.git.createRef - github

I use the following code inside a Github Action workflow file:
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/heads/' + '${{ github.event.inputs.combineBranchName }}',
sha: baseBranchSHA
});
The code results into a 404 :
RequestError [HttpError]: Not Found
at /home/runner/work/_actions/actions/github-script/v6/dist/index.js:6173:21
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async eval (eval at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:13340:16), <anonymous>:71:3)
at async main (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:13436:20) {
status: 404,
response: {
url: 'https://api.github.com/repos/myusername/myrepo/git/refs',
status: 404,
headers: {
...
},
data: {
message: 'Not Found',
documentation_url: 'https://docs.github.com/rest/reference/git#create-a-reference'
}
},
request: {
method: 'POST',
url: 'https://api.github.com/repos/myusername/myrepo/git/refs',
headers: {
accept: 'application/vnd.github.-preview+json',
'user-agent': 'actions/github-script octokit-core.js/3.6.0 Node.js/16.13.0 (linux; x64)',
authorization: 'token [REDACTED]',
'content-type': 'application/json; charset=utf-8'
},
body: '{"ref":"refs/heads/combined-prs-branch","sha":"a3167bb784fa5d045bbad57545a7a96c5d89be4f"}',
request: { agent: [Agent], hook: [Function: bound bound register] }
}
}
I'm using a PAT that has access to public repo.
I went from 403 error with GITHUB_TOKEN to 404 with PAT_TOKEN.
So I guess I solved the permission issue but why is it 404 now ?
I can access the URL https://api.github.com/repos/myusername/myrepo/git/refs in a browser.

Related

Flutter http with authorisation: ClientException (Failed to parse header value)

I have an API that expects a JWT token.
I tested the API with https://hoppscotch.io, here is the query that returns the expected results (no error)
import axios from "axios";
const options = {
method: 'POST',
url: 'https://my_authority/text-message',
headers: {
Authorization: 'Bearer my_token',
'content-type': 'application/json'
},
data: {message: ''}
};
axios.request(options).then(function (response) {
console.log(response.data);
}).catch(function (error) {
console.error(error);
});
And here is the code in Dart that fires the error ClientException (Failed to parse header value):
await http.post(
Uri.parse('$_httpEndpoint/$path'),
headers: {
HttpHeaders.contentTypeHeader: 'application/json',
HttpHeaders.authorizationHeader: 'Bearer my_token',
},
body: jsonEncode(body));
Both queries have the same parameters. I have no clue about the root causes.
Here is requests.headers in locals for IOClient.send when the error fires:
_CompactLinkedCustomHashMap ({content-type: application/json; charset=utf-8, authorization: Bearer my_token})
I don't know why http adds charset=utf-8, and I didn't manage to remove it.
I looked over the internet and didn't find an answer. Most of the similar questions are related to an error in the backend, it is not the case here.

Creating new document with Firestore REST API and Local Emulator Suite for Integration Test, Returning Error 400: Problem with Request Body?

I recently posted a question regarding creating a document in a collection in the local emulator suite using a HTTP Post Request with Axios.
Creating new document with Firestore REST API and Local Emulator Suite, Returning Error 404: Problem with Path Parameter
My previous error was a 404 error with the URL path parameter. Since making changes to that, now I’m receiving a 400 error. The following is the code:
First, using a post request to create an authenticated user ID token and storing that in a variable. No issues here.
//HTTP Post Request to create an auth ID, storing ID Token in variable
const createUserResponse = await axios.post(createUserInstance.url, createUserInstance.data, createUserInstance.config);
const userIdToken = createUserResponse.data.idToken;
const userLocalId = createUserResponse.data.localId;
console.log(userIdToken);
console.log(userLocalId);
Second, writing the request body. I’ve modified the URL which works now. I’ve also re-modified the data body to make sure it’s in the correct format.
Wondering if the issue is in:
the way I’ve written the query parameters (do I need to specific the new document name? is the API key the problem?)
the formatting of the data request body : according to the documentation a new document is automatically generated. I’d presume fields would be read as containing the key-value pairs to include in the document fields.
the formatting of the headers. I’ve checked and re-checked this. My userIDToken contains a string
//create a document in the user collection
//request body
const createDocumentInstance : createPostRequest = {
url: 'http://localhost:8080/v1beta1/projects/okane-crud-dev/databases/(default)/documents/test?key=<API_KEY>',
data: {
'fields': {
'localId': 'hello',
}
},
//directly pasted IdToken as using the variable resulted in problem with ' ' error
config: {
'headers':
{
'Content-Type': 'application/json',
'Authorization': `Bearer ${userIdToken}`,
}
}};
To make sure of what I was looking at, I logged the entire request in my console. This is what it looks like.
console.log
{
url: 'http://localhost:8080/v1beta1/projects/okane-crud-dev/databases/(default)/documents/test?key=AIzaSyCQSnirvajGL5Uok34OgEn7tF1S_tp5sa0',
data: { fields: { localId: 'hello' } },
config: {
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJlbWFpbCI6Im15ZW1haWxAZW1haWwuY29tIiwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJhdXRoX3RpbWUiOjE2NjU0NTQ2MDgsInVzZXJfaWQiOiI1Vmt3TUtRc1k0THJRTkRWaXpFYmdnYnExOVNyIiwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6eyJlbWFpbCI6WyJteWVtYWlsQGVtYWlsLmNvbSJdfSwic2lnbl9pbl9wcm92aWRlciI6InBhc3N3b3JkIn0sImlhdCI6MTY2NTQ1NDYwOCwiZXhwIjoxNjY1NDU4MjA4LCJhdWQiOiJva2FuZS1jcnVkLWRldiIsImlzcyI6Imh0dHBzOi8vc2VjdXJldG9rZW4uZ29vZ2xlLmNvbS9va2FuZS1jcnVkLWRldiIsInN1YiI6IjVWa3dNS1FzWTRMclFORFZpekViZ2dicTE5U3IifQ.'
}
}
}
Finally, making the post request on Axios. Exact same syntax as my previous post request.
//Post Request to create a document
const createDocument = await axios.post(createDocumentInstance.url, createDocumentInstance.data, createDocumentInstance.config);
const docReference = createDocument.data;
console.log(docReference);
When running this, the following error is returned:
{
message: 'Request failed with status code 400',
name: 'Error',
description: undefined,
number: undefined,
fileName: undefined,
lineNumber: undefined,
columnNumber: undefined,
stack: 'Error: Request failed with status code 400\n' +
' at createError (/Users/georgettekoo/Documents/Code/Okane/Okane-Firebase-Backend-Deprecated/functions/node_modules/axios/lib/core/createError.js:16:15)\n' +
' at settle (/Users/georgettekoo/Documents/Code/Okane/Okane-Firebase-Backend-Deprecated/functions/node_modules/axios/lib/core/settle.js:17:12)\n' +
' at IncomingMessage.handleStreamEnd (/Users/georgettekoo/Documents/Code/Okane/Okane-Firebase-Backend-Deprecated/functions/node_modules/axios/lib/adapters/http.js:293:11)\n' +
' at IncomingMessage.emit (node:events:539:35)\n' +
' at endReadableNT (node:internal/streams/readable:1344:12)\n' +
' at processTicksAndRejections (node:internal/process/task_queues:82:21)',
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
adapter: [Function: httpAdapter],
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 0,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
validateStatus: [Function: validateStatus],
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
Authorization: 'Bearer eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJlbWFpbCI6Im15ZW1haWxAZW1haWwuY29tIiwiZW1haWxfdmVyaWZpZWQiOmZhbHNlLCJhdXRoX3RpbWUiOjE2NjU2MzAwMTUsInVzZXJfaWQiOiJEMTBoblpsek9nQWR0ZlJlNm1VUDBOY2ZtNm5pIiwiZmlyZWJhc2UiOnsiaWRlbnRpdGllcyI6eyJlbWFpbCI6WyJteWVtYWlsQGVtYWlsLmNvbSJdfSwic2lnbl9pbl9wcm92aWRlciI6InBhc3N3b3JkIn0sImlhdCI6MTY2NTYzMDAxNSwiZXhwIjoxNjY1NjMzNjE1LCJhdWQiOiJva2FuZS1jcnVkLWRldiIsImlzcyI6Imh0dHBzOi8vc2VjdXJldG9rZW4uZ29vZ2xlLmNvbS9va2FuZS1jcnVkLWRldiIsInN1YiI6IkQxMGhuWmx6T2dBZHRmUmU2bVVQME5jZm02bmkifQ.',
'User-Agent': 'axios/0.24.0',
'Content-Length': 30
},
method: 'post',
url: 'http://localhost:8080/v1beta1/projects/okane-crud-dev/databases/(default)/documents/test?key=AIzaSyCQSnirvajGL5Uok34OgEn7tF1S_tp5sa0',
data: '{"fields":{"localId":"hello"}}'
},
code: undefined,
status: 400
}
Not sure what I'm missing and where the issue is. Does anyone have any hints?

Why the server responded with a status of 400

I am trying to create a sharepoint list using REST call. But i am getting error message: 'The server responded with a status of 400.'
Below is my code. Not able to understand where I am doing mistake:
url: https://abcTest.sharepoint.com/sites/dev/_api/web/lists.
digest: I am getting from a different function call.
const response = await fetch(url, {
method: 'POST',
credentials: 'include',
headers: {
'Accept': 'application/json;odata=verbose',
'Content-Type': 'application/json;odata=nometadata',
'X-RequestDigest': digest
},
body: JSON.stringify({
__metadata: {
type: 'SP.List`
},
AllowContentTyes: true,
BaseTemplate: 100,
ContentTypesEnabled: true,
Description: 'List description',
Title: 'MyList'
})
});
I think you should change
Accept: 'application/json;odata=verbose'
===> 'Accept': 'application/json;odata=verbose'
And : method: 'POST'` ===> method: 'POST'
Make sure parameter is json data.

Fork repository on github through GitHub REST API

How could I make request through GitHub REST API? I have id, generated secret and toket with access to repository, but HOW to make request (correct url or so on) to Fork selected repository?
What I did:
const forkRepository = await fetch("https://api.github.com/repos/dd/controlp5/forks", {
method: 'POST',
headers: {
'Authorization': 2733364296c2b40e2c4088cade1ffc9cc758dbf8,
'Content-Type': 'application/json'
}
});
return forkRepository;
And I took this
Response {type: "cors", url: "https://api.github.com/repos/dd/controlp5/forks", redirected: false, status: 401, ok: false, …}
body: ReadableStream
locked: (...)
__proto__: Object
bodyUsed: false
headers: Headers
__proto__: Headers
ok: false
redirected: false
status: 401
statusText: "Unauthorized"
type: "cors"
url: "https://api.github.com/repos/dd/controlp5/forks"
__proto__: Response
And the last what i need understand, what token I need to use and how could I take it? Because my acces token doesn't work to fork.
URI to fork a repository:
POST https://api.github.com/repos/:owner/:repo/forks
:owner replaces the owner and :repo the Repository name.
For example, here's a repository forking germanysources/FOSSwareSearch:
POST https://api.github.com/repos/germanysources/FOSSwareSearch/forks
The github documentation can be found at:
https://developer.github.com/v3/repos/forks/

Creating JIRA issue through angular form

Trying to create an issue from angularjs using rest api throwing 403 forbidden error. New to this, any help would be appreciated.
error:
Response to preflight request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost:8080' is therefore not allowed
access. The response had HTTP status code 403.
$http({
method: "POST",
url: 'https://jira.ab.com/rest/api/2/search',
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " +
btoa('abc#ab.com' + ":" + '***'));
},
headers: {
'Content-Type': 'application/json'
},
data: JSON.stringify({
jql: {
project: "JQR",
maxResults: 20,
}
})
}).then(function successCallback(response) {
return response.data;
}, function errorCallback() {
console.log("Error calling API")
});