How to edit a github issue using the API (curl)? (especially: close) - api

I'm planning to migrate a couple hundred bugs tracked in another (home-rolled) system into GitHub's issue system. Most of these bugs were closed in the past. I can use github's API to create an issue, e.g.
curl -u $GITHUB_TOKEN:x-oauth-basic https://api.github.com/repos/my_organization/my_repo/issues -d '{
"title": "test",
"body": "the body"
}'
... however, this will leave me with a bunch of open issues. How to close those? I've tried just closing at the time of creation, e.g.:
curl -u $GITHUB_TOKEN:x-oauth-basic https://api.github.com/repos/my_organization/my_repo/issues -d '{
"title": "test",
"body": "the body",
"state": "closed"
}'
... but the result is to create an open issue (i.e. the "state" is ignored).
It looks to me like I should be able to "edit" an issue to close it (https://developer.github.com/v3/issues/#edit-an-issue) ... but I'm unable to figure out what the corresponding curl command is supposed to look like. Any guidance?
Extra credit: I'd really like to be able to assign a "closed" date, to agree with the actual closed date captured in our current system. It's not clear that this is possible.
Thanks!

migrating a bunch of issues to github with the command line? are you crazy?
anyway, using php and hhb_curl from https://github.com/divinity76/hhb_.inc.php/blob/master/hhb_.inc.php ,
this worked for me, unfortunately couldn't set the "closed_at" date (it was ignored by the api), but i could emulate it using labels, then it looked like
, the code should give you something to work on when porting it to command line:
<?php
declare(strict_types = 1);
require_once ('hhb_.inc.php');
$hc=new hhb_curl();
define('BASE_URL','https://api.github.com');
$hc->_setComfortableOptions();
$data=array(
'state'=>'closed',
'closed_at'=> '2011-04-22T13:33:48Z',// << unfortunately, ignored
'labels'=>array(
'closed at 2011-04-22T13:33:48Z' // << we can fake it using labels...
)
);
$data=json_encode($data);
$hc->setopt_array(array(
CURLOPT_CUSTOMREQUEST=>'PATCH',
// /repos/:owner/:repo/issues/:number
// https://github.com/divinity76/GitHubCrashTest/issues/1
CURLOPT_URL=>BASE_URL.'/repos/divinity76/GitHubCrashTest/issues/1',
CURLOPT_USERAGENT=>'test',
CURLOPT_HTTPHEADER=>array(
'Accept: application/vnd.github.v3+json',
'Content-Type: application/json',
'Authorization: token <removed>'
),
CURLOPT_POSTFIELDS=>$data,
));
$hc->exec();
hhb_var_dump($hc->getStdErr(),$hc->getResponseBody());
(i modified the "Authorization: token" line before posting it on stackoverflow ofc)

As suggested by hanshenrik, the correct altered curl command is:
curl -u $GITHUB_TOKEN:x-oauth-basic https://api.github.com/repos/my_organization/my_repo/issues/5 -d '{
"state": "closed"
}'
I'd failed to understand the documentation referenced in his answer:
/repos/:owner/:repo/issues/:number
translates to
https://api.github.com/repos/my_organization/my_repo/issues/5
(I now understand that fields starting with ":" are variables)
For the record, I'm planning to script the calls to curl. :)

Related

twitter api v2 to capture random sample of a specific language

I can't believe this is not a common/often considered query to the twitter v2 API
We are looking for a sample of tweets in a specific language (we're testing language translation tech) e.g. english or spanish.
There exists a sample end point, there exists a search query end point, however
sample endpoint doesn't seem to allow to attach a query. The search query doesn't seem to allow an 'empty search string', on which can add the language specifier
we've tried things like (as no real clues in the docs, so these do fail as expected)
curl --request GET 'https://api.twitter.com/2/tweets/sample/stream?lang:en'
curl --request GET 'https://api.twitter.com/2/tweets/search/recent?query=lang:en'
curl -X POST 'https://api.twitter.com/2/tweets/search/stream/rules' \
-H "Content-type: application/json" \
-H "Authorization: Bearer <TOKEN>" -d \
'{
"add": [
{"value": " lang:en"}
]
}'
and also things like
"'{
"add": [
{"value": "from: * lang:en"}
]
}'
we could query the sample, include the language field and then dismiss all we are not interested in, but given we need large volumes, this will waste quotas.
Anyone accomplished this?

How to create a elasticsearch document document via URL(http)

I am new to elasticsearch and trying to find a way to create a document from url(http-API). I have tried below given options but none of them worked.
http://Myserver:9200/dilbert/user/3 -d '{ "name" : "Praveena" }
http://Myserver:9200/dilbert/user/3{ "name" : "Praveena" }
http://Myserver:9200/dilbert/user/3?pretty _create name=Praveena
I expect this to add a record. Here dilbert is Index name. user is type & 3 is id. This index only contains a single element called name.
First option should work, but you must explicitly set request type to PUT.
It seems to me that you use curl to insert data. If you send data to server with -d option, curl issues the POST request by default. But you specify id of document in URL, so Elasticsearch waits for PUT request (see official documentation). You can use POST requests only in case of automatic ID generation.
So your request may look as follows:
curl -X PUT http://Myserver:9200/dilbert/user/3 -d '{ "name" : "Praveena" }'

wit.ai HTTP Post/entities API not show expressions in "Keyword" search strategy

I try to post Intent and entity via wit.ai HTTP API.
My JSON format:
{"entities"=>[{"id"=>"intent", "lookups"=>["trait"], "values"=> [{"value"=>"ask_info", "expressions"=>["How old are you ?"]}]}, {"id"=>"age", "values"=>[{"value"=>"old", "expressions"=>["How old are you ?"]}]}]}
Input sentence is "How old are you ?"
Intent is ask_info
Entity is age for value 'old'
I call post entitiles API twice for Intent and Entity
$ curl -XPOST 'https://api.wit.ai/entities?v=20160526' \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"id"=>"intent", "lookups"=>["trait"], "values"=> [{"value"=>"ask_info", "expressions"=>["How old are you ?"]}]}'
$ curl -XPOST 'https://api.wit.ai/entities?v=20160526' \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"id"=>"age", "values"=>[{"value"=>"old", "expressions"=>["How old are you ?"]}]}'
In wit.ai page, entity age not mapping to expression "How old are you ?".
Just display in Synonyms
Display Image
Downloaded Dataset only show intent no entity
{
"text" : "How old are you ?",
"entities" : [
{
"entity" : "intent",
"value" : "\"ask_info\""
}
]
}
wit.ai GUI work very nice
{
"text" : "How old are you ?",
"entities" : [
{
"entity" : "intent",
"value" : "\"ask_info\""
},
{
"entity" : "age",
"value" : "\"old\"",
"start" : 2,
"end" : 3
}
]
}
Do you have any method could solve this problem?
I've bypassed this bug by manually crafting an archive which I later used for deploy.
There are multiple issues with this approach:
Apps cannot be updated from an archive, the importer only supports creating new apps as far as I know. This means the history will be lost between deploys and the server token will need to be changed.
The importer seems to be a little flaky. Tampering with the archive is possible, but zipping back is complicated: all files should be in an directory, no directory entries should be present, and the file order also seems to be important.
The upside is multiple features that are not available in the API are exposed, such as setting the 'free-text' lookups option.
I've downloaded an sample application and proceeded from there.

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.

Parse geo-queries always empty

Im currently trying to get Parse's geo-query system to work. On my data browser, I have an installation with a key "location" of type geo-point that has a geo-point with latitude 30.27263636013176 and longitude -97.75766807716373 set in it.
However, if I try to query with the following code, I always get "results":[].
curl -X GET \
-H "X-Parse-Application-Id: myAppKey" \
-H "X-Parse-REST-API-Key: myAPIKey" \
-G \ --data-urlencode 'limit=10' \
--data-urlencode 'where={
"location": {
"$nearSphere": {
"__type": "GeoPoint",
"latitude": 30,
"longitude": -97
}
}
}' \
https://api.parse.com/1/classes/PlaceObject
Note that the query is running successfully; there are no errors. The problem is the installation I have should come up.
If I change the latitude and longitude in the query to exactly the latitude and longitude shown in the data browser, I still get empty results. What is the reason for this? Is it not possible to query for device installations near a point?
The Installation class can't be queried from the client, for good reason. Too much sensitive information is stored in the Installation class to allow querying from a client.
Either move the location property to another class you can query, or query it in a Cloud Function.
You can query it in Cloud Code if you use Parse.Cloud.useMasterKey();, though I strongly recommend using a different class to store the location.
Should the url be https://api.parse.com/1/classes/Installation instead of https://api.parse.com/1/classes/PlaceObject ?