Adding comment to a JIRA issue ticket using REST API in R - r

I would like to add more comments to an existing JIRA ticket using REST API pro grammatically from R
I tried the following based on this link in this forum but did not work:
library(httr)
POST("https://xxxxxx.atlassian.net/rest/api/2/issue/issueId/comment",body = "New Comment", authenticate(userid,password, "basic"))

I checked the accepted answer in your forum link, which suggests the following POST using curl:
curl -u admin:admin -X POST --data '{"body": "comment."}' -H "Content-type: application/json" http://localhost:2990/jira/rest/api/2/issue/TEST-1/comment
Note carefully that the body is JSON content, with the content type also being set as JSON. You may try doing the same in your call to the POST() function from httr:
POST("https://xxxxxx.atlassian.net/rest/api/2/issue/issueId/comment",
body = '{"body": "comment."}', authenticate(userid, password, "basic"),
encode="raw")

Related

How to send a file in a url via curl?

I have an image in a URL like https://i.postimg.cc/GpDskmSG/sdssds.png and I want to send it over to be stored at nft.storage. Could I send it directly as a URL instead of a file from a path? I tried the below but it only stores the image URL.
curl -H "Authorization: Bearer eyJhbGciOiJIwetertyrtyUzI1NiIsInR5cCI6Ikp" -H "Content-Type: image/png" --data "https://i.postimg.cc/GpDskmSG/sdssds.png" --url "https://api.nft.storage/upload"
P/S: I'm testing on windows curl.
According to the API docs (https://nft.storage/api-docs/), it will accept multipart/form-data for this type of POST.
You can try using -F/--form instead, for which a good example exists on the curl man page (https://linux.die.net/man/1/curl):
curl -F "web=#index.html;type=text/html" url.com

Error when I POST JSON data to wordpress site

My command is:
curl -X POST --user "admin:admin" https://website.com/wp-json/wp/v2/posts/ -H "Content-Type: application/json" -d {"title":"test","content":"Content","status":"draft"}
The response I get:
{"code":"rest_invalid_json","message":"Invalid JSON body passed.","data":{"status":400,"json_error_code":4,"json_error_message":"Syntax error"}}
Thanks!
From my earlier comments, I have the feeling that this error is related to the -d possibly needing to have quotes around the data text.
So in your case, it might be worth trying to put single quotes around the -d data text because you are currently using double quotes in the json text.
Thus, your curl command might look like this:
curl -X POST --user "admin:admin" https://website.com/wp-json/wp/v2/posts/ -H "Content-Type: application/json" -d '{"title":"test","content":"Content","status":"draft"}'
This is based on how the curl docs appear to show that quotes should be used with -d related data text based on the example under the "POST (HTTP)" section of the curl documentation here. I think this is what I have done in the past, as well, but I don't have a specific personal example on me at the moment.
Update
For what it's worth, when I tried running this curl type of command on my own, I got the following error when I didn't use single quotes around the json text:
{"code":"rest_invalid_json","message":"Invalid JSON body passed.","data":{"status":400,"json_error_code":4,"json_error_message":"Syntax error"}}curl: (3) Port number ended with 'C' curl: (3) Port number ended with 'd'
When I ran the command with single quotes around the json data, like this: -d '{"title":"test","content":"Content","status":"draft"}', the command worked and a draft was added in WordPress. I also received back a json response that looks related to the new draft post.
Another thing to check might be the credentials used with the --user part. I ended up having to use an "Application Password" that I generated for a user in my WordPress account. This is different than my user's login password. If you haven't already tried using an "Application Password" in WordPress for this part, it might be worth trying to see if that fixes your issue. I found this when I:
Logged into my WordPress website
Clicked on the Users menu item
Clicked on a user
Scrolled down to the bottom of the user info page
Clicked on the Add New Application Password button
Ok, this was a windows specific problem, I guess most people out there are running unix/linux clients so this doesn't apply to them. I found the solution here: https://stackoverflow.com/a/7173011/15161479
The issue is with curl on windows, the quotes need to be escaped. I also did a couple other things like installing the "Application Passwords" plugin.
This is what my command looks like now
curl --user "user:application password" http://website.com/wp-json/wp/v2/posts/ -H "Content-Type: application/json" --data "{"""title""":"""test""","""content""":"""Content""","""status""":"""draft"""}"
Hope this helps some other people out there!

Accessing datasets for AutoML Vision API

I have found GET request url for getting datasets from documentation https://cloud.google.com/vision/automl/docs/reference/rest/ as below:
https://automl.googleapis.com/v1beta1/Concreting (Concreting is dataset name)
In response I am getting 404 file not found error so there is something missing in url.
can you please provide me correct documentation link which I should refer?
{name} needs to be the fully qualified identifier of the dataset in format projects/{project-id}/locations/us-central1/datasets/{dataset-id}.
Dataset IDs are not unique across projects so you need to specify your Project ID in the REST endpoint URL.
You can find an example in the docs using the analogous DELETE method.
In your case, this should be something like:
projectId=$(gcloud config get-value project)
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://automl.googleapis.com/v1beta1/projects/$projectId/locations/us-central1/datasets/Concreting

Unable to upload to Watson Analytics data with R

I have the following code:
curl -v -X PUT -H "X-IBM-Client-Id:YOUR_CLIENT_ID" -H "X-IBM-Client-Secret:YOUR_CLIENT_SECRET" -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -H "Content-Type:text/csv" https://api.ibm.com/watsonanalytics/run/data/v1/datasets/ID_OF_DATA_SET/content -d "YOUR_DATA"
That code is the example they gave me in order to upload data, when I try to translate the to R it looks like this:
I am using the following libraries:
library(RCurl)
library(RJSONIO)
library(XML)
library(httr)
library(readr)
and the code looks like :
Upload_data<-PUT( url = "https://api.ibm.com/watsonanalytics/run/data/v1/datasets/DataID/content",
add_headers('Content-Type' = 'text/csv'),
add_headers('Accept'= 'application/json'),
add_headers('X-IBM-Client-Secret' = Secret),
add_headers('X-IBM-Client-Id' = Client),
add_headers('Authorization: Bearer'=Auth, body= "Province,Population density,Area,Population,
Ontario,97,83858,8169929
Quebec,337,30510,11007020
Alberta,111,547030,63601002
Manitoba,233,357021,81799600
British Columbia,393,41526,16824400
Costa Rica, 1,10000, 1000000"))
Seems that it is not working, do you know some way to fix it?
If I'm not mistaken, I believe that R is not yet supported through the Watson Analytics API Explorer, which is what your PUT request is using "https://api.ibm.com/watsonanalytics/"
The supported languages include Python, JavaScript, Java, C#, and PHP.

How do you create a user using RESTServer in Drupal?

Using REST Server 6.x-2.0-beta3, I'm trying to understand how to post to user.save.
curl -d 'XX' -v http://localhost/services/rest/service_user/save
I've tried to replace XX with:
account{'name':'myname','pass':'mypassword','mail':'my#email.org'}
account = {'name':'myname','pass':'mypassword','mail':'my#email.org'}
account="name=myname,pass=mypassword,mail=myemail.org"
account=name=myname,pass=mypassword,mail=myemail.org
account=myname,mypassword,myemail.org
But none of these seems to be right and finding any documention regarding this is next to impossible.
I've also tried the following:
curl -H "Content-Type: application/json" -d 'account={"name":"myname","pass":"mypassword","email":"123"}' -v http://localhost/services/rest/service_user/save
The error I get in this case is:
HTTP/1.0 406 Not Acceptable: Missing required argument account
Hi I also just started working with this module and wondering how to create content using JSON.
Just been able to create a simple node using this:
Post URL: http://path-to-site/services/rest/node
Request Header: Content-Type: application/json
Request Body: {"type":"story","title":"REST Test","body":"REST using JSON"}
I think you're using the wrong URL
I figured it out:
curl -H “application/x-www-form-urlencoded” -d "sessid=xxxx" -d "account[name]=MyName&account[pass]=mypass&account[mail]=myemail#gmail.com&account[conf_mail]=myemail#gmail.com" -v http://path-to-site/services/rest/service_user/save
You only have to add -d "sessid=xxxx" if you have configured Services to require a session. Make sure in that case to replace xxxx with your actual session id (from system.connect).

Resources