How to call API in Command Line Interface - json

I have an API URL which looks like this https://my.domain.com/api/users, but when i try to access it through web I got blank page,
and when i try curl i got nothing, how do i access it to view content of the users? I have api_key and accessToken
This is what i have done so far:
curl https://my.domain.com/api/users
I have an API URL which looks like this https://my.domain.com/api/users, but when i try to access it through web I got blank page,
and when i try curl i got nothing, how do i access it to view content of the users? I have api_key and accessToken
This is what i have done so far:
curl https://my.domain.com/api/users

Related

Application/Json error when sending Gmail with Postman

I'm trying to send a Gmail with Postman but got this error:
These are my configured headers:
I have configured everything needed on Google Cloud engine (Oauth permissions, certifications...etc), read similar posts, and also tried testing from gmail API playground and everything was ok:
Any idea of what could be wrong?
Remove all custome headers , (Create a new request by following below steps)
Steps:
https://console.developers.google.com/ Goto url and create an API. (by clicking credentials>create credentials)
https://console.developers.google.com/apis/api/gmail.googleapis.com/overview Goto url, click credentials> create new 0auth0.2 ( select applicaiton type as Web application)
While creating 0auth0.2 scroll down and set Authorized redirect URIs as https://localhost
CLick the download as json and then save the auth
Open postman and set authorization as 0auth2.0 from authorization header:
Generate new token by filling the content as per the downloaded json ( open the json and fill postman as in json)
set scope and state as : https://mail.google.com/ ( full access ) see scope at : https://developers.google.com/gmail/api/auth/scopes
In postman Set url as :https://gmail.googleapis.com/gmail/v1/users/praveendvd0pravu%40gmail.com/messages/send?key={YOURAPI_KEY_That_was_generated}
goto https://www.base64encode.org/ , and paste below content and click encode. Copy the output.
From: youremail#gmail.com
To: tosomeemail#gmail.com
Subject: Hi
Hi this is
9): paste it as json body
{
"raw":"IEZyb206IHlvdXJlbWFpbEBnbWFpbC5jb20KIFRvOiB0b3NvbWVlbWFpbEBnbWFpbC5jb20KIFN1YmplY3Q6IEhpICAKICAgIApIaSB0aGlzIGlzIA=="
}
Send it :

drupal 7 services rest not returning json

I have created a webservice successfully and I can call it , but it returns XML always. I tried adding .json at the end of the url and 'accept: application/json' header, but when I call these, it returns blank with a 200 response.
The configuration done (admin/structure/services) is:
edit tab: created a rest service with "path to endpoint" = loginapi & debug enabled
server tab: response formatters & parsing are all checked (including json)
resources tab: everything under user is checked without any alias
domain.com/loginapi/user/login --> this works perfect & I can login and returns xml, adding .json (login.json) returns nothing
How can I make this work please? I've went through all docs & examples, but none work for me
thanks
Check your server configuration is as follow: Services API
Then validate your endpoint with curl -H "Accept: application/json" -i https://your.domain/endpoint. Return header should have Content-Type: application/json
To return JSON from Drupal, check the drupal_json_output function (It sets the HTTP Content-Type header for you). Pro Tip: If your endpoint is defined through hook_menu, you can add 'delivery callback' => 'drupal_json_output' to your menu item to tell Drupal that your page callback's return value should be converted to output.
However, this doesn't work if your menu item has an 'access callback'. For some technical reason inside of Drupal core, a 3 gets returned instead of a 403 status if the access check fails. I wish I could remember how I solved that when I first figured it out half a year ago :-(

Twitter endpoint request gets HTML response in Node app deployed to Heroku

I made a small script querying a Twitter public endpoint to ask for a username's availability.
A cURL request to this endpoint throws a JSON response formatted like this:
$ curl 'https://twitter.com/users/username_available?username=jack'
{
"valid":false,
"reason":"",
"msg":"Nombre de usuario no disponible",
"desc":"Nombre de usuario no disponible"
}
Based on this, I wrote a small NodeJS app which makes this same request (using Request package).
Both CURL and my app work fine when run locally.
But in Heroku both CURL and my app get a full HTML response (with Twitter's mobile version) instead of JSON, so my app can't parse and evaluate.
Anyone had similar issues, and know how to get it working?
Thanks!
Edit (extra info):
Script is running in a web dyno in a free plan. Can't figure out how to switch to a worker dyno (if that's even still a thing)
Edit 2 (update): Now it's running on a worker Dyno, but the issue persists. Still getting HTML responses.
The endpoint you are calling is not a documented or supported Twitter API endpoint, so there should be no expectation of support, or guarantee that it will work. If you try to hit such an endpoint regularly from an unknown IP address then you should expect the IP to be blocked by Twitter's infrastructure as a protective measure.

BOX-API: Trying to get a shared folder without a token 401 Unauthorized error

I want to interrogate a shared folder without having to log the user in, from reading the documentation, this should be fine to do, but if run the example within my command line:
curl https://api.box.com/2.0/shared_items \
-H "Authorization: BoxAuth api_key=YOUR_API_KEY&shared_link=https%3A%2F%2Fwww.box.com%2Fs%2F8tqjqtoky18sbnoz264c"
Using my API key it works fine, however, within my app or just within a web browser, if I use:
https://api.box.com/2.0/shared_items -H "Authorization: BoxAuth api_key=YOUR_API_KEY&shared_link=https%3A%2F%2Fwww.box.com%2Fs%2F8tqjqtoky18sbnoz264c"
again with my API key, I get 401 Unauthorized error.
What am I doing wrong? Is it an encoding issue? as it looks like the end part of the string needs to be encoded, however the rest of it doesn't, I have tried to make sure that the C# code I am using does not encode the string, and I think it is not, but it still fails with 401.
It looks like the shared link from the example that you're using (the one ending with 8tqjqtoky18sbnoz264c) is no longer a valid URL. You should go into the Box web app and create a new shared link to test with, and that should work.

POST: sending a post request in a url itself

I have been given a url .. www.abc.com/details and asked to send my name and phone number on this url using POST. They have told me to set the content-type as application/json and the body as valid JSON with the following keys:
name: name of the user
phone number: phone number of the user
Now i have no clue how to send this request! Will it be something like:
http://www.abc.com/details?method=post&name=john&phonenumber=445566
or do i have to use java to send the same?
Please help
Based on what you provided, it is pretty simple for what you need to do and you even have a number of ways to go about doing it. You'll need something that'll let you post a body with your request. Almost any programming language can do this as well as command line tools like cURL.
Once you have your tool decided, you'll need to create your JSON body and submit it to the server.
An example using cURL would be (all in one line, minus the \ at the end of the first line):
curl -v -H "Content-Type: application/json" -X POST \
-d '{"name":"your name","phonenumber":"111-111"}' http://www.example.com/details
The above command will create a request that should look like the following:
POST /details HTTP/1.1
Host: www.example.com
Content-Type: application/json
Content-Length: 44
{"name":"your name","phonenumber":"111-111"}
You can post data to a url with JavaScript & Jquery something like that:
$.post("www.abc.com/details", {
json_string: JSON.stringify({name:"John", phone number:"+410000000"})
});
It is not possible to send POST parameters in the URL in a straightforward manner. POST request in itself means sending information in the body.
I found a fairly simple way to do this. Use Postman by Google, which allows you to specify the content-type (a header field) as application/json and then provide name-value pairs as parameters.
You can find clear directions at [2020-09-04: broken link - see comment] http://docs.brightcove.com/en/video-cloud/player-management/guides/postman.html
Just use your URL in the place of theirs.
You can use postman.
Where select Post as method.
and In Request Body send JSON Object.
In windows this command does not work for me..I have tried the following command and it works..using this command I created session in couchdb sync gate way for the specific user...
curl -v -H "Content-Type: application/json" -X POST -d "{ \"name\": \"abc\",\"password\": \"abc123\" }" http://localhost:4984/todo/_session
If you are sending a request through url from browser(like consuming webservice) without using html pages by default it will be GET because GET has/needs no body. if you want to make url as POST you need html/jsp pages and you have to mention in form tag as "method=post" beacause post will have body and data will be transferred in that body for security reasons. So you need a medium (like html page) to make a POST request. You cannot make an URL as POST manually unless you specify it as POST through some medium. For example in URL (http://example.com/details?name=john&phonenumber=445566)you have attached data(name, phone number) so server will identify it as a GET data because server is receiving data is through URL but not inside a request body
In Java you can use GET which shows requested data on URL.But POST method cannot , because POST has body but GET donot have body.