Can not create an organizational repository from a template with github API - github-api

I want to create an organizational repository with "internal" visibility (as it is the only way to create repositories in my org) in github but from a template.
So far I have been able to create an empty repository by doing the following: (note the option 'visibility: internal')
curl --location --request POST 'https://api.github.com/orgs/MYORGANIZATION/repos' \
--header 'Accept: application/vnd.github+json' \
--header 'Authorization: Bearer 123123' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "repo-by-github-api",
"description": "This is your first repository",
"visibility": "internal"
}'
This returns 201.
Now when creating a repository from a template: (note that there is no 'visibility: internal' option as it is not available)
curl --location --request POST 'https://api.github.com/repos/Louis3797/awesome-readme-template/generate' \
--header 'Accept: application/vnd.github+json' \
--header 'Authorization: Bearer 123123' \
--header 'Content-Type: application/json' \
--data-raw '{
"owner": "MYORGANIZATION",
"name": "repo-by-github-api",
"description": "This is your first repository"
}'
This returns 403 forbidden with a body that contains:
{
"message": "Forbidden",
"errors": [
{
...
"message": "MyGithubAccount123 cannot create a repository for MYORGANIZATION.",
...
}
The API token I'm using has all the permissions. I'm also following this documentation: https://docs.github.com/en/rest/repos/repos?apiVersion=2022-11-28#create-a-repository-using-a-template
What am I doing wrong? Is this a bug, as there is no way to configure the visibility option?

Related

Using Curl need to call a REST API

I am trying to generate a file using REST API by Header authorization "Bearer Token" and password encryption.
token=$(curl --header "Content-Type: application/json" --header "aesiv: xxxxxxxx" \
--request POST \
--data '{"login":"username","password":"encrypted_pswd"}' \
https://ssssss/api/login)
curl -X GET https://ssssss/api/generate-report -H "Accept: encryptionIntVeD" "Authorization: aesiv {xxxxxxxxxxx}" -H "Accept: application/json" -H "Authorization: Bearer {token}"
File not getting generated, can anyone guide me where I am stuck.

Passing a long JSON text to curl POST

I am referring to the thread: Passing a large text to bash curl url
I have a shell script that looks like:
#!bin/bash
curl --location --request POST 'example.com/abcxyz' \
--header 'Content-Type: application/json' \
--header 'Cookie: my_secret_key' \
--data-raw '{_my_very_long_json_content_here}'
Approach 1: I put everything after the curl, i.e. from --location ... to the end to a test.txt file then
tempfile = test.txt
curl "#$tempfile"
and I get the error curl: (6) Could not resolve host: test.txt
Approach 2: I put everything in a test.sh file:
#!bin/bash
curl --location --request POST 'example.com/abcxyz' --header 'Content-Type: application/json' --header 'Cookie: my_secret_key' --data-raw '#-' <<< 'my_very_long_json'
and I have an error {"error":"invalid character '#' looking for beginning of value","code":3}(base)
What should I do to pass a very long JSON content to curl POST?
Note that, if the JSON content is not too long, I can put everything in a SH file then run
bash test.sh
and it is okay.
--data-raw specifically disables # interpretation. Use --data #- or --data-binary #- to read from stdin.
curl --location --request POST 'example.com/abcxyz' \
--header 'Content-Type: application/json' \
--header 'Cookie: my_secret_key' \
--data #- <<< '{_my_very_long_json_content_here}'
You might find a heredoc more ergonomic than a long string:
curl --location --request POST 'example.com/abcxyz' \
--header 'Content-Type: application/json' \
--header 'Cookie: my_secret_key' \
--data #- <<'DATA'
{
'json': 'here'
}
DATA

How to chain curl such that the output of one become another's input?

Could someone tell me how to pass the output of one CURL GET to another CURL POST? I mean something like this:
curl --header "Content-Type: application/json" --request POST --data "{\"specification\": curl --header "Content-Type: application/json" --request GET "https://user:pass#anotherhost"}" "https://user:pass#localhost"
Use jq to craft JSON in the shell.
response="$(curl --header "Content-Type: application/json" --request GET "https://user:pass#anotherhost")"
data="$(jq "{specification: .}" <<< "$response")"
curl --header "Content-Type: application/json" --request POST --data "$data" "https://user:pass#localhost"
Keep in mind, that passwords in command line arguments are public to the host.
It looks like you need to use command substitution. The result would be something like this.
curl --header "Content-Type: application/json" --request POST --data "{\"specification\": $(curl --header "Content-Type: application/json" --request GET "https://user:pass#anotherhost")}" "https://user:pass#localhost"
$() is used for command substitution and it invokes a subshell. The command in the parentheses (a.k.a. round brackets) of $() is executed in a subshell and the output is then placed in the original command.
So the curl GET will be executed in a subshell and the result will be passed to the curl POST
You can read more about it at the link below:
https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html

What are the REST calls to import a CSV file into Shopware 6?

We saw https://developer.shopware.com/docs/guides/integrations-api but couldn't find a detailed documentation of the APIs.
EDIT: I found https://my-shop-host.example/api/v2/_info/swagger.html which describes all available APIs and import-export-file endpoints, but it is not clearly described how to use them (and which ones to use).
I believe we need to call (extracted from the admin panel work flow)
/api/v2/_action/import-export/prepare
and then
/api/v2/_action/import-export/process
to trigger an import.
But how are the files uploaded?
Is there an easier way, for example in one call?
I start with the authentication
curl 'http://example.com/api/oauth/token'\
-H 'Accept: pplication/vnd.api+json'\
-H 'Content-Type: application/json' \
--data '{
"grant_type": "client_credentials",
"client_id": "<my client ID from the integration>",
"client_secret": "<my secret>"
}' | jq .access_token
This returns and auth token which is valid for 10 minutes.
I store it to the variable $B
Next I upload the file and set the expiry date to 10 days in the future:
curl 'http://example.com/api/v2/_action/import-export/prepare' \
-H 'Accept: application/vnd.api+json' \
-H "Authorization: Bearer $B"
--form "file=#\"products.csv\"" --form "profileId=d4ec3999a33242a690ca5c213a7145cd" --form "expireDate=+10 days" | jq .log.id
This returns a log.id field
This field must be passed to the process call
curl 'http://example.com/api/v2/_action/import-export/process' \
-H 'Accept: application/vnd.api+json' \
-H 'Content-type: application/json' \
-H "Authorization: Bearer $B" --data '{"logId":"1410eaa1ca434744a8c211b60f65a3c5","offset":0}'
EDIT: Each chunk has to be triggered separately by using the last returned offset and pass it again to the process call.

I am very new to API. Please send me what -H mean?

curl -X POST https://api.commerce.coinbase.com/charges/ \
-H "Content-Type: application/json" \
-H "X-CC-Api-Key: YOUR_API_KEY" \
-H "X-CC-Version: 2018-03-22" \
-d "#data.json"
how do i make this api work?
-H attaches a header to your request. See manpage of curl.
The -H is adding a Header to the request so everything between the speech marks after the -H is a header.
Your CURL request has 3 headers.
See https://developer.mozilla.org/en-US/docs/Glossary/Request_header

Resources