Below web API returns JSON for the given ID.
http://aws-av-devser/Assigning_ID/api/QidMasters/2
It's working as expected in postman.
but when I try to consume this web API in different projects on the same server. I am getting
404 Not found Error
Below is the code to consume the web API
var uri = "http://aws-av-devser/Assigning_ID/api/QidMasters/2";
var response = await httpClient.GetAsync(uri);
Error Message :
{
StatusCode: 404,
ReasonPhrase: 'Not Found',
Version: 1.1,
Content: System.Net.Http.HttpConnectionResponseContent,
Headers:
{
Server: Microsoft-HTTPAPI/2.0
Date: Fri, 17 Jun 2022 17:59:28 GMT
Connection: close
Content-Type: text/html; charset=us-ascii
Content-Length: 315
}
}
Please correct me if I am missing something
Related
Here is my code:
Here is the response:
2020/09/14 12:19:51.425: INFO Results for adding ppsEmailAddress as recovery email: {data=[object Object], finalURL=https://www.googleapis.com/admin/directory/v1/users/ttestaccount#pps.net, headers={Alt-Svc=h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43", Content-Length=357, Content-Type=application/json; charset=UTF-8, Date=Mon, 14 Sep 2020 19:19:51 GMT, Server=ESF, Vary=[Origin, X-Origin, Referer], X-Content-Type-Options=nosniff, X-Frame-Options=SAMEORIGIN, X-XSS-Protection=0}, initialURL=https://www.googleapis.com/admin/directory/v1/users/ttestaccount#pps.net, statusCode=400.0, statusReason=Bad Request}
Full code:
Trying to follow the Google API reference here, though something wrong with my syntax:
https://developers.google.com/admin-sdk/directory/v1/reference/users#resource
I made a similar request using the Google OAuth Playground
This was the format of my request:
PATCH /admin/directory/v1/users/youremail#joshgoldeneagle.com HTTP/1.1
Host: www.googleapis.com
Content-length: 45
Content-type: application/json
Authorization: Bearer {REPLACE WITH ACCESS TOKEN}
{
recoveryEmail: "yourPatchEmail#joshgoldeneagle.com"
}
Ensure that callGoogleAPI() makes a request in this format.
References:
https://developers.google.com/admin-sdk/directory/v1/reference/users/patch
Lazarus 1.8.4
Indy 10 (March 2020)
Windows Server 2016
I'm trying to build a little "Dialer" module for a contact list I've built in Lazarus. After fiddling for months, I was finally able to translate all the RingCentral API settings into Postman, then into Indy HTTP settings, to accomplish obtaining a token. That part works reliably. However, I am unable to do a RingOut API. I always get 404 not found. The examples in other programming languages given by RingCentral in their docs don't translate well into Indy.
if htpCall.Connected then
htpCall.Request.Connection := 'close'; // Close the socket after using it to obtain the token
htpCall.Request.Clear;
htpCall.Request.Accept := 'application/json';
htpCall.Request.ContentType := 'application/json';
htpCall.Request.Username := '<redacted>'; // Client ID
htpCall.Request.Password := '<redacted>'; // Client Secret
htpCall.Request.CustomHeaders.Clear;
htpCall.Request.CustomHeaders.FoldLines := False;
htpCall.Request.BasicAuthentication := False;
htpCall.Request.CustomHeaders.AddValue('Authorization', 'Bearer ' + acc_tkn);
prms_lst.Add('from=<redacted>');
prms_lst.Add('to=<redacted>');
prms_lst.Add('callerId=<redacted>');
prms_lst.Add('country=Canada');
prms_lst.Add('playPrompt=true');
// Remove the text ".devtest" for the production version of your code, and replace the phone account with the real main phone number
htpCall.Post('https://platform.devtest.ringcentral.com/restapi/v1.0/account/<redacted>/extension/101/ring-out', prms_lst);
UPDATE:
If I leave the TIdHTTP open, then run the code above, I get a different error.
Sent:
POST /restapi/v1.0/account//extension/101/ring-out HTTP/1.1
Content-Type: application/json
Content-Length: 82
Authorization: Basic
Host: platform.devtest.ringcentral.com
Accept: application/json
User-Agent: Mozilla/3.0 (compatible; Indy Library)
from=&to=&callerId=&country=Canada&playPrompt=true
Rcvd:
HTTP/1.1 401 Unauthorized
Server: nginx
Date: Tue, 25 Aug 2020 01:50:24 GMT
Content-Type: application/json
Content-Length: 175
Connection: keep-alive
WWW-Authenticate: Bearer realm="RingCentral REST API"
RCRequestId: 57c97008-e675-11ea-87cf-005056bb81b6
{
"errorCode" : "AGW-402",
"message" : "Invalid Authorization header",
"errors" : [ {
"errorCode" : "AGW-402",
"message" : "Invalid Authorization header"
} ]
}
In our current WebAPI calls, only a few specific ones are returning the 405 error message (405 Method not allowed), the rest are working okay. The ones that are failing are only failing in a specific environment, in all the other environments all calls are returning 200 and everything is kosher.
Which IIS setting or system setting can cause this ? I am zooming in on this because this looks more like a systems/config issue.
Request URL : <hostname/GetAllStuff?userId=johndoe&sortByCustom=CreatedDate&sortByOrder=desc
Request Method: GET
Status Code: 405 Method Not Allowed
Remote Address: 172.72.78.33:443
Referrer Policy: no-referrer-when-downgrade
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Methods: GET,POST,PUT,DELETE,OPTIONS
Access-Control-Allow-Origin: *
Allow: GET,POST,DELETE,PUT
Cache-Control: no-cache
Content-Length: 136
Content-Type: application/json; charset=utf-8
Date: Tue, 06 Nov 2018 17:16:28 GMT
Expires: -1
The Response looks like this. What is strange is that ALL the API calls are 1.0 (api-version: 1.0) yet only a couple of calls throw this error and that too in a specific environment.
{
"Error": {
"Code": "UnsupportedApiVersion",
"Message": "The requested resource with API version '1.0' does not support HTTP method 'GET'."
}
}
I'm working on an API that would return an image. In case any error is encountered in the API, though I can issue a HTTP - 500 response (or similar error codes) with text content or no content at all, I need to be able to return an Image Content with the error represented inside the image itself. In other words, when any error is encountered, I create an image representation of the error text and return the image, with the http status code at as 500 - Internal Server Error. I'm using ASP.net Web API and I'm able to create a HTTP 500 Response with Image content and mime type as "image/jpg".
Http 500 with plain text response:
HTTP/1.1 500 Internal Server Error
Content-Length: 14
Content-Type: text/plain; charset=utf-8
Server: Microsoft-HTTPAPI/2.0
Date: Mon, 24 Jul 2017 06:43:55 GMT
Error Occured!
Http 500 with Image Content:
HTTP/1.1 500 Internal Server Error
Content-Length: 622485
Content-Type: image/jpg
Server: Microsoft-HTTPAPI/2.0
Date: Mon, 24 Jul 2017 06:44:56 GMT
<<ImageContent>>
Though it is possible, I need to know if this approach is OK as per the best practices of web API or not. Thanks.
Best-practice ("everybody does it") is to return HTML, with a Content-Type: text/html, even if the request was for an image.
You can refer to this site here
Below you can take look at piece of code from shared link:
var result = new HttpResponseMessage(HttpStatusCode.OK);
String filePath = HostingEnvironment.MapPath("~/Images/HT.jpg");
FileStream fileStream = new FileStream(filePath, FileMode.Open);
Image image = Image.FromStream(fileStream);
MemoryStream memoryStream = new MemoryStream();
image.Save(memoryStream, ImageFormat.Jpeg);
result.Content = new ByteArrayContent(memoryStream.ToArray());
result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/jpeg");
return result;
I'm trying to connect to Parse.com 's REST-API via NSURLConnection to track AppOpened metadata.
I get 200 OK back from the API and the headers are the same to the cURL headers but my API calls are not being represented in the data browser on Parse.com . Is NSURLConnection doing something silly I don't know of? API response is the same but one request gets represented while the other one isn't.
NSLog output:
<NSHTTPURLResponse: 0x7ff5eb331ca0> { URL: https://api.parse.com/1/events/AppOpened } { status code: 200, headers {
"Access-Control-Allow-Methods" = "*";
"Access-Control-Allow-Origin" = "*";
Connection = "keep-alive";
"Content-Length" = 3;
"Content-Type" = "application/json; charset=utf-8";
Date = "Sun, 04 Jan 2015 22:42:54 GMT";
Server = "nginx/1.6.0";
"X-Parse-Platform" = G1;
"X-Runtime" = "0.019842";
} }
cURL output:
HTTP/1.1 200 OK
Access-Control-Allow-Methods: *
Access-Control-Allow-Origin: *
Content-Type: application/json; charset=utf-8
Date: Sun, 04 Jan 2015 23:03:51 GMT
Server: nginx/1.6.0
X-Parse-Platform: G1
X-Runtime: 0.012325
Content-Length: 3
Connection: keep-alive
{}
It's the same output. What am I doing wrong? Has anyone experience with this?
Turns out Parse was showing funny API keys the moment I copied them out of the cURL example they provide in their lovely docs. Don't know whose analytics I screwed over but I'm terribly sorry and it wasn't my fault!
Always copy your API keys out of [Your-Parse-App-Name]->Settings->Keys
It probably was just a stupid glitch that happened on the Server.