ProductProjectionByKeyGet not retrieving Channel Reference by Key - commercetools

When getting product details by product key from commercetools, The response that I get does not have the Channel Key as channelId but instead I get a random UUID (I believe the reference id).
final ProductProjectionByKeyGet productProjectionByKeyGet =
ProductProjectionByKeyGet.of(productKey, ProductProjectionType.CURRENT)
.withExpansionPaths(product -> product.allVariants()
.attributes().valueSet());
return clientManager.getClientForProjectKey(ctAdapterProperties, projectKey)
.execute(productProjectionByKeyGet).toCompletableFuture().get();
In the response after getting product details, If we take a look into the property prices[].channel.id the value for it is a UUID but inside the commercetools, I have the channel key as a string like: <store>-<online>
prices={PriceDraftDsl[
channel=Reference{
typeId='channel',
id='b5c57a89-4f18-41eb-b5c3-e0de1c09cf81',
obj=null},
country=<null>,
custom=<null>,
customerGroup=<null>,
tiers=<null>,
validFrom=<null>,
validUntil=<null>,
value=USD 12]}
When I tried to do ProductSync with the above prices, I got the following error exception.
ReferenceResolutionException: Failed to resolve 'channel'
reference on PriceDraft with country:'null' and value: 'USD 12'.
Reason: Channel with key 'b5c57a89-4f18-41eb-b5c3-e0de1c09cf81'
does not exist.
Is there any way I can get the channel's key instead of a random UUID for channelId? and if not, Can I maybe get the channel details by using this ID?
I am currently using version 1.7.0 for commercetools-sync-java package.
I'm pretty new at this. Any help on this is deeply appreciated.
Thanks in advance!

Unfortunately, The product price does not contain channel key only a channel id.
The sync java library does provide channel key resolution and so it expects that your price draft will contain the key.
https://github.com/commercetools/commercetools-sync-java/blob/master/docs/usage/PRODUCT_SYNC.md#syncing-from-an-external-resource
Does that help?
Best Regards
Brian
You might also consider using the Import API
https://docs.commercetools.com/tutorials/import-and-export#import-api

Related

making discord bot command to store message content (python)

So this is my first time coding an actual project that isn't a small coding task. I've got a bot that runs and responds to a message if it says "hello". I've read the API documentation up and down and really only have a vague understanding of it and I'm not sure how to implement it.
My question right now is how would I go about creating a command that takes informationn from a message the command is replying to (sender's name, message content) and stores it as an object. Also, what would be the best way to store that information?
I want to learn while doing this and not just have the answers handed to me ofc, but I feel very lost. Not sure where to even begin.
I tried to find tutorials on coding discord bots that would have similar functions to what I want to do, but can't find anything.
Intro :
Hi NyssaDuke !
First of all, prefer to paste your code instead of a picture. It's easier for us to take your code and try to produce what you wish.
In second, I see an "issue" in your code since you declare twice the bot. You can specify the intents when you declare your bot as bot = commands.Bot(command_prefix="!", intents=intents)
Finally, as stated by #stijndcl , it's against TOS, but I will try to answer you at my best.
filesystem
My bot needs to store data, like users ID, language, and contents relative to a game, to get contacted further. Since we can have a quite big load of requests in a small time, I prefered to use a file to store instead of a list that would disappear on crash, and file allow us to make statistics later. So I decided to use pytables that you can get via pip install pytables. It looks like a small DB in a single file. The file format is HDF5.
Let say we want to create a table containing user name and user id in a file :
import tables
class CUsers (tables.IsDescription) :
user_name = StringCol(32)
user_id = IntCol()
with tables.open_file("UsersTable.h5", mode="w") as h5file :
groupUser = h5file.create_group("/", "Users", "users entries")
tableUser = h5file.create_table(groupUser, "Users", CUsers, "users table")
We have now a file UsersTable.h5 that has an internal table located in root/Users/Users that is accepting CUsers objects, where, therefore, user_name and user_id are the columns of that table.
getting user info and storing it
Let's now code a function that will register user infos, and i'll call it register. We will get the required data from the Context that is passed with the command, and we'll store it in file.
#bot.command(name='register')
async def FuncRegister (ctx) :
with tables.open_file("UsersTable.h5", mode="a") as h5file :
tableUser = h5file.root.Users.Users
particle = tableUser.row
particle['user_name'] = str(ctx.author)
particle['user_id'] = ctx.author.id
particle.append()
tableUser.flush()
The last two lines are sending the particle, that is the active row, so that is an object CUsers, into the file.
An issue I got here is that special characters in a nickname can make the code bug. It's true for "é", "ü", etc, but also cyrillic characters. What I did to counter is to encode the user name into bytes, you can do it by :
particle['user_name'] = str(ctx.author).encode()
reading file
It is where it starts to be interesting. The HFS5 file allows you to use kind of sql statements. Something you have to take in mind is that strings in the file are UTF-8 encoded, so when you extract them, you have to call for .decode(utf-8). Let's now code a function where a user can remove its entry, based on its id :
#bot.command(name="remove")
async def FuncRemove(ctx) :
with tables.open_file("UsersTable.h5", mode="a") as h5file :
tableUser = h5file.root.Users.Users
positions = tableUser.get_where_list("(user_id == '%d')" % ctx.author.id)
nameuser = tableUser[positions[0]]['user_name'].decode('utf-8')
tableUser.remove_row(positions[0])
.get_where_list() returns a list of positions in the file, that I later address to find the right position in the table.
bot.fetch_user(id)
If possible, prefer saving ID over name, as it complicates the code with encode() and decode(), and that bots have access to a wonderful function that is fetch_user(). Let's code a last function that will get you the last entry in your table, and with the id, print the username with the fetch method :
#bot.command(name="last")
async def FuncLast(ctx) :
with tables.open_file("UsersTable.h5", mode="r") as h5file :
tableUser = h5file.root.Users.Users
lastUserIndex = len(tableUser) - 1
iduser = tableUser[lastUserIndex]['user_id']
member = await bot.fetch_user(iduser)
await ctx.send(member.display_name)
For further documentation, check the manual of discord.py, this link to context in particular.

API Response - How to handle response in React

I'm trying to work with an API that sends out a list of questions to create a question set. This is the response from the API:
{"questionSetItems":[[1,"From which date would you like your insurance to start from?","This is the date on which you want the policy to begin. The policy will not pay for any claims which occur prior to this date.","Dropdown",[],"",false],[2,"What is your title?","","DropDown",[],"",false],[3,"What is your title?","","DropDown",[],"",false],[4,"What is your forename?","","Edit",[],"",false],[5,"What is your surname?","","Edit",[],"",false],[6,"What is your date of birth?","","Date",[],"",false],[7,"You and your spouse or partner are not: <br\/>Professional Sportspeople<br\/>Professional Entertainers<br\/>Professional Gamblers<br\/>Moneylenders or Pawnbrokers<br\/>Bailiffs or Bodyguards<br\/>Bar Managers<br\/>Car Dealers\/Salespeople<br\/>Circus or Fairground Employees\/Owners<br\/>Clairvoyants, Tarot Readers or Palmistry Experts<br\/>Croupiers, Gaming Club Managers\/Proprietors<br\/>Diamond or Metal Dealers<br\/>Exotic Dancers<br\/>Jewellers or Jewellery Consultants<br\/>Street\/Market Traders<br\/>Tattooists<br\/>Student<br\/>Unemployed\/In voluntary employment<br\/><br\/>Please confirm that you agree to the above statements.","","YesNo",["inputEmploymentYes","inputEmploymentNo"],"",true],[8,"Please select the relevant employment types for both you and your spouse or partner","","ButtonList",["inputSportspeople","inputEntertainers","inputGamblers","inputBar","inputBailiffs","inputMoneyLender","inputTarot","inputCircus","inputCar","inputExotic","inputDiamond","inputCroupiers","inputTattooists","inputStreet","inputJewellers","inputVoluntary","inputUnemployed","inputOther","inputStudent"],"partnerType",false],[9,"Do you need to add a joint policyholder?","","YesNo",["inputJointHolderYes","inputJointHolderNo"],"",true]],"headerLogo":"","cOB":"STDH","isLastPage":false}
How to look through the array in React?
yo
u can use like this .u can keep it in a variable name and u can check in which key ur getting the array of datas , then you can map the fields and u will get data
enter image description here

Comparing Old and new value of the record

Hope you are all doing good!!!.
I just need to fix this one and I googled the logic and when I tried I got an error and then I have copied the online code and paste that too but no use.
the logic of the below code is :Check the phone number of the account and compare old and new value of the phone number if it's not the same value then I need to update the old value in the description.
public class CheckOldAndNewValueonAccount {
public static void accNewOldValues(List<Account> accList){
for(Account acc: accList){
Account oldAcc = Trigger.oldMap.get(acc.Id);
if(acc.Phone != oldAcc.Phone){
acc.Description = 'Old Phone number this account is :'+oldAcc.Phone;
}
}
}
}
Error: Illegal assignment from SObject to Account.
Please guide me on this.
Thanks in Advance.
I believe the issue is this line:
Account oldAcc = Trigger.oldMap.get(acc.Id);
I believe the type of old map is Map<String, sObject>.
sObject is a type that is a Salesforce object (any one) but none specifically.
So you are trying to assign an sObject to a variable you are declaring as an Account type.
You can just do the following:
sObject oldAcc = Trigger.oldMap.get(acc.Id);
unless you specifically want to try and cast the sObject to an Account (concrete) type. I don't see any major benefit to doing so. Let us know if that was the problem and if this resolved it.
Edit: see this trailhead:
https://trailhead.salesforce.com/en/content/learn/modules/apex_database/apex_database_sobjects
Section: Casting Generic sObjects to Specific sObject Types
You can easily cast to Account. There is a snippet there.
Dot notation is not available on generic sObject types.
Or you can use .get('fieldname') which works on generic sObject as well.

in Watson Discovery News Feed API, limiting articles returned by date

Per the API documentation, manipulating the vales of "start" and "end" will result in different data sets being returned. Strangely, changing the values of start and end resulted in the same result being returned. What am I missing? Thanks!
qopts = {'query': '/automotive and vehicles',
'aggregation' : '[term(yyymmdd).term(docSentiment.type,count:3)]',
'return': 'docSentiment.type,yyyymmdd',
'count': '50',
'start': 'now-2w',
'end' : 'now-1w',
'offset': my_offset}
my_query = discovery.query(my_disc_environment_id, my_disc_collection_id, qopts)
I hope it is helpful for you.
I am not sure if this is right answer for you because I have limited information.
First of all, please check the number of return-sets. if the return-set has more then 50 dataset, result could be same. (might count param. -1 = unlimited in the rest API of WCA (Watson Context Analytics)
Second, if you can check the log from the server side, you can see the full query which manipulated from WATSON engine.
Last, I am not really sure that watson REST-API can recognize 'now-2w' style start-end form. Would you please link the tutorial? In my previous project, I wrote the start-end date by Y-M-D form.
Good Luck

How to get unique identifiacation number of iphone

I want to get unique id of iphone.currently I am using Display.getInstance().getUdid(); but it gives different unique id each time I install an application on iphone.
Can you please let me how to resolve it?
You can no longer get the Unique id per device because of apples revised security policy . identifierForVendor is the best alternative you can go for.
You can try
UIDevice *device = [UIDevice currentDevice];
NSString *currentDeviceId = [[device identifierForVendor]UUIDString];
getUDID() returns a faux number that can't be made unique due to Apple's restrictions.
You can get it by calling this function:
UIDevice.currentDevice().identifierForVendor

Categories

Resources