without Error in my code i am getting error in postaman #PostMapping - postman

I write code for Restful services.in postman when i tried to send a request by using #Postmapping its getting error in postaman
this is my controller class
public class BookController {
private BookRepository bookrepository;
#PostMapping("/addBook")
public String save(#RequestBody Book book)
{
bookrepository.save(book);
return "added book with id"+book.getId();
}
#GetMapping("/findAllBooks")
public List<Book> getBooks()
{
return bookrepository.findAll();
}
#DeleteMapping("/delete")
public String deleteBook(#PathVariable int id){
bookrepository.deleteById(id);
return "book deleted"+id;
}
}
when i send a request to postman by post method at the time i m getting a error like the below
{
"timestamp": "2019-03-27T12:22:20.319+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/addBook"
}

Related

Which .NET Object corresponds to Lambda Proxt Integration in AWS

I've a lambda function that does some verification before inserting data into dynamoDB. I wish to return a 400 HttpStatus code if the passed payload is invalid and that's the reason I've googled and found
public async Task<APIGatewayProxyResponse> FunctionHandler(RequestItem request, ILambdaContext context)
{
But when I return the code as
private static APIGatewayProxyResponse GetBadRequestResponse()
{
var responseBadRequest = new APIGatewayProxyResponse
{
StatusCode = (int)HttpStatusCode.BadRequest,
Body = "Invalid payload sent",
// Headers = new Dictionary<string, string> { { "Content-Type", "text/plain" } }
};
return responseBadRequest;
}
It returns a 200 with the content of
{
"statusCode": 400,
"body": "Invalid payload sent",
"isBase64Encoded": false
}
In the AWS Console I did
But doing so If I put the APIGatewayProxyRequest as request, I've got null for Body field
Anyone has got a simila situation?

webhooks for MS graph create subscription fails when includeResourceData=true

{
"changeType": "created,updated,deleted",
"notificationUrl": "https://somewebsite.com/mswebhook/graph/notifications",
"resource": "/teams/{team-id}/channels/{channel-id}/messages",
"expirationDateTime": "2019-12-30T09:41:21Z",
"clientState": "",
"includeResourceData": true,
"encryptionCertificate": "TUlJQklUQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FRNEFNSUlCQ1FLQ0FRQlhFL0xOZjVYYVY4ZFlXbWFuSU9qUwphSnhyUG1tN0dHN0lWOGYwV2RjZDltbUkvaTVXQzhCNFBYaVBKREtKTnVFL2QvMXo5TndSbjR1UFBQQm9sN1BWCmdudVJ6UmZJSVEvUW1TZjYwUi9LUnYybHVlZzVwNW84Qk5UNDczdTRCbVZJVHNBWlF1eG43RGdnUi9JZlQzSVgKelpMdzNXWitDYzJyS1crblpmbUwwU0NiN21EL3RTZ3VqQUJPVEVvS0xBODkvNWhUamhuNzcvWHJzUTYrV1hMVgpKL3NtVDJvU3R3TzBnYXRIRUkwWkRSL0VYNkdVWDRRRVI4M0puS2hPSDJrZzZQNlZUMDFGUEw0Nk5WemZydWE4ClVob052Z0VlQStPY2xBOU5mUUpJQnVKUVFTbGZ0TmhYODJtVEdhVEtBTFN1bWZieUNac1ljQ3l4MXQ5RXF6Qi8KQWdNQkFBRT0=",
"encryptionCertificateId": "id",
"lifecycleNotificationUrl": "https://somewebsite.com/mswebhook/graph/notifications"
}
when this request is sent from postman It is giving
{
"error": {
"code": "InvalidRequest",
"message": "System.Security.Cryptography.CryptographicException: Cannot find the requested object.\r\n\r\n at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)\r\n at System.Security.Cryptography.X509Certificates.X509Utils._QueryCertBlobType(Byte[] rawData)\r\n at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)\r\n at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData)\r\n at Microsoft.Graph.Encryptor.Encryptor.ValidateCertificate(String certificate, String& errorMessage) in X:\\bt\\1070414\\repo\\src\\Dev\\Notifications\\Notifications.Azure\\Encryptor\\Encryptor.cs:line 293",
"innerError": {
"request-id": "e578bdba-2c47-41d7-a0da-5395b05e4203",
"date": "2019-12-31T06:57:59"
}
}
}
without includeResourceData property, subscription and notifications are working fine.
I am facing problem while choosing encryptionCertificate property.Currently I am passing Base64bit encoded 2048 bit RSA public key (online generated) in encryptionCertificate.

Facebook Graph API: The remote server returned an error: (400) Bad Request instead of error inside

I have a code that make a Get request to Facebook Graph API to get business account.
This is code:
var facebookBusinessAccountId = ConfigurationManager.AppSettings["facebook_business_account_id"];
facebookRestUrl += "&access_token=" + acct.AccessToken;
facebookRestUrl = facebookRestUrl.Replace("{0}", facebookBusinessAccountId);
var request = WebRequest.Create(facebookRestUrl);
request.Method = "GET";
request.ContentType = "application/json";
var response = request.GetResponse(); (Error here)
The URI look like:
https://graph.facebook.com/v3.1/1x8xx4005xxxxxx?fields=business_discovery.username(yess_cub){biography,id,ig_id,profile_picture_url,username,website}&access_token=EAAJ..
It should be return error like this:
{
"error": {
"message": "Invalid user id",
"type": "OAuthException",
"code": 110,
"error_subcode": 2207013,
"is_transient": false,
"error_user_title": "Cannot find User",
"error_user_msg": "The user with username: yess_cub cannot be found.",
"fbtrace_id": "BMEAcyYOZf9"
}
}
But error : The remote server returned an error: (400) Bad Request is what I get
Could anyone please help me?
Thanks alot!
I found an idea and catch the inner exception from try/catch statement
It should be like this:
catch (WebException ex)
{
using (StreamReader reader = new StreamReader(ex.Response.GetResponseStream()))
{
string jsonMessageString = reader.ReadToEnd();
}
}

Token Based Authentication on Postman

I am trying to send a request using a authentication token using Postman. I can successfully login from it and get the token. After that, when I try to send a request to a Authenticate method, it returns me a 401 - Unauthorized.
In the error definition, it says "The signature is invalid".
How I send a login request:
Here what it returns after logging in on postman :
{
"state": 1,
"msg": null,
"data": {
"requestAt": "2017-08-27T23:44:18.1397478+03:00",
"expiresIn": 2400,
"tokenType": "Bearer",
"accessToken": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6InVzZXIxIiwiSUQiOiIxMTYwYzg1YS0yMmVkLTQ2N2YtYThjNC05NTk4NmMyNTcyMGYiLCJuYmYiOjE1MDM4NjY2NjAsImV4cCI6MTUwMzg2OTA1OCwiaWF0IjoxNTAzODY2NjYwLCJpc3MiOiJNeUlzc3VlciIsImF1ZCI6Ik15QXVkaWVuY2UifQ.m9q84OVsei19_3zdDSZMfGDsNqotBr6L6xf1e5aJq9OmTE5ZfqJ9k2l84cbMuge4qvABxId_h7QUZT0pI_vqEqohTfhaF2kDloqXEWawN0LTDUdeJt6xqT3W9AWmvmnDFrehM6HOeStNGKqG8955OHnwHyEiYn6AIaqg4Sm6I87xk1C5aBhyfkV6-We-Wfj0W4NSg7_2LOIF6TApsnV8VF34PB5VATER9-g-dVUE0E_q4UmLFYD6lkudAXbA4Oa3iTXJKhLCL4NhacBXYXGN-ZyGwX64F7dWPw_mI8Q_AHpHkSrb4m5pscvgvo0leGRGVmuWuCP__rAZpw1EnLmTiQ"
}
}
This is the method I am requesting after the login method :
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[HttpGet]
public IActionResult GetUserInfo()
{
var claimsIdentity = User.Identity as ClaimsIdentity;
return Json(new RequestResult
{
State = RequestState.Success,
Data = new { UserName = claimsIdentity.Name }
});
}
And this is how I send a request to GetUserInfo method :
Lastly my TokenAuthOptions class :
public class TokenAuthOption
{
public static string Audience { get; } = "MyAudience";
public static string Issuer { get; } = "MyIssuer";
public static RsaSecurityKey Key { get; } = new RsaSecurityKey(RSAKeyHelper.GenerateKey());
public static SigningCredentials SigningCredentials { get; } = new SigningCredentials(Key, SecurityAlgorithms.RsaSha256Signature);
public static TimeSpan ExpiresSpan { get; } = TimeSpan.FromMinutes(40);
public static string TokenType { get; } = "Bearer";
}

Timeline item update error

I have a bundle of timelineitems using Mirror API, Now I am trying to change content of a timeline from bundle. But the below error occurs
An error occurred from update timeline : com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
{
"code" : 404,
"errors" : [ {
"domain" : "global",
"message" : "Not Found",
"reason" : "notFound"
} ],
"message" : "Not Found"
}
And update method is something like below
public static TimelineItem updateTimelineItem(Credential credential,
String itemId, String newText) {
try {
Mirror.Timeline timeline = getMirror(credential).timeline();
TimelineItem timelineItem = timeline.get(itemId).execute();
timelineItem.setText(newText);
return timeline.update(itemId, timelineItem).execute();
} catch (IOException e) {
System.err.println("\nAn error occurred from update timeline : " + e);
return null;
}
}
First I try to retrieve the timeline item, when I write execute, then the error occurred
Mirror.Timeline timeline = getMirror(credential).timeline();
TimelineItem timelineItem = timeline.get(itemId).execute();
How can I solve it?
It isn't completely clear from the exception you've posted, but it looks like the itemId isn't valid. How are you getting this itemId and can you verify if it is the timeline.get or the timeline.update that is causing the problem?