I created a windows form app and have been looking for a way to pass authentication to connect to the server and retrieve product information.
Couldn't find any examples anywhere. Can someone help me?
Here is the api link.
If you check out this link you might get everything you need:
https://github.com/nickvane/Magento-RestApi/wiki/Authentication-steps
Usage of the library can be found here:
https://github.com/nickvane/Magento-RestApi
(just scroll down a bit)
So in order to authenticate your code, you can use:
var client = new MagentoApi()
.Initialize("http://www.yourmagentourl.com", "ConsumerKey", "ConsumerSecret")
.AuthenticateAdmin("UserName", "Password");
or the other variants that exist in the last above link.
Please use the code below. I think it will help you
var client = new MagentoApi()
.SetCustomAdminUrlPart(AdminUrlPart)
.Initialize(StoreUrl, ConsumerKey, ConsumerSerect)
.AuthenticateAdmin(AdminUserName, AdminPassword);
var filter = new Magento.RestApi.Models.Filter();
//filter.FilterExpressions.Add(new FilterExpression("name", ExpressionOperator.like, "L%"));
filter.PageSize = 100;
filter.Page = 0;
// var response = await client.GetProducts(filter);
var sCode = Task.Run(async () => await client.GetProducts(filter));
MagentoApiResponse<IList<Magento.RestApi.Models.Product>> product = sCode.Result;
Related
Attempting this on .NET Core 3.1
After several hours of trying to publish a photo to my public facebook page (as in business page) of which I am the admin and have a long-term token for...
I keep getting the following response to my request using the official Facebook SDK for .NET. However, the image itself is never loaded.
{{"id":"786692942226147","post_id":"113260773923227_786692942226147"}}
The request looks like
var imageMedia = new FacebookMediaObject { FileName = file.FileName, ContentType = file.ContentType };
var stream = file.OpenReadStream();
var bytes = await stream.ReadAsByteArrayAsync();
imageMedia.SetValue(bytes);
var fbClient = new FacebookClient(credential.Token)
{
AppId = _config.GetValue<string>("FacebookClientId"),
AppSecret = _config.GetValue<string>("FacebookSecret")
};
dynamic parameters = new ExpandoObject();
parameters.message = request.Message;
parameters.file = imageMedia;
var result = await fbClient.PostTaskAsync($"{credential.PageId}/photos", parameters, token);
I'm sure it has something to do with the parameters I'm passing in, like parameters.file... but the docs for this thing are VERY unclear... as in "literally does not exist"
Anyone with experience getting this working, please point me in the right direction?
The solution is to change parameters.file to parameters.image...
Using the Azure DevOps REST API in C#, I'm creating a pull request and then attempting to complete it like this (simplified):
var pullRequest = new GitPullRequest {
Title = "My PR",
SourceRefName = "refs/heads/my",
TargetRefName = "refs/heads/master",
Commits = commits
};
pullRequest = await gitClient.CreatePullRequestAsync(pullRequest, repositoryId);
await Task.Delay(3000);
if (pullRequest.MergeStatus == PullRequestAsyncStatus.Succeeded) {
var pr2 = new GitPullRequest
{
LastMergeSourceCommit = pullRequest.LastMergeSourceCommit,
Status = PullRequestStatus.Completed
};
var result = await gitClient.UpdatePullRequestAsync(pullRequest, pullRequest.Repository.Id, pullRequest.pullRequestId);
}
This works fine if there's no conflicts. But if the pull request has conflicts, MergeStatus will be Conflicts. Now, let's assume someone resolves those conflicts manually and the PR is ready to be merged.
After resolving conflicts I get the pull request again
var pullRequest = await gitClient.GetPullRequestByIdAsync(pullRequestId);
pullRequest.MergeStatus is still Conflicts, even though UI is showing green.
Is there a way to refresh MergeStatus once it has been set to Conflicts? I tried updating the pull request by setting MergeStatus to Queued. Or is it a missing feature in the API?
Hopefully you got through this, so just in case someone else comes looking (like I did today) this worked for me.
var prOriginal = gitClient.CreatePullRequestAsync(
new GitPullRequest() {
SourceRefName = $"refs/heads/{Input.SrcBranch}",
TargetRefName = $"refs/heads/{Input.TgtBranch}",
Title = Input.Title,
Description = Input.Description
},
tgtRepo.Id).Result;
Thread.Sleep(TimeSpan.FromSeconds(30));
var statusRetry = 0;
var prTest = gitClient.GetPullRequestAsync(
tgtRepo.Id,
prOriginal.PullRequestId).Result;
while(PullRequestAsyncStatus.Succeeded != prTest.MergeStatus) {
// TODO decide when to quit.
Thread.Sleep(TimeSpan.FromSeconds(30));
prTest = gitClient.GetPullRequestAsync(
tgtRepo.Id,
prOriginal.PullRequestId).Result;
}
Debug.WriteLine($"MergeStatus: {prTest.MergeStatus}");
MergeStatus came back succeeded soon after I resolved the problems online. Now if I can get those conflicts resolved using the api I'll be in great shape.
I'm using C# and Bot Framework SDK4 and need to get the user email from a 1:1 chat with my bot. Is it possible? All I can seem to get is ID and full name.
I have tried the things listed here https://learn.microsoft.com/en-us/microsoftteams/platform/concepts/bots/bots-context
but the teamsContext is just returning null.
ITeamsContext teamsContext = turnContext.TurnState.Get<ITeamsContext>();
string incomingTeamId = teamsContext.Team.Id;
string incomingChannelid = teamsContext.Channel.Id;
string incomingTenantId = teamsContext.Tenant.Id;
So is it even possible to get the user email from the current user chatting with the bot?
You can! Per the docs, you just do the same as if you were getting the team roster, but use the conversation id, instead. For example:
var credentials = new MicrosoftAppCredentials("<yourAppId>", "<yourAppPassword>");
var connector = new ConnectorClient(new Uri(turnContext.Activity.ServiceUrl), credentials);
var conversationId = turnContext.Activity.Conversation.Id;
var userInfo = await connector.Conversations.GetConversationMembersAsync(conversationId );
Note: I tried using the Microsoft.Bot.Connector.Teams package to do this, but couldn't get it to work. Had to use the connector method above.
Private async Task GetUserProfile(TurnContext context,CancellationToken cancellationToken)
{
BotFrameworkAdapter botAdapter = (BotFrameworkAdapter)context.Adapter;
var conversation = await botAdapter.GetConversationMembersAsync(context, cancellationToken);
}
You can visit - How get user email from MS Teams with a Bot using SDK4?
As per the docs, to send an SMS for single number, we need not create SNS topic.
Clearly, they have given a sample code which shows we can set phone number for publish request method
http://docs.aws.amazon.com/sns/latest/dg/sms_publish-to-phone.html
As per the java docs, I can clearly see that method.
http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/sns/model/PublishRequest.html#setPhoneNumber-java.lang.String-
But, how do we implement same in c#? I couldn't find any method to send an sms without creating an SNS topic.
Can someone guide me how do I send an SMS without creating an SNS topic from C# SDK?
I hope this helps:
var smsAttributes = new Dictionary<string, MessageAttributeValue>();
MessageAttributeValue senderID = new MessageAttributeValue();
senderID.DataType = "String";
senderID.StringValue = "mySenderId";
MessageAttributeValue sMSType = new MessageAttributeValue();
sMSType.DataType = "String";
sMSType.StringValue = "Promotional";
////MessageAttributeValue maxPrice = new MessageAttributeValue();
////maxPrice.DataType = "Number";
////maxPrice.StringValue = "0.1";
CancellationTokenSource source = new CancellationTokenSource();
CancellationToken token = source.Token;
smsAttributes.Add("AWS.SNS.SMS.SenderID", senderID);
smsAttributes.Add("AWS.SNS.SMS.SMSType", sMSType);
////smsAttributes.Add("AWS.SNS.SMS.MaxPrice", maxPrice);
PublishRequest publishRequest = new PublishRequest();
publishRequest.Message = vm.Message;
publishRequest.MessageAttributes = smsAttributes;
publishRequest.PhoneNumber = vm.PhoneNumber;
AmazonSimpleNotificationServiceClient client = new AmazonSimpleNotificationServiceClient(vm.AccessKey, vm.SecretKey, config);
AmazonSNSResponse resp = new AmazonSNSResponse();
await client.PublishAsync(publishRequest);
AmazonSNSResponse response = new AmazonSNSResponse();
response.Status = HttpStatusCode.OK.ToString();
response.Message = "Success";
return response;
I believe you'll find the answer here: https://forums.aws.amazon.com/thread.jspa?threadID=250183&tstart=0
Basically what is saying and quote: "...PhoneNumber property was added in version 3.1.1.0 of AWSSDK.SimpleNotificationService..."
I haven't put example code since the PhoneNumber property is what is missing in the request, the rest should work as similar to Java Example :D.
See Publish(PublishRequest).
Amazon.SimpleNotificationService.Model.PublishRequest has a PhoneNumber property, used for setting the number when sending a direct SMS message.
I am using the Google C# API for the Custom Search and have it working and returning results, however I cannot see a way to make the paging work correctly.
Looking at what I get returned, no where does it tell me how many pages there are in the result? It just has a .Start property? Which is not much good unless I know how many 'pages' of results I have?
Am I missing something stupid here? Here is an example of the code I have so far
var svc = new CustomsearchService(new BaseClientService.Initializer { ApiKey = settings.GoogleCustomSearchApi });
var listRequest = svc.Cse.List(searchTerm);
listRequest.Cx = settings.GoogleCustomSearchEngineId;
listRequest.ImgSize = CseResource.ListRequest.ImgSizeEnum.Medium;
listRequest.Num = 10;
// List to hold everything in
var resultItems = new List<Google.Apis.Customsearch.v1.Data.Result>();
// Result set 1
listRequest.Start = 1;
var search = listRequest.Execute();
resultItems.AddRange(search.Items);
I have resulted at the moment to doing two or three calls one after the other and getting a load of results back. But I would prefer to have this properly paged.
The JSON API response has totlResults field:
https://developers.google.com/custom-search/json-api/v1/reference/cse/list#response.
It should be exposed under search.Queries
Found it, its in
search.SearchInformation.TotalResults