Gitlab API curl request - api

When I'm trying to use GitLab API GET request to get all commits from specific date range and specific branch, I receive only commits from NEXT day after I put since date.
I mean, if I define since date for example - from 2022-12-01T12:17:30.000+02:00 until 2022-12-15T15:01:36.000+01:00. But, my commits from curl request starting from 2 Dec 2022.
How does to include initial date to response?
curl -s --header "PRIVATE-TOKEN: <token>" https://gitlab.example.com/api/v4/projects/ID/repository/commits"?ref_name=${branch}&since=${since_date}&until=${until_date}" | jq -r '.[] | .committed_date + "\t" + .title'
Response which I receive:
2022-12-15T15:01:36.000+01:00
2022-12-15T14:39:44.000+02:00
2022-12-14T08:26:43.000+02:00
2022-12-13T20:55:03.000+02:00
2022-12-13T15:51:34.000+01:00
2022-12-13T15:43:26.000+01:00
2022-12-12T16:50:49.000+01:00
2022-12-07T16:38:26.000+01:00
2022-12-05T22:41:04.000+01:00
2022-12-02T09:23:58.000+01:00
By the way, I tried to use, but it didn't help me.
?first_parent=true

It could be a pagination problem. Try adding &per_page=100 to see if there are more commits. I think you can't get more than 100 items in one api call.
See https://docs.gitlab.com/ee/api/#pagination for more info

Related

How to iterate over an array and use the values in a command in shell?

A Noob here. I am trying to call an API endpoint with curl to get list of (users) to use later in another subsequent API call with a while loop.
Curl request:
users=$(curl https://localhost/users/)
When I echo the response this is what I get?
["Jane","Joe","random","Person"]
How can I loop through all users in that array, to use them in subsequent API call?
Ps: I am using shell for this :)
How can I loop through all users in that array, to use them in subsequent API call?
If you have jq installed, you can use it to extract the users from the JSON array:
for user in `curl https://localhost/users/ | jq -r '.[]'`
do echo $user
done
Another variant, using tr:
for user in `curl https://localhost/users/ | tr '[",]' \ `
do echo $user
done

GitLab API: pipeline not returning all jobs

I'm using the GitLab api, to list out the jobs in a pipeline. It's always been fine in the past, but I've added a couple of extra items to the flow and now it doesn't return all of the jobs:
$ curl --globoff -sSH "$CURL_HEADER" https://.../api/v4/projects/$CI_PROJECT_ID/pipelines/$PIPEID/jobs?scope[]=success | jq --raw-output '.[] | "\(.id)"' | wc -l
20
The jobs that are missing aren't retries (as noted here).
I can see the missing jobids in the web interface.
Is there a maximum of 20 jobs via this method?
So turns out this API response is paginated, there's no indication in docs for this item.
There is a general item describing this here, but it doesn't give a list of routes it is related to. If it did it would probably show up in a search far easier.
All I needed to do was append &per_page=100 (qq-ing for the & for my use case). Alternatively you can check the return header for the X-Next-Page value and then append &page=X to get the subsequent pages...
Related page variables are:
x-next-page: 2
x-page: 1
x-per-page: 20
x-prev-page:
x-total: 23
x-total-pages: 2

Jira API not filtering on fields

I can't seem to get my request results to filter on the field pass. No matter what I input I get this massive data dump from Jira. Nor does it seem to limit by the maxResults count. Here's the API call:
curl -u app_jira_docs:"xxxxxxxxxx" --url 'https://jira.xxxxxxxxx.com/rest/api/2/search?jql=project=10506&"name"="epic"&"fields"="summary"&startAt=0&maxResults=2' -H "Content-Type: application/json" | jq '.' --sort-keys
Any help would be great.
I was able to get a similar query to filter correctly by swapping a few of your parameters around and adjusting some of the formatting:
curl --location --request GET 'https://jira-url/rest/api/latest/search?jql=project%3D10506%20AND%20name%3Depic&fields=summary&startAt=0&maxResults=2' --header 'Accept: application/json'
I grouped all of the JQL terms together, separated them with spaces and AND clauses, dropped the double-quoting around some of the parameters, and then URL encoded the whole thing.

Get Salesforce Product List and Data

Can I get salesforce product list using REST API? Or can you provide better and easier way to get product list. Please help. Thank You
Yes, Product2 records can be queried through the REST API. Here's a sample query:
curl -H 'X-PrettyPrint: 1' \
-H 'Authorization: Bearer ##Session_Id##' \
https://ap4.salesforce.com/services/data/v42.0/query?q=SELECT+Id+FROM+Product2

How to Display "title" and "displayvalue" from smart sheets using the cURL code shown below?

curl https://api.smartsheet.com/2.0/sheets/5848567060424580/columns/4140686686611332 -H "Authorization: Bearer 21txb6n2ajlf6dhsil8g3jxtdu"
^^^^That is the curl command i put into the terminal and when i do, i get this information poster below. The access token: 21txb6n2ajlf6dhsil8g3jxtdu & Sheet ID:5848567060424580. I want to get a curl command that only displays certain values instead of every single ID and formatting option in the columns from the Smartsheet. Any help would be useful thanks!
{"id":4140686686611332,"index":2,"title":"Column3","type":"TEXT_NUMBER","width":150}MAC-C02Q3C5MG8WP:~ jxs18$ curl https://api.smartsheet.com/2.0/sheets/584856724580 -H "Authorization: Bearer 21txb6n2ajlf6dhsil8g3jxtdu"
{"id":5848567060424580,"name":"JagTestSheet","version":1,"totalRowCount":3,"accessLevel":"EDITOR_SHARE","effectiveAttachmentOptions":["FILE","ONEDRIVE","GOOGLE_DRIVE","EVERNOTE","BOX_COM","EGNYTE","DROPBOX"],"ganttEnabled":false,"dependenciesEnabled":false,"resourceManagementEnabled":false,"cellImageUploadEnabled":true,"userSettings":{"criticalPathEnabled":false,"displaySummaryTasks":true},"permalink":"https://app.smartsheet.com/b/home?lx=PoM3LKb9HF6g_jsJ9JoWwg","createdAt":"2016-07-07T14:44:38Z","modifiedAt":"2016-07-07T15:22:53Z","columns":[{"id":1888886872926084,"index":0,"title":"Primary Column","type":"TEXT_NUMBER","primary":true,"width":150},{"id":6392486500296580,"index":1,"title":"Column2","type":"TEXT_NUMBER","width":150},{"id":4140686686611332,"index":2,"title":"Column3","type":"TEXT_NUMBER","width":150},{"id":8644286313981828,"index":3,"title":"Column4","type":"TEXT_NUMBER","width":150},{"id":481511989372804,"index":4,"title":"Column5","type":"TEXT_NUMBER","width":150},{"id":4985111616743300,"index":5,"title":"Column6","type":"TEXT_NUMBER","width":150}],"rows":[{"id":6858731183990660,"rowNumber":1,"expanded":true,"createdAt":"2016-07-07T15:22:53Z","modifiedAt":"2016-07-07T15:22:53Z","cells":[{"columnId":1888886872926084,"value":234.0,"displayValue":"234"},{"columnId":6392486500296580,"value":657.0,"displayValue":"657"},{"columnId":4140686686611332,"value":875.0,"displayValue":"875"},{"columnId":8644286313981828},{"columnId":481511989372804},{"columnId":4985111616743300}]},{"id":1229231649777540,"rowNumber":2,"siblingId":6858731183990660,"expanded":true,"createdAt":"2016-07-07T15:22:53Z","modifiedAt":"2016-07-07T15:22:53Z","cells":[{"columnId":1888886872926084,"value":564.0,"displayValue":"564"},{"columnId":6392486500296580,"value":546.0,"displayValue":"546"},{"columnId":4140686686611332,"value":453.0,"displayValue":"453"},{"columnId":8644286313981828},{"columnId":48151198937280MAC-C02Q3C5MG8WP:
You could consider piping the output into something like jsawk
to query the JSON response for what you are looking for from your cURL request.