How to define Error schema using Spring Boot Open API 3? - swagger-2.0

I am using Spring Boot and Spring Rest Application. In this example I am migrating from Swagger2 to Open API 3.
I've below #APiResponse which returns 500 errors code and I define the ErrorResource Object for the same. I am not sure how to define error schema in this annatation for the same ?
#ApiResponses(value = { #ApiResponse(responseCode = "200", description = "For Success"),
#ApiResponse(responseCode = "500", description = "Internal Server Error") })

You add the schema implementation of your ErrorDetails on the content attribute.
For exampel:
#ApiResponse(responseCode = "500", description = "Internal Server Error", content = #Content(mediaType = "application/json",
schema = #Schema(implementation = ErrorDetails.class)))
You can have a look at the swagger documentation:
https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Annotations

In case you are using the SpringFox dependency:
#ApiResponses(value = {
#ApiResponse(code = "200", message = "For Success"),
#ApiResponse(code = "500", message = "Internal Server Error", response = MyErrorResponse.class)
})

Related

error creating event with Meetup's api (Python)

I am trying to use Meetup's api to automatically post events on the network, and I am following their guide but I still getting b'Must provide query string.' as a return.
Does anyone know what I may be doing wrong?
import requests
authent_url = "https://api.meetup.com/gql"
params = {
"Authorization" : "Bearer [API KEY HERE]",
}
creating_event = {"mutation": '{createEvent(input: {"groupUrlname": "MY NAME", "title": "Arraial do Cabo", "description": "Trip para arraial", "startDateTime": "2022-09-10 15:00:00.000"}) {event {id} errors {message code field}}}'}
query_by_title = requests.post(authent_url, headers=params, json=creating_event)
query_by_title.content
I don't know what else to do, any help?
EDIT:
Remade the query here and got it
https://splunktool.com/post-graphql-mutation-with-python-requests

How can I troubleshoot a 401 error from MS Dataverse through R?

Yesterday I was using the following code to get data out of my MS Dataverse through R. It was working fine.
require(httr)
require(rvest)
dataverse_api = oauth_endpoint(request = NULL,
authorize = "https://login.microsoftonline.com/REDACTED/oauth2/v2.0/authorize",
access = "https://login.microsoftonline.com/REDACTED/oauth2/v2.0/token",
base_url = "https://login.microsoftonline.com/common/oauth2/authorize?resourcehttps://org593dc393.crm4.dynamics.com")
API.Key = "REDACTED"
API.Secret = "REDACTED"
App = oauth_app("EPS Project Development", key = API.Key, secret = API.Secret)
API.token = oauth2.0_token(dataverse_api, App, scope = "https://org593dc393.crm4.dynamics.com/.default")
API.AuthKey = API.token$credentials$access_token
GET.Buildings = GET("https://org593dc393.crm4.dynamics.com/api/data/v9.2/crfd0_dartbuildingses", add_headers(Authorization = paste("Bearer", API.AuthKey, sep = " ")))
Today, trying to run the same lines of code with no modifications is giving me a 401 error. Based on some research on debugging 401 errors (none of them specific to MS Dataverse) I tried clearing my cache, clearing my cookies, flushing my DNS with ipconfig/flushdns and navigating directly to the endpoint and inspecting the request, which returned the following 200 response:
With all of these efforts, despite the fact that this code worked yesterday, I am still getting the following response in R:
I also generated a new token using Postman. When I run the GET command using that token, I get a status of 200.
API.AuthKey = "REDACTED TOKEN FROM POSTMAN"
GET.Buildings = GET("https://org593dc393.crm4.dynamics.com/api/data/v9.2/crfd0_dartbuildingses", add_headers(Authorization = paste("Bearer", API.AuthKey, sep = " ")))
GET.Buildings$status_code
[1] 200
Is it apparent to anyone in the R response to my initial attempt what I've done wrong? If not, how can I debug this?
It turned out the code was supplying the same Access Token each time. I just needed to add cache = FALSE so that I'm not using cached tokens. If it's helpful to anyone, the full code is now:
require(httr)
require(rvest)
dataverse_api = oauth_endpoint(request = NULL,
authorize = https://login.microsoftonline.com/REDACTED/oauth2/v2.0/authorize,
access = https://login.microsoftonline.com/REDACTED/oauth2/v2.0/token,
base_url = https://login.microsoftonline.com/common/oauth2/authorize?resourcehttps://org593dc393.crm4.dynamics.com)
API.Key = "REDACTED"
API.Secret = "REDACTED"
App = oauth_app("EPS Project Development", key = API.Key, secret = API.Secret)
API.token = oauth2.0_token(dataverse_api, App, scope = https://org593dc393.crm4.dynamics.com/user_impersonation, cache = FALSE)
API.AuthKey = API.token$credentials$access_token
GET.Buildings = GET(https://org593dc393.crm4.dynamics.com/api/data/v9.2/crfd0_dartbuildingses, add_headers(Authorization = paste("Bearer", API.AuthKey, sep = " ")))

Posting a file to an outside API with a JSON web token

I am trying to upload a database file to an outside organization's API using R. I have a username and password, as well as an separate address to get the token from, and then to upload the file.
usr<-"username"
pw<-"passwood"
url <- "https:/routurl/api/"
Token='Token'
UploadFile='UploadFile'
#Get Token
r <- httr::POST(url = paste0(url,Token),
body = list(
UserName = usr,
Password = pw,
grant_type = "password"
), verbose())
tkn=jsonlite::prettify(httr::content(r, "text"))
This seems to work, as I can extract a token from the content.
> tkn
{
"result": {
"token": "eyJhbGciOiJIUzFAKEIsInR5cCI6IkpCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiZ3JphzZSIsImp0aSI6IjUwNmIwN2MyLTTHISISFAKEIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL2VIVECHANGEDTHINGScyI6ImVtaWx5dGdyaWZmaXRoc0BiaW9zLmF1LmRrIiwiZXhwIjoxNTk4NzEwMTU3LCJpc3MiOiJ2bXNhcHAiLCJhdWQiOiJ2bXN1c2VycyJ9.z8sr-HT21u1bN7qCEXAMPLEONLY-TKAluO3k",
"expiration": "29 August 2020 16:09:17"
},
"id": 2,
"exception": null,
"status": 5,
"isCanceled": false,
"isCompleted": true,
"isCompletedSuccessfully": true,
"creationOptions": 0,
"asyncState": null,
"isFaulted": false
}
#re-formatting
tkn=jsonlite::fromJSON(content(r, "text"), simplifyVector = FALSE)
So, this all seems ok, however, if I try to double check this on the JSON DeCoder, my correct web information comes up in the payload, but at the bottom it claims it is an invalid signature.
Also, the auth_token variable is NULL in the request, and that doesn't seem right.
> r$request$auth_token
NULL
However, I can't test this because I cannot, for the life of me, figure out how to use this JWT to POST a file to the rooturl/UploadFile. Every document I look at that goes over how to POST to an API does not include how to include your JWT in the POST, or at least it isn't very clear. Is it in the header? Is it like this?
r2=POST(url=paste0(url,UploadFile), body = list(y = upload_file('O:/Igoturfilerighthere.h5')),
add_headers('Authorization' = paste("Bearer", tkn$result$token, sep = " ")), encode = "json", verbose())
Am I setting the headers incorrectly?
r3=POST(url=paste0(url,UploadFile), body = list(y = upload_file('O:/Igoturfilerighthere.h5')),
httr::add_headers("x-auth-token"=tkn$result$token), verbose())
For the r3 request I get a 401 error, which makes me think that I am on the correct path and that I am entering my token information incorrectly. If anyone could help guide me on the next step, I'd appreciate it. I just don't know where else to place that information.
Cheers,
etg
UPDATE:
If, in the initial request, I add 'encode = "json"', it throws a 400 Bad Request Error. This is how the website I am trying to upload to writes its own code. I've double checked my username and password, and they are correct.
r <- httr::POST(url = paste0(url,Token),
body = list(
UserName = usr,
Password = pw,
grant_type = "password"
),encode = "json", verbose())
HTTP/1.1 400 Bad Request
Transfer-Encoding: chunked
Content-Type: application/problem+json; charset=utf-8
Server: Microsoft-IIS/10.0
Strict-Transport-Security: max-age=2592000
X-Powered-By: ASP.NET
So, I reached out to the org behind the API I was trying to access, and there few a few problems with my JWT request. This is the correct code:
r <- httr::POST(paste0(url,Token),
body = list(UserName = usr, password = pw),
encode = "form", verbose())
The big difference is 'grant_type' is removed and 'encode="form"', as I was trying to log in via a form on their site. With that difference, I was able to upload a file using the following:
r2=POST(url=paste0(url,UploadFile), body = list(fileToUpload = httr::upload_file('O:/IGotUrFileHere.h5')),
httr::add_headers('Authorization' = paste("Bearer", tkn$result$token, sep = " ")), verbose())
Again, the verbose() function isn't necessary. It just helps you troubleshoot. Good luck!

Gmail authentication error: invalid_request Missing required parameter: client_id

I am facing an issue while trying to access gmail through gmailr package.
Had given then input for Client and secret_key and it is able to run gmail_auth(..........). However, when I am trying to extract messages() I am getting 400 error.
Tried using .json secret_file as well. But same result!
Can you explain where I am missing the client_id?
gmail_auth(scope = c("read_only", "modify", "compose", "full"), id = the$id,secret = the$secret, secret_file = NULL)
messages(search="XX",num_results = 2, label_ids = NULL,include_spam_trash = FALSE,page_token = NULL, user_id = "me")
That’s an error.
Error: invalid_request
Missing required parameter: client_id
Learn more
Request Details
scope=https://www.googleapis.com/auth/gmail.readonly https://www.googleapis.com/auth/gmail.modify https://www.googleapis.com/auth/gmail.compose https://mail.google.com/
redirect_uri=urn:ietf:wg:oauth:2.0:oob
response_type=code

Upload video fail to youtube from asp.net website by data api

I am trying to upload video in my ASP.net website to YouTube using the data API but I am getting this error: "The remote server returned an error: (403) Forbidden."
I am using the below code:
YouTubeRequestSettings settings = new YouTubeRequestSettings("VideoPortal", "Developer_Key", "username", "password");
YouTubeRequest request = new YouTubeRequest(settings);
Video newVideo = new Video();
newVideo.Title = "testvideo";//txttitle.Text.Trim();
newVideo.Tags.Add(new MediaCategory("Autos", YouTubeNameTable.CategorySchema));
newVideo.Keywords = "testvideo";//txtkeyword.Text.Trim();
newVideo.Description = "testvideodesc";//txtdesc.Text.Trim();
newVideo.YouTubeEntry.Private = false;
newVideo.Tags.Add(new MediaCategory("mydevtag, anotherdevtag",
YouTubeNameTable.DeveloperTagSchema));
newVideo.YouTubeEntry.Location = new GeoRssWhere(37, -122);
// alternatively, you could just specify a descriptive string
// newVideo.YouTubeEntry.setYouTubeExtension("location", "Mountain View, CA");
string path = Server.MapPath("video/Screen-Recording.mov");
newVideo.YouTubeEntry.MediaSource = new MediaFileSource(path,
"video/quicktime");
settings.Timeout = 100000000;
Video createdVideo = request.Upload(newVideo);
Can anybody please suggest to me how I can make this code work and resolve the error?
what the HTTP response body's content is when you get back your HTTP 403 response? There should be an error message in the response body that provides an explanation of what went wrong

Resources