How to retrieve Amazon Returned Item from MWS - amazon-mws

I try to get the returned items for every Orders, but unfortunately it dosen't seem to provide this kind of information from the Amazon Web Services.
public GetOrderResponse InvokeGetOrder()
{
// Create a request.
GetOrderRequest request = new GetOrderRequest();
request.SellerId = sellerId;
string mwsAuthToken = "";
request.MWSAuthToken = mwsAuthToken;
List<string> amazonOrderId = new List<string>();
amazonOrderId.Add("106-5297482-5403402");
request.AmazonOrderId = amazonOrderId;
return this.client.GetOrder(request);
}
The code above is to getting the Order Information for a specific Amazon Order ID.
Here is the result
<GetOrderResponse xmlns="https://mws.amazonservices.com/Orders/2013-09-01">
<GetOrderResult>
<Orders>
<Order>
<AmazonOrderId>asdfasdf</AmazonOrderId>
<SellerOrderId>asdfasdfas</SellerOrderId>
<PurchaseDate>07/17/2014 10:39:34</PurchaseDate>
<LastUpdateDate>07/17/2014 22:17:37</LastUpdateDate>
<OrderStatus>Shipped</OrderStatus>
<FulfillmentChannel>AFN</FulfillmentChannel>
<SalesChannel>Amazon.com</SalesChannel>
<ShipServiceLevel>SecondDay</ShipServiceLevel>
<ShippingAddress>
</ShippingAddress>
<OrderTotal>
<CurrencyCode>USD</CurrencyCode>
<Amount>53.18</Amount>
</OrderTotal>
<NumberOfItemsShipped>2</NumberOfItemsShipped>
<NumberOfItemsUnshipped>0</NumberOfItemsUnshipped>
<PaymentExecutionDetail />
<PaymentMethod>Other</PaymentMethod>
<MarketplaceId></MarketplaceId>
<BuyerEmail></BuyerEmail>
<BuyerName></BuyerName>
<ShipmentServiceLevelCategory>SecondDay</ShipmentServiceLevelCategory>
<OrderType>StandardOrder</OrderType>
<EarliestShipDate>07/17/2014 18:50:15</EarliestShipDate>
<LatestShipDate>07/17/2014 18:50:15</LatestShipDate>
</Order>
</Orders>
</GetOrderResult>
<ResponseMetadata>
<RequestId>asdfsadfasdfasdf</RequestId>
</ResponseMetadata>
</GetOrderResponse>
I know this order contains a returned item.
Thanks a lot.

You can try scheduling the transaction report from seller central because you can not request using MWS and whenever this report is ready you can retrieve it using "_GET_DATE_RANGE_FINANCIAL_TRANSACTION_DATA_" which does includes returned or refunded orders.

Related

Creating a Multi-Contact Event with Apex in Salesforce

I am attempting to use Apex to create a multi-contact event.
I have already enabled Allow Users to Relate Multiple Contacts to Tasks and Events in the activity settings in the scratch org.
I am following the guide and the example at the bottom of these docs but I am constantly getting an error when pushing to the scratch org:
// ...
event.setEventWhoIds(attendeeContactIds);
// ...
Method does not exist or incorrect signature: void setEventWhoIds(List<String>) from the type Event.
I also tried to write directly to the field with:
event.EventWhoIds = attendeeContactIds;
With that, I get the error, that the field is not writable.
attendeeContactIds is a List of Strings representing Contact IDs.
What could I be missing? 🤔🙇🏻‍♂️
It's bit stupid, it's readonly in apex. It's exposed so integrations can quickly create event and essentially a related list together in one all-or-nothing transaction. See also https://salesforce.stackexchange.com/questions/238094/eventwhoids-is-not-writeable-in-apex-class-but-working-on-jsforce
Try something like that?
Savepoint sp = Database.setSavepoint();
event e = new Event(
StartDateTime = System.now(),
EndDateTime = System.now().addHours(1)
);
insert e;
List<EventRelation> invitations = new List<EventRelation>();
for(Contact c : [SELECT Id FROM Contact LIMIT 5]){
invitations.add(new EventRelation(
EventId = e.Id,
RelationId = c.Id,
IsInvitee = true
));
}
insert invitations;
Database.rollback(sp); // unless you really want to send it out

RestFB: Getting list of users who liked a post

I need to get the name of each like on each post on a group page. Since I first have to get some data from the original post, I'm trying to make a connection then iterate through the likes and get a list of the users who liked each post. Here's what I have:
Connection<Likes> feedLikes = postFeed.fetchConnection(id+"/likes", Likes.class, Parameter.with("fields","from,actions,type"));
// Get the iterator
Iterator<List<Likes>> likeIt = feedLikes.iterator();
while(likeIt.hasNext()) {
List<Likes> likeFeed = likeIt.next();
for (Likes currLike: likeFeed) {
String ObjectId = id;
String LikeUserId = currLike.getId();
String LikeUserName = currLike.getName();
like_data.add(new String[] {ObjectId, LikeUserId, LikeUserName});
}
}
This doesn't work and I'm a little stuck on why. I know the username is stored in Likes.LikeItem but I can't even get to that step so far. Does anyone have any idea what I'm missing?
According to the Facebook reference this is not possible (https://developers.facebook.com/docs/graph-api/reference/v3.2/object/likes):
A User or Page can only query their own likes. Other Users'or Pages' likes are unavailable due to privacy concerns.
Only aggregated counts using total_count with the summary parameter are available for Post likes.

Ordering the solr search results based on the indexed fields

I have to order the search results from solr based on some fields which are already indexed.
My current api request is like this without sorting.
http://127.0.0.1:8000/api/v1/search/facets/?page=1&gender=Male&age__gte=19
And it gives the search results based on the indexed order. But I have to reorder this results based on the filed 'last_login' which is already indexed DateTimeField.
Here is my viewset
class ProfileSearchView(FacetMixin, HaystackViewSet):
index_models = [Profile]
serializer_class = ProfileSearchSerializer
pagination_class = PageNumberPagination
facet_serializer_class = ProfileFacetSerializer
filter_backends = [HaystackFilter]
facet_filter_backends = [HaystackFilter, HaystackFacetFilter]
def get_queryset(self, index_models=None):
if not index_models:
index_models = []
queryset = super(ProfileSearchView, self).get_queryset(index_models)
queryset = queryset.order_by('-created_at')
return queryset`
Here I have changed the default search order by 'created_at' value. But for the next request I have order based on the 'last_login' value. I have added a new parameter in my request like this
http://127.0.0.1:8000/api/v1/search/facets/?page=1&gender=Male&age__gte=19&sort='last_login'
but it gives me an error
SolrError: Solr responded with an error (HTTP 400): [Reason: undefined field sort]
How can I achieve this ordering possible? Please help me with a solution.
The URL you provided http://127.0.0.1:8000/api/v1/search/facets/ is not direct SOLR URL. It must be your middle-ware. Since you have tried the query directly against Solr and it works, the problem must be somewhere in middle-ware layer.
Try to print or monitor or check logs to see what URL the midde-ware actually generates and compare it to the valid URL you know works.

How to apply a condition to a specific table in every request on Entity Framework?

I have a many-to-many structure mapped to entity framework. This is a sample of what it looks like:
User UserTag Tag
------- -------- -------
IdUser(PK) IdUserTag(PK) IdTag(PK)
Name IdUser(FK) TagName
Desc IdTag(FK) Active
Now, I needed to exclude from any request of any method the viewing of Tags that were Active=false.
First, I tried doing it manually in every method, like:
public User GetById(int id)
{
var item = UserRepository.GetById(id); //This is just a repository that calls the EF context
//EF automatically maps it to the *UserTags* property
foreach(var tag in item.UserTags)
{
if(tag.Tag.Active == false)
item.UserTags.Remove(tag);
}
}
But it throws the following exception:
The relationship could not be changed because one or more of the foreign-key properties is non-nullable
So, I wanted to know if there's a way to conditionaly filter every request made to a specific table, whether it is select or a join request.
Try this in your GetById method:
var user.UserTags = dbContext.Entry(user)
.Collection(u => u.UserTags)
.Query()
.Where(ut => ut.Active == true)
.ToList();
The supplied code fails because it is attempting to remove items from the data entities not the list. If you want to pass the data entity around instead of the data model, you need to not use Remove. Something like the below (untested should work).
tags = item.UserTags.Where((ut) => ut.Active).ToList();
This line will get you a list of data entities that are active. However, you should really map all of this into a data model (see AutoMapper) and then you would not be removing items from the database.

How to get Entry Id for a Newly Created Entity in Breeze

i want to create a registration form that will be in batch with a continuation button, getting the id of the entry will help me to call the save method.
I want to immediately get the primary key of a new Entry Created using BreezeJS, Pls i need help on this.
Thanks
Not entirely sure I understand your question, but it sounds like you want to get the id of a newly saved record immediately after the save. If so then the answer below applies.
When the save promise resolves it returns both the list of saved entities as well as a keyMappings array for any entities whose ids changed as a result of the save. i.e. a mapping from temporary to real ids. i.e. (Documented here: http://www.breezejs.com/sites/all/apidocs/classes/EntityManager.html#method_saveChanges)
myEntityManager.saveChanges().then(function (saveResult) {
// entities is an array of entities that were just saved.
var entitites = saveResult.entities;
var keyMappings = saveResult.keyMappings;
keyMappings.forEach(function(km) {
var tempId = km.tempValue;
var newId = km.realValue;
});
});
On the other hand if you have an entity and you just want its 'key' you can use the EntityAspect.getKey method. (see http://www.breezejs.com/sites/all/apidocs/classes/EntityAspect.html#method_getKey)
// assume order is an order entity attached to an EntityManager.
var entityKey = order.entityAspect.getKey();

Resources