curl POST request is not working - rest

I am trying to consume POST URL using curl. Curl request is as below:
curl -k -H "Content-Type : application/x-www-form-urlencoded;charset=UTF-8" -H "Accept: application/json, text/plain, */*" -H "Authorization : OAuth oauth_consumer_key=2IaG9fzswU1f8bJ2bWCIIQ" -X POST -d "{'consumer_id':'google_bps','app_id':'google_bps_app','user_id':'bala.gto3','first_name':'bala','last_name':'gto3','email':'bala.gto3#gmail.com'}" https://ec2-54-189-116-121.us-west-2.compute.amazonaws.com/cec_baseline/api/users/save
Although JSON data is accurate I am getting bad request error.
Response is as below:
{"status":400,"code":0,"message":"Bad Parameters: Consumer Id and Application Id Mandatory!","description":"BAD REQUEST","result":[]}

Your have set Content-Type as application/x-www-form-urlencoded so you have to send form URL encoded data :
curl -k -H "Content-Type: application/x-www-form-urlencoded;charset=UTF-8" \
-H "Accept: application/json, text/plain, */*" \
-H "Authorization: OAuth oauth_consumer_key=2IaG9fzswU1f8bJ2bWCIIQ" \
-X POST \
-d 'consumer_id=google_bps&app_id=google_bps_app&user_id=bala.gto3&first_name=bala&last_name=gto3&email=bala.gto3#gmail.com' \
https://ec2-54-189-116-121.us-west-2.compute.amazonaws.com/cec_baseline/api/users/save
which gives :
{"status":200,"code":1,"message":"Successfully Saved!","description":"","result":[]}
Moreover, it seems your endpoint doesn't support JSON, when issuing your previous request with Content-Type: application/json it gives :
{"status":400,"code":0,"message":"Content Type must be application\/x-www-form-urlencoded!","description":"BAD REQUEST","result":[]}

Related

POST request to google cloud storage using Curl

In the following Curl command, content type and content length and access bearer are attached to my bucket URI to upload a file to google cloud storage.
C:\softwares\curl>curl -X POST -H "Content-Type:application/json" \
-H "Content-Length:100" \
-H "Authorization: Bearer <MY_OAUTH2_TOKEN>" \
"https://www.googleapis.com/upload/storage/v1/b/kids-74096.appspot.com/o?uploadType=media&name=newcurl" \
-d '{"text":"something"}'
But I am getting this error:
curl: (92) HTTP/2 stream 1 was not closed cleanly: PROTOCOL_ERROR (err 1)
Make sure to include a Content-Type header, and ensure that your Content-Length matches the length of the data you're sending. Here's an example:
curl -k -v -X POST \
-H "Authorization: Bearer <your_oauth2_token>" -H "Content-Length: 8" \
-H "Content-Type: text/plain" \
'https://www.googleapis.com/upload/storage/v1/b/your-bucket/o?uploadType=media&name=yourobjectname' \
-d 'yourdata'
As suggested in the comments, you might find it easier to use gsutil or the Cloud Storage client libraries to accomplish this.

How do I add users to value-based custom audience via API

The following is my request:
curl -X POST https://graph.facebook.com/v2.11/{customer_audience_id}}/users -d '{"payload": {"data": [["test#mail.com"]], "schema": ["EMAIL"]}}' -H "Content-Type: application/json" -H "Authorization: Bearer {ACCESS_TOKEN}
And the Response is:
{"error":{"message":"(#100) Weighted Custom Audience requires weight attribute.","type":"OAuthException","code":100,"fbtrace_id":"123123123"}}
If add one field 'WEIGHT' into the request:
curl -X POST https://graph.facebook.com/v2.11/{customer_audience_id}}/users -d '{"payload": {"data": [["test#mail.com", 100]], "schema": ["EMAIL", "WEIGHT"]}}' -H "Content-Type: application/json" -H "Authorization: Bearer {ACCESS_TOKEN}
The response becomes:
{"error":{"message":"(#100) Raw PII type is invalid, it should be one of EXTERN_ID,EMAIL,PHONE,GEN,DOBY,DOBM,DOBD,LN,FN,FI,CT,ST,ZIP,MADID,COUNTRY,PARTIALPHONE,PHONEID,STREETNAME,STREETNUM,STREETTYPE,STREET2ROW,STREETADDRESS,APPUID,PAGEUID,F5FIRST,F5LAST,EMAIL_MD5,PHONE_MD5","type":"OAuthException","code":100,"fbtrace_id":"123123123"}}
Seems like the weight variable is not even in the list of supported parameters. My question is: Is it possible to add users into value-based custom audience through API? I cannot find any references on the documentation page.

Can't post in a specific Yammer's group

I'm doing a curl to send a POST in my group, and it doesn't works, it posts on the All Company Network even if I sent the group_id.
curl -H "Accept: application/json" -H "Content-type: application/json" -H "Authorization: Bearer OAUTHTOKENHERE" -X POST -d '{"activity":{"actor":{"email":"MYEMAIL"},"action":"create"}}' https://www.yammer.com/api/v1/messages.json?body=TestingfromYammersAPI&group_id=GROUPID
I'm writing the right group_id, and still not reading that argument.
Does anyone has this problem too?
Yammer's API docs:
https://developer.yammer.com/docs/messages-json-post
The problem was that I wasn't quoting the URL -___-
Working code:
curl -H 'accept: application/json' -H 'authorization: Bearer OAUTHTOKENHERE' -H 'content-type: application/json' -X POST -d ' ' 'https://www.yammer.com/api/v1/messages.json?body=MESSAGE_HERE&group_id=GROUP_ID'

Is it a bug in Hbase REST API `get version/cluster`?

Hbase REST API, this interface get 'version/cluster', when I use the header Accept: application/json, the response is not JSON but plain text.
curl -X GET \
-H "Accept: application/json" \
"http://localhost:8888/version/cluster"
# "1.2.2"
But when I use Accept: text/xml, the response is correct XML.
curl -X GET \
-H "Accept: text/xml" \
"http://localhost:8888/version/cluster"
# <?xml version="1.0" encoding="UTF-8" standalone="yes"?><ClusterVersion>1.2.2</ClusterVersion>
Hbase issue #17713. The Jan Hentschel's comment, he is right. The JSON spec has been updated from RFC 4627 to RFC 7159 and a String is valid JSON.

curl: Could not resolve host: Authorization

I wrote this curl command which doesn't seem to work.
curl -H "Content-Type: application/json" -X PUT "Authorization: Bearer {token}" -d "{"login":"user1","password":"xxx"}" https://localhost:8443/users/user1 -k
I tried to change quotation marks but it doesn't work either. All I got is
curl: (6) Could not resolve host: Authorization
{"error":"unauthorized","error_description":"Full authentication is required to access this resource"}
The Authorization works fine though. I'm sure the token is correct.
The -H flag is missing in front of the Authorization header.
Try
curl -H "Content-Type: application/json" -H "Authorization: Bearer {token}" \
-X PUT -d '{"login":"user1","password":"xxx"}' \
https://localhost:8443/users/user1 -k
Because that was missing it was not seeing that as a header, but part of the request URL.
To test, I decode with this in PHP:
var_dump(json_decode(stream_get_contents(fopen('php://input', 'r'))));