Twilio Programable Chat Rest API Accepting JSON - twilio

When creating a Channel the REST API seems to ignore any data in requests with a JSON body. Example:
curl -X POST https://chat.twilio.com/v2/Services/{instance sid}/Channels -H 'authorization: Basic blah blah blah' -H 'content-type: application/json' -d '{ "friendly_name": "Test Chat One", "type": "private" }'
Does the API not support JSON requests? The docs show requests with post with form data https://www.twilio.com/docs/api/chat/rest/channels?code-sample=code-create-a-channel&code-language=curl&code-sdk-version=default but not JSON??
Have I missed something?
Ta

Twilio developer evangelist here.
The Twilio API does not support JSON requests (though it will respond with JSON if you ask it to).
Check the documentation on the API here. It says:
In the PUT or POST, you represent the properties of the object you wish to update as form urlencoded key/value pairs. Don't worry, this is already the way browsers encode POSTs by default. But be sure to set the HTTP Content-Type header to "application/x-www-form-urlencoded" for your requests if you are writing your own client.

Related

mediawiki API does not see the csrf token

When running my own mediawiki on localhost I run into a problem with the api endpoint for editing a page. The api works fine otherwise. For instance when querying tokens I get the following output:
$ curl "http://localhost/api.php?action=query&meta=tokens&type=createaccount|csrf|login&format=json"
{"batchcomplete":"","query":{"tokens":{"createaccounttoken":"1e5c2ce3f9e12fdab05a0e6e6352da3162644214+\\","csrftoken":"+\\","logintoken":"35ee2e6ccbbd654bcfada9cddab07f7662634214+\\"}}}
Interestingly the csrftoken has the strange value '+\\', which also seems to be appended to the logintoken.
When posting an edit action (for an existing page called Alice) with this token I get the reponse that the token is missing from the post body. But it's not missing, or is it?
$ curl -X POST "http://localhost/api.php?action=edit&title=Alice&summary=test&text=article&baserevid=0&token=+\\&format=json"
{"error":{"code":"mustpostparams","info":"The following parameter was found in the query string, but must be in the POST body: token.","*":"See http://localhost/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/> for notice of API deprecations and breaking changes."}}
Then I followed this advice and added the cookie-jar option to make the curl request from the same session, but it gave the same error response. Any ideas?
By the way I used the docker.io/bitnami/mediawiki:1 docker image together with a mariadb to set up my mediawiki.
The following parameter was found in the query string, but must be in the POST body
I'm not very familiar with curl but it seems that you are sending a post request with the params in the query part. Try sending them in the post body as the error suggests:
curl --data "action=edit&title=Alice&summary=test&text=article&baserevid=0&token=+\\&format=json" http://localhost/api.php

How to pass multiple username in JIRA REST API to get bulk users?

I am referring to below mention Rest API, It returns details of users specified in a list of usernames or key, It's mention in doc to provide Comma-separated list of usernames.
Get Bulk User Jira API
This API is working perfectly when pass single username, but when I pass multiple emails (Comma separated it doesn't work)
curl -D- \
-X GET \
-H "Authorization: Basic Secret_Key" \
-H "Content-Type: application/json" \
"https://mydomain.atlassian.net/rest/api/2/user/bulk?username=**myusername**"
Above curl command works perfectly fine, but I am not able to search multiple username in single query, if I pass comma separated usernames it returns empty result.
the document said "To specify multiple users, pass multiple username parameters". So you will need to repeat the parameter, like /user/bulk?username=**myusername**&username=**anothername**

How can I get custom field data from the Asana API?

I've configured some custom fields for a project in Asana. How can I fetch those fields when getting tasks from the Asana API?
You can get the value of custom fields by fetching the task object directly:
curl -H "Authorization: Bearer <personal_access_token>" https://app.asana.com/api/1.0/tasks/1001
Or by adding custom_fields to the opt_fields parameter for a request which returns compact representations of tasks:
curl -H "Authorization: Bearer <personal_access_token>" https://app.asana.com/api/1.0/projects/1331/tasks?opt_fields=custom_fields

Posting attachments to Slack API

So I just understood that the Slack Web API does not support JSON data over POST. Which means I have to encode my complex and nested JSON object to fit in query parameters over GET. Problem is, the attachements don't seem to work. Does anyone have a solution ?
So I just understood that the Slack Web API does not support JSON data over POST. Which means I have to encode my complex and nested JSON object to fit in query parameters over GET.
I'm not sure I follow what you mean. You can certainly use POST. The body of a Slack API call should be form-encoded, but parameter values are sometimes JSON (as is the case for attachments).
Here's a working curl command that uses HTTP POST to post a message with a simple attachment.
$ curl -d token=<REDACTED> -d channel=<REDACTED> \
-d text="This is the main text." \
-d attachments='[{"text": "This is an attachment."}]' \
https://slack.com/api/chat.postMessage
I'd recommend using POST, but GET also works fine. If you fill in the values in https://api.slack.com/methods/chat.postMessage/test, the tool will give you a URL at the bottom that you can use with HTTP GET.

Constructing an HTTP POST request using Curl and Postman

I have been using curl & Postman on Chrome to send http POST requests with one variable to an simple HTTP server I have running and I have noticed that they construct the requests slightly differently. Apologies if I might have used any incorrect terminology in constructing the question - I'm still learning this stuff.
Using Postman, the request is constructed by putting a '?' between the resource name and the variable. E.g.
http://192.168.0.2:9999/1/command?a=b
However, the following curl command:
curl -X POST http://192.168.0.2:9999/1/command --data a=b
does not put a '?' between the resource name and the variable.
The result is that the HTTP server interprets the requests differently.
In the first case, the body of the request is empty and in the second case the body contains a=b.
Which version is correct?
Constructing curl , python request , using HTTP POST
Open postman client and click on code [Below save button ] refer snapshot .
when click on code another window appears . refer snapshot .
similarly you can generate various other request [curl , python ,java , php ] refer snapshot
You can refer below link
http://jmeterblogb.blogspot.in/2016/11/constructing-curl-from-python-http-php.html
POST requests post data as part of the request body and GET requests via URL parameters. If you choose the form data option in postman you can pass it the same way (request body) in postman as well. How are parameters sent in an HTTP POST request? may be worth reading.

Resources