When I try to call my WEB API from Fiddler it calls using GET even though I set Fiddler to use POST.
NOTE: All my GET API methods are working fine.
POST http://www.myapisite.com/api/UserAccounts/CreateAccount
[Header] User-Agent:
Fiddler Host: www.myapisite.com
Content-Type: application/json; charset=utf-8
Content-Length: 453
[Request Body]
{
"user_id": "1",
"store_id": "1",
"merchant_id": "1"
}
My WEB API method signature:
[ValidateModelState]
[System.Web.Mvc.HttpPost]
[Route("api/UserAccounts/CreateAccount")]
[EnableCors(origins: "mymvcsite.com", headers: "*", methods: "*")]
public virtual IHttpActionResult CreateAccont(
[FromBody]AccountHolderDto accountHolderDto)
{
...
}
AccountHolderDto is simply a class with public properties (user_id, store_id, merchant_id)
Any help much appreciated! - This has had me baffled the entire day
Damn!, I removed the "www" prefix of the uri and it works now
From this:
http://www.myapisite.com/api/UserAccounts/CreateAccount
To this:
http://myapisite.com/api/UserAccounts/CreateAccount
Unbelievable the smallest things cause so much pain
Related
When I make a GET http request for the metadataHeaders that only requests one of them like so:
https://gmail.googleapis.com/gmail/v1/users/me/messages/${messageId}?$format=metadata&metadataHeaders=From
it works just fine. But my question is how do I go about sending the array of headers that I want [to, from, subject], in my request? So basically, how would I restructure my metadataHeaders query parameter... found here ->
https://gmail.googleapis.com/gmail/v1/users/me/messages/${messageId}?$format=metadata&metadataHeaders=From
to also contain From, To, & Subject
I have been trying to figure out how to get these headers for quite a while to no avail. I tried looking at the documentation ( https://developers.google.com/gmail/api/reference/rest/v1/users.messages/get ) but although I know its possible thanks to it, I can't seem to find out how to implement it in my http request. I also tried looking through the stack overflow responses to similar questions but many weren't really useful at all since many of the questions were different from mine, using the oauth library, or in a programming language. All I care for is how to make the http request.
Headers is just an array So you can just add it more then once
metadataHeaders=from&metadataHeaders=to&metadataHeaders=subject
Request:
GET https://gmail.googleapis.com/gmail/v1/users/me/messages/185cf8d12166fc7a?format=metadata&metadataHeaders=from&metadataHeaders=to&key=[YOUR_API_KEY] HTTP/1.1
Authorization: Bearer [YOUR_ACCESS_TOKEN]
Accept: application/json
Resonse:
"payload": {
"partId": "",
"headers": [
{
"name": "From",
"value": "[REDACTED]"
},
{
"name": "To",
"value": "[REDACTED]#gmail.com"
},
{
"name": "Subject",
"value": "Security alert"
},
]
},
i am trying to comment on a post using SocailActions Api
i am using the following permissions w_organization_social r_organization_social w_member_social
and i am logged in as a an admin of the page that i am trying to comment on its behalf
my request is :
POST https://api.linkedin.com/v2/socialActions/urn%3Ali%3Ashare%3AXXXXXXXXXX/comments HTTP/1.1
Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXX
Host: api.linkedin.com
cache-control: no-cache,
X-Restli-Protocol-Version: 2.0.0
Accept: application/json
Content-Type: application/json
Content-Length: 136
{
"actor":"urn:li:organization:23741470",
"object" :"urn:Al:share:6664163994204549120",
"message":{
"text":"tessst"
}
}
and i am getting 403
{
"serviceErrorCode": 100,
"message": "Field Value validation failed in REQUEST_BODY: Data Processing Exception while processing fields [/actor]",
"status": 403
}
the same thing happened when i tried to use the ugcPost Api to post an new comment
any ideas what might cause this ?
i was able to solve this finally, i remove all header property except the content type and content length then it worked
I have tried using
GET https://www.googleapis.com/gmail/v1/users/userId/messages
but only get id and threadId as a response.
I want to display list of email with title and from email. Is there an api exist to get info or any way I can get it?
Gmail API is designed in such a way, that
you need to obtain the IDs of all emails of interest (you can use the search parameter q to filter the results) with GET https://www.googleapis.com/gmail/v1/users/userId/messages - as you already did
you need to retrieve each of the messages separately by their ID with GET https://www.googleapis.com/gmail/v1/users/userId/messages/id
If you write a code in a language of your choice you can automatize this process with loops.
Sample how to do it with Apps Script:
function myFunction() {
var myMessages=Gmail.Users.Messages.list("me",{'maxResults': 5 }).messages;
Logger.log(myMessages);
for(var i=0;i<myMessages.length;i++){
var id=myMessages[i].id;
Gmail.Users.Messages.get('me', id).payload.headers.forEach(function(e){
if(e.name=="Subject"||e.name=="From"){
Logger.log(e.name+": "+e.value)
}
}
);
}
}
The user messages.list method only returns a message list of message id and thread id. This is a limitation in the API itself and there is nothing you can do to change that. Its a free api and we are bound by the limitations of google.
{
"messages": [
{
"id": "16d1f7849145662a",
"threadId": "16d1f55457d4e145"
},
{
"id": "16d1f69d541016ee",
"threadId": "16d1f55457d4e145"
},
In order to get additional information about the message you need to do a message.get on each message.
GET https://www.googleapis.com/gmail/v1/users/userId/messages/id
Sorry its the only way its a lot of gets.
batching
You can try the batching endpoing batch You're limited to 100 calls in a single batch request. If you need to make more calls than that, use multiple batch requests.
postman headers
Content-Type multipart/mixed; boundary=batch_foobarbaz; type=application/http
Authorization Bearer ya29.GluBB7_cEfLMThXKuxR_9g8YyjSTLwBHRHdPtiYXwDABKQlrbxEyFqSFsnFYTs5b54W7
Accept-Encoding application/gzip
postman body
--batch_foobarbaz
Content-Type: application/http
GET gmail/v1/users/me/messages/16d24956228a98c4
Accept: application/json; charset=UTF-8
--batch_foobarbaz
Content-Type: application/http
GET gmail/v1/users/me/messages/16d24956228a98c4
Accept: application/json; charset=UTF-8
--batch_foobarbaz--
SMTP
beyond that you can go though the smtp server directly. This will require a programming language which can handle direct calls to a mail server.
I'm trying to check my api implementation with my documentation written in blueprint. I've expected that dredd will fail when json returned from server will be different than specified in documentation. To check this I've copied dredd-example. First I've run dredd with original apib file to make sure that all is green. Then I've modified response in documentation and expected dredd to show me some red... But it doesn't.... it looks like tool is only checking response headers but not the response body. Here is output from console:
pass: GET /machines duration: 18ms
request:
host: localhost
port: 3000
path: /machines
method: GET
headers:
User-Agent: Dredd/0.2.1 (Darwin 13.0.0; x64)
expected:
headers:
Content-Type: application/json
body:
[
{
"_id": "52341870ed55224b15ff07ef",
"type": "bulldozer",
"name": "willyxxxxxx" #HERE IS WHERE I CHANGED RESPONSE IN DOCUMENTATION
}
]
status: 200
actual:
headers:
x-powered-by: Express
content-type: application/json
content-length: 95
date: Thu, 20 Mar 2014 08:22:40 GMT
connection: keep-alive
body:
[
{
"_id": "532aa5507dcdfff362931799",
"type": "bulldozer",
"name": "willy"
}
]
status: 200
Can I check response body using dredd? And how can I do this?
In JSON bodies Dredd is checking only for keys not for values. When you change key in the expected JSON body document, it will definitely fails.
I have an integration test which uses eventmachine to receive http requests. This is my eventmachine handler:
class NotificationRecipient < EM::Connection
def receive_data(data)
EM.stop
end
end
I need to test various properies of the received request, e.g. I want to extract a json payload from an HTTP POST request string I've received like this. Is there a nicely packaged way to do it?
Googling finds lots of ways to make a request and parse the response, e.g. rest-client will parse response automatically. However, since I'm receiving the request, not making it, none of these ways work for me.
I would make use of WEBrick. WEBrick::HTTPRequest has a serviceable parser, and all you need to do is pass an IO object to its parse method and you have yourself an object you can manipulate.
This example declares a POST request with a JSON body in a string and uses StringIO to make it accessible as an IO object.
require 'webrick'
require 'stringio'
Request = <<-HTTP
POST /url/path HTTP/1.1
Host: my.hostname.com
Content-Type: application/json
Content-Length: 62
{
"firstName": "John",
"lastName": "Smith",
"age": 25
}
HTTP
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
req.parse(StringIO.new(Request))
puts req.path
req.each { |head| puts "#{head}: #{req[head]}" }
puts req.body
output
/url/path
host: my.hostname.com
content-type: application/json
content-length: 62
{
"firstName": "John",
"lastName": "Smith",
"age": 25
}