Wiremock.Net query parameter with SOQL Query - c#

I'm using WireMock-Net for stubbing requests.
I want to do the following request:
Request:
http://localhost:63078/services/query/?q=SELECT Id from User where username='user#gmail.com'
The request is composed by a SOQL Query.
Here's a snippet of what I tried to do:
stub.Given(Request.Create()
.WithPath("/services/query/")
.WithParam("q", "SELECT Id from User where username='user#gmail.com'")
.UsingGet())
.RespondWith(Response.Create()
.WithStatusCode(200)
.WithHeader("Content-Type", "application/json")
.WithBodyAsJson(new { Id = "5bdf076c-5654-4b3e-842c-7caf1fabf8c9" }));
The problem is: wiremock always replies with a 404. I've also tried using the RegexMatcher, like so:
.WithPath("/services/query/")
.WithParam("q", new WireMock.Matchers.RegexMatcher("SELECT Id from User where username.*$"))
But I still got a 404.
I think the problem is in the query parameter, because it has two equals "=".
Can someone help me solve this?

This has been fixed in the latest version (1.0.19) from WireMock.Net
Please retry and mark this answer as accepted if it works correctly for you.
Details: the solution is based on Get url parameters from a string in .NET

You could try to do the url encode.
So when you are doing
SELECT Id from User where username='user#gmail.com'
you should be doing
SELECT %20Id%20from%20User%20where%20username%3D%27user%40gmail.com%27
Hope it helps.

Related

Hot to put with httpclient? Rest(ish) API

I'm working with the pipedrive API and trying to update a record (deal, but the endpoint isn't important). The format of the is as follows.
https://companyDomain.pipedrive.com/api/v1/deals/DealID?api_token=API-Token
Where companydomain specifies your account with them, dealID is the ID we're updating and API token is the token supplied by pipedrive to access the API. It's not a token that's returned by logging in, it's static one, given on day one and never changes.
HttpClient seems to want a base address so "https://companyDomain.pipedrive.com/", then something like the following:
HttpResponseMessage response = await client.PutAsJsonAsync(
$"api/v1/deals/{dealId}/", args);
Where args is a class with the field/s and value/s I want to update.
If I include the api_token as fields in "args", it returns a 404 not found. If I append it to the base url or the $api/v1/deals/{dealID}/ it returns permission denied.
Any suggestions as to how I can handle this?
I've managed to make a living coding for 30 years avoiding the web, now it's all anyone seems to want. Appears I have to finally get a handle on this, hence the recent questions! ;-)
Thanks in advance
Jim
Append it with a "?"
So your URL should look like api/v1/deals/YOUR_ID?api_token=THE_TOKEN
HttpResponseMessage response = await client.PutAsJsonAsync(
$"api/v1/deals/{dealId}?api_token={apiToken}", args);

Pass parameters to Get request on swiftUI

I'm having trouble with passing in parameters to a get request. This request is intended to return a list of warehouses after the user entered some search parameters such as Date, State, ZIP and/or warehouse number, which is the only mandatory field. So when the search button is pressed the query is executed, but im getting this error:
2021-04-19 15:49:00 +0000
2021-11-02 13:06:44.670511-0600 WAREHOUSE_IOS-Master[3142:186324] GET method must not have a body
2021-11-02 13:06:44.670799-0600 WAREHOUSE_iOS-Master[3142:186324] Task <C7839029-C527-490E-8747-137012285F14>.<3> finished with error [-1103] Error Domain=NSURLErrorDomain Code=-1103 "resource exceeds maximum size" UserInfo={NSLocalizedDescription=resource exceeds maximum size,
error: invalidResponse
Okay so what im doing is passing a body to the get request that includes the search parameters as such:
struct WarehouseBody : Codable {
let dateRegistration : String?
let state : String?
let zip : String?
let warehouseNumber : String
}
and I'm expecting a response of this type:
struct WareHouseResponse: Codable {
let status: String?
let code: Int?
let responseCode, message: String?
let error: Bool?
let errorMessage: String?
let result: Result?
enum CodingKeys: String, CodingKey {
case status = "Status"
case code = "Code"
case responseCode = "ResponseCode"
case message = "Message"
case error = "Error"
case errorMessage = "ErrorMessage"
case result = "Result"
}
}
but according to what I've reading on other posts this is not the correct way of using a get request, but I really really need to do some testing. Is there a way that I can achieve this without needing to alter the backend? Just to mention that I ´m also the developer of the backend (c# using .net framework and dapper)so if the easiest way is to achieve this is by altering it I can also do that. Any ideas are very much appreciated.
On the backend I was thinking of implementing a post Request that sends the search parameters to the server and then a get request that pulls out the requested information, but I don't know if that's the correct approach. But this not feasible at the moment because the Web API are already publish and I cannot re publish with the changes at the moment, and is really urgent to test the response so that's why I would like to know if all this can be done from the front end first. Thank you very much for all the help!
Thank you very much for your help!
EDIT: Also I forgot to mention that the api has been previously tested on POSTMAN and is working perfectly.
Since iOS 13. you cannot pass in parameters to a GET request. There’s no easy way around this. You need to change your request from a GET to a POST on the backend. In my case, this was an easy task because I had access to the API source— but, if you don’t, just ask the backend team to change it, and pass in the parameters as in any other POST request. That should work.

Google Classroom - Get Course by Alias

I'm trying to get a Google Classroom Course in C# using its Project Alias.
On the API Documentation page I can get the course no problem using ID or Alias.
For talking sake, let's say:
ID - 123456
Alias - p:abc
When I try on the Documentation page I get a 200 response and retrieve the course when I use either of the above.
However, when in code I can only get the course using the ID. When I try to do it using the alias I get the following error: 404 course not found.
var id= "123456";
var alias = "p:abc";
var request = classroomService.Courses.Get (id);
var course = request.Execute(); //200 response, course is the JSON course
request = classroomService.Courses.Get(alias);
course = request.Execute(); //404 - COURSE NOT FOUND
Not sure if I have to somehow specify the request is using a project-alias but I can't seem to see any options within the request to suggest this.
Thanks
EDIT: Just to add to this, I have tested using a domain alias,
alias - "d:xyz"
This works fine in code, so it appears it is just the project wide alias that isn't working.
As the documentation says, project aliases are visible only by the same project id that created them.
A project-scoped alias is visible to any request from an application using the Developer Console project ID that created the alias and can be created by any project.
Since the project ID used to create the aliases is different from the one used to call the .get() method it will return a 404 - Course Not Found error.

Cannot include user-agent into my headers

I'm currently trying to send a post request with a user agent however I get errors every time I try to use a user agent. Please may someone help?
I've already tried:
request.Headers.Add("User-Agent", "{My user agent}");
I get this error when I try to use the code above:
System.ArgumentException: 'The 'User-Agent' header must be modified using the appropriate property or method.
Parameter name: name'
Thanks in advance
Use the HttpRequestHeader.UserAgent instead of a string "User-Agent". That'll fix it.

androidpublisher api google authorname empty

I have been testing the google api to get the comments of my android application in google play and it always returns me the empty authorname, do I need some other permission? I put the json of what returns me.
Thank you!
I suspect this is an issue with fields
var request = service.Reviews.List ("my.app");
request.Fields = "*";
var results = request.ExecuteAsync() ;
I don't have access to that api so the code is an educated guess give it a try let me know if it doesn't work. Try testing it here as well Google APIs explorer.
Update 1:
I have one last guess try running a Reviews.Get request after your review.list maybe the name isn't return in the list it should be though.
var request = service.Reviews.Get("my.app",reviewIdFromListRequest);
request.Fields = "*";
var results = request.ExecuteAsync() ;
If this doesn't work i say we log it as a bug.
Update 2:
apparently its a documented bug
Found in this documentation page reviews

Categories

Resources