I'm trying to implement a domain search in our website, but I have no clue how... the WHOIS service I registered by, gave me an API key to use... When I use the following address in my browser's url,
http://api.robowhois.com/v1/availability/example.com
a login box appears, asking me for my username and password, when I type in my username and password which is the key they gave me, a page appears with the following
{
"response": {
"available": false
}
}
I'm sorry to say, but I've been searching for weeks on how to solve this but at the end my last resort was to turn to stack overflow... can someone please help, is there a way on how to use and call the url and use the info?
You already got the information you need. It responds with a JSON object saying it's not available.
To retrieve the information as you wish, you can use Jquery, just put your URL in a function as in the examples and get data.response.available value and assign it to your textbox etc. For more information how to make JSON calls and parse them, check out this documentation in Jquery website.
RoboWhois is a web service that provides an API suite to access WHOIS
records and domain related information with a unified, consistent
interface. Using RoboWhois API you can retrieve WHOIS details parsed
as convenient JSON structure.
In order to check the availability of a given domain you have to send a http get request to the robowhois api http://api.robowhois.com/v1/availability/example.com
The server does answer the request by sending http response containing json which looks like this:
{
"response": {
"available": false
}
}
which means the domain is no longer available.
In order to use the information contained in the json response you should deserialize the json object to a c# object. You can do this for example with the json.net library.
Here is a small example from the documentation on how to use json.net to deserialize a json:
Product product = new Product();
product.Name = "Apple";
product.ExpiryDate = new DateTime(2008, 12, 28);
product.Price = 3.99M;
product.Sizes = new string[] { "Small", "Medium", "Large" };
string output = JsonConvert.SerializeObject(product);
//{
// "Name": "Apple",
// "ExpiryDate": "2008-12-28T00:00:00",
// "Price": 3.99,
// "Sizes": [
// "Small",
// "Medium",
// "Large"
// ]
//}
Product deserializedProduct = JsonConvert.DeserializeObject<Product>(output);
Related
I am working with Stripe/Stripe.net Webhooks in my ASP.Net Core app. I am trying to map an object where I can use the properties returned from the Webhook JSON response and save various properties into my database. Using Postman, I am able to receive the sample JSON that I got from Stripe test webhooks in my Controller method and parse the JSON using
var json = await new StreamReader(HttpContext.Request.Body).ReadToEndAsync();
Event stripeEvent = EventUtility.ParseEvent(json);
which returns:
stripeEvent = {<Stripe.Event#2269235 id=evt_00000000000000> JSON: {"id": "evt_00000000000000", "object": "event", "account": null, "api_version": "2020-03-02", "created": 1326853478, "data": { "object": { "id": "ch_00000000000000", "...
I am needing to map the JSON from the RawObject ChildrenTokens into a model but I'm not able to access the ChildrenTokens through C#. Is there any way to be able to map these properties?
The trick here is to cast the stripeEvent.Data.Object as the specific class that the underlying event data should represent. Typically, you'll have a switch or if statement checking the stripeEvent.Type.
For instance, if the type of the event is payment_intent.succeeded, then the underlying data would be a PaymentIntent and you might have the following code to check the type, then cast to that type.
if (stripeEvent.Type == Events.PaymentIntentSucceeded)
{
var paymentIntent = stripeEvent.Data.Object as PaymentIntent;
}
From there, you can interact with the paymentIntent and it's related properties.
While I've been developing in Dynamics for awhile, I have never had to do an external call to an API before.
I'm not sure where to start. Any help in pointing me in the right direction would be very helpful.
The Api in question is located here:
http://apidocs.assess.com/
There are examples within there that show what needs to get passed to the url (https://app.fasttestweb.com/FastTest/api/swagger.json)
But in all honesty, this is my first attempt at this and I'm overwhelmed with the information I've been finding, and having trouble parsing through what needs to be done for this.
Step 1, of course is to generate an auth token from the site.
This needs to be passed in this formation (I assume that is JSON).
But I'm having trouble figuring out how to even do that part, or what the code should even look like. If anyone has an example of something they've done, or can point me to a link/video that walks through this, that would be awesome.
Note, I do have Newtonsoft.Json installed in Visual Studio, but I'm having trouble finding good examples on how to actually pass the information back and forth.
Thank you in advance.
How to call an API in rest is a really common practice as a developer since this is common practice to expose data, i highly recommend that you read up on the subject, there are alot of good resources out there, this site is one and youtube is another, did a quick search and found alot about it: https://www.youtube.com/results?search_query=intro+to+rest+c%23
To the problem at hand:
The swagger documentation tells you all you need to know to call the service your after,
Take the auth service for example, first of we need to know which method the service uses, in this case it is post.
Now we need to know which address we can call the service. Specified in the docs as: https://app.fasttestweb.com/FastTest/api/auth/simple
What are we sending:
{
"username": "string",
"pwd": "string",
"apiKey": "string",
"timeSent": 0,
"tokenTTL": 0
}
if you switch to model you can see the description of the parameters. You can even test this out directly in the page by editing the editable box with the values you were given and pressing "try it out!" in the bottom of the endpoint specification.
What response are we getting:
{
"apiToken": "string",
"timeGenerated": 0,
"ttl": 0
}
To call it, there are many ways to do this, i like to make separate objects/dto's of what im sending and recieving and then serialize/deserialize them from and to that object. Since you already have json.net here is how you do serialize.
You can specify the specific json names so it matches with the schema with an attribute
or define a strategy.
When you get the json back from the service you will have to deserialize it.
So your body obj would look like this for example
public class AuthBody
{
[JsonProperty("username")]
public string UserName { get; set; }
[JsonProperty("pwd")]
public string Password { get; set; }
[JsonProperty("apiKey")]
public string ApiKey { get; set; }
[JsonProperty("timeSent")]
public int TimeSent { get; set; }
[JsonProperty("tokenTTL")]
public int TokenTimeToLive { get; set; }
}
Just setup the response in similar fashion.
I like to use a lib called RestSharp to call rest services, its available on nuget.
Here is a very basic code example (not tested):
var body = new AuthBody()
{
UserName = "value",
Password = "value",
ApiKey = "value",
TimeSent = 123,
TokenTimeToLive = 10000
};
var json = JsonConvert.SerializeObject(body);
var client = new RestClient("https://app.fasttestweb.com/FastTest/api");
var request = new RestRequest("auth/simple", Method.POST, DataFormat.Json);
request.AddParameter("application/json", json, ParameterType.RequestBody);
var jsonResponse = client.Execute(request);
AuthResponse authResponse = JsonConvert.DeserializeObject<AuthResponse>(jsonResponse.Content);
You can also set the default serializer of restsharp to json.net if you want, then you can set the body with addJsonBody instead of the parameter and you dont have to serialize your object yourself, more info is available on RestSharp.
if you dont want to use RestSharp, the normal client is called HttpClient instead of RestClient, if you want to google it.
Hope it helps.
I need your help how do i go to the next data and follow them, the json is below
"paging": {
"cursors": {
"before": "QVFIUkpHTGJjc2RVTDY5YUpnb240dEdCbTVKZAGNhZAjJSNmY0TzJVRWhNcXk4eVROVU5nRzJUWFFuS1dZAMDhhVFNHMEJ6X0ZAqQTlHMmlfRk9ISHo0Qkw3MTdn",
"after": "QVFIUlFsWXF0OUJLVXdkb0Y3TXBhVG5LVUxCeVN1ZAjhoeVNudkdHXy1tZAWZAOTW1DbzZAIOTJmNGw1RjlKS3liYXJJdWtKMXAtQXNHM0NjVGIzN1JnY3hVTFVB"
},
"next": "https://graph.facebook.com/v1.0/1512513832114020/members?access_token=token&pretty=1&fields=name&limit=100&after=QVFIUlFsWXF0OUJLVXdkb0Y3TXBhVG5LVUxCeVN1ZAjhoeVNudkdHXy1tZAWZAOTW1DbzZAIOTJmNGw1RjlKS3liYXJJdWtKMXAtQXNHM0NjVGIzN1JnY3hVTFVB",
"previous": "https://graph.facebook.com/v1.0/1512513832114020/members?access_token=token&pretty=1&fields=name&limit=100&before=QVFIUkpHTGJjc2RVTDY5YUpnb240dEdCbTVKZAGNhZAjJSNmY0TzJVRWhNcXk4eVROVU5nRzJUWFFuS1dZAMDhhVFNHMEJ6X0ZAqQTlHMmlfRk9ISHo0Qkw3MTdn"
}
Its facebook graph api, so after the extract done, its move to next page until data empty.
in C#, you must use newtonsoft.dll to process data of JSON.
You can download at: https://www.newtonsoft.com/json
On the Slack website, I can format a message like this:
{
"text": "<http://google.com|link to google>"
}
And in the message it will appear like this:
link to google
But I am trying to write a bot and those links aren't working. Using my websocket connection I can send a message like this:
var send = new MessageToSlack()
{
type = "message",
channel = msg.channel,
text = $"http://google.com"
};
ws.SendAsync(JsonConvert.SerializeObject(send), b => { });
And Slack will correctly interpret http://google.com as a link and display it like:
http://google.com
But if I try to send a message with the link in angle brackets with the pipe between the link and the link text (which works on Slack's site) like this:
var send = new MessageToSlack()
{
type = "message",
channel = msg.channel,
text = $"<http://google.com|to google>"
};
ws.SendAsync(JsonConvert.SerializeObject(send), b => { });
I end up with:
<http://google.com|to google>
So how do I get this working from my bot? Why is it not able to parse by links correctly? What am I missing?
As far as I can see from the docs, this should work. Here in the section on formatting messages it says:
The RTM API only supports posting simple messages formatted using our default message formatting mode.
And links to here which does mention links with the pipe character, so I think it should work.
(note MessageToSlack is just an ordinary .NET class with type, channel and text properties that gets serialized by JSON.Net and appears to give the correct JSON. ws is my websocket connection from the WebSocketSharp nuget package)
JSON:
{
"id": 1,
"type": "message",
"channel": "C6QRKT0EA",
"text": "<http://google.com|to google>"
}
Edit: So it seems if I switch from replying with the web socket connection and instead post to https://slack.com/api/chat.postMessage, it will work correctly, but it's a bit more fiddly to use and the documentation led me to believe that the links should work without needing to jump through that particular hoop. Am I just misreading the docs? Or are docs just not very clear on this point?
Try to enable markdown support by adding "mrkdwn": true to your json
{
"type": "message",
"channel": "C6QRKT0EA",
"text": "<http://google.com|to google>",
"mrkdwn": true
}
Read Message Formatting section. Hope it will help.
We are using the GMail Api in a C# application, and have received a message with an embedded image.
You can see the image if you look at the GMail account (in a browser as a user) but I am unable to find it either in the Payload or get an attachment id when I use the api.
Does the api even support accessing embedded images?
If I use:
var part = message.Payload.Parts
.Where(x => x.MimeType.Equals(mimeType))
.Select(x => x.Body.Data)
.FirstOrDefault();
With the Mime type set to Gif,Jpeg or Tiff it always comes back null;
You might want to check the - Users.messages: get
Gets the specified message.
To be familiar on the structure specially when reading the email message Resource representations. I used the Try it now to get the Users.messages resource in the response body and how it will be formed.
When checking the email, the embedded image will fall in the payload.
........
{
"partId": "1",
"mimeType": "image/png",
"filename": "pasted1",
"headers": [
{
"name": "Content-Type",
"value": "image/png; name=pasted1"
},
.........
This is how it should look like.
Hope this helps.