Developer forum

Forum » Integration » DW 9 - Live integration to BC - using dwapi

DW 9 - Live integration to BC - using dwapi

Mateusz Struzik
Reply

Hi 

I hit some problems with lve integration to BC - because of client requirements we had to rewrite some of our product list page, now we need to retreieve products by /dwapi//ecommerce/products.
But i have a problem with getting prices from BC - it basically looks like when i am using built in endpoint the live integration is not working, i checked the source code and it seems like the products are taking only from DB,. 

Is there  a way how to using a dwapi do also a live call to BC ? if not is there a way how can i used live integation connector or price provider to get prices from BC and combine them with list of products returned from api ? 

Regards 

Mateusz 


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Mateusz,

Maybe this can help:
https://doc.dynamicweb.com/forum/integration/integration/lazy-loading-li-prices-loads-from-db

Do you use one of the latest Live integration and Dynamicweb 9 versions?
Can you also check changing the Live integration options for the:
1) Shop set to "Any",
2) "Product Information Cache Level" is set to "Page"
3) FilledProperties in the dwapi url contains the tags for the "Price": &FilledProperties=Price&PriceSettings.FilledProperties=Price

BR, Dmitrij

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Are you sending a JWT token to your products endpoint?

https://doc.dynamicweb.dev/documentation/headless/delivery-api/commerce.html#user-and-personalised-prices

Imar

 
Mateusz Struzik
Reply

Thanks Dmitriy and Imar for quick response 

I didn't check all your hints, i set the shop to  any and cache i set to Page, 

The DW  version is  9.19.0 

and DynamicwebLiveIntegrationAddIn : 7.4.12.0

the api cal we are using looks like that :
dwapi/ecommerce/products/search?LanguageId=LANG17&RepositoryName=Products&QueryName=ProductsList&ProductSettings.FilledProperties=Id,Name,Number,Price,Discount,Manufacturer,ProductFields,StockUnits&PageSize=7&CurrentPage=1&PriceSettings.FilledProperties=Price&UserID=13733&GroupID=1-130

so when i am adding  &FilledProperties=Price it is failing.
added PriceSettings.FilledProperties didn't help much 

My quesstion is dou you think we should use the post api method : dwapi/ecommerce/products instead the one with search ?

i will check other options myabe they will help  

reagrds 

Mateusz 

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Get is fine for the Search request.
Can you append the following params to the request url?
&UserId=XYZ&LanguageId=LANG1&CurrencyCode=EUR&CountryCode=ES&ShopId=SHOP1
BR, Dmitrij

 
Mateusz Struzik
Reply

I was more thinking to use the other endpoint for products

 
Mateusz Struzik
Reply

I append the params, 

My call looks like that: /dwapi/ecommerce/products/search?LanguageId=LANG17&RepositoryName=Products&QueryName=ProductsList&ProductSettings.FilledProperties=Id,Name,Number,Price,Discount,Manufacturer,ProductFields,StockUnits&PageSize=7&CurrentPage=1&PriceSettings.FilledProperties=Price&CurrencyCode=NOK&CountryCode=NO&ShopId=SHOP13&UserID=13733&GroupID=1-130

Still nothing, i am getting llist of products  but it seems like live integration is not called at all as i dont have any log info 

Regards 

Mateusz 

 
Mateusz Struzik
Reply

Probably worth to mention that on search bar where we use feed to gather product info the LI is working ok 

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Are you sending a JWT token for the user?

@Dmitriy: wouldn't a JWT token be necessary? Just specifying a user ID would be a security concern, no? That would allow you to see other people's prices?

Imar

 

 
Mateusz Struzik
Reply

Hi Imar

I dont see any JWT tokens error, the api call is pulling prodcucts, prices are taking from db, in the code i don't see any line that is require for jwt, maybe there is specific li code responsible for that, but i am not able to say this. Also based on api doccs for dw9 the user id should be enough as not further authentication is require. And also the LI seems not working with api but it is ok in other application part where we use more traditional way. Unfortunatelly project is not fresh one and the frontend base on Rapido 

Regards 

Mateusz  

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
This post has been marked as an answer

>> I dont see any JWT tokens error

You wouldn't see any errors; you would simply get behavior for anonymous users which is the DB price

>> the api call is pulling prodcucts

Yeah, that makes sense, but with the wrong price

>> in the code i don't see any line that is require for jwt

LI can work with the user's context. When there's a user, it'll attach the user ID and customer number to the request which then gives you user specific prices.

>> Also based on api doccs for dw9 the user id should be enough as not further authentication is require.

Which docs? Without a JWT, your API request will be anonymous and thus not user-specific.

>> And also the LI seems not working with api but it is ok in other application part where we use more traditional way.

That makes sense; with normal pages you submit the user's auth data with a cookie. With a REST call you (probably) submit nothing making the request anonymous.

Can you try the request in Postman or Bruno and send a JWT bearer token as explained here: 

https://doc.dynamicweb.dev/documentation/headless/delivery-api/commerce.html#user-and-personalised-prices
https://doc.dynamicweb.dev/documentation/headless/delivery-api/access.html#authentication

Imar

Votes for this answer: 1
 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

JWT is needed.

Votes for this answer: 1
 
Mateusz Struzik
Reply

Hi 

So the user id shop id etc from the url : /dwapi/ecommerce/products/search?LanguageId=LANG17&RepositoryName=Products&QueryName=ProductsList&ProductSettings.FilledProperties=Id,Name,Number,Price,Discount,Manufacturer,ProductFields,StockUnits&PageSize=7&CurrentPage=1&PriceSettings.FilledProperties=Price&CurrencyCode=NOK&CountryCode=NO&ShopId=SHOP13&UserID=13733&GroupID=1-130

is basically for get details from BC but they are not authenticate it ? 

@Imar i tried to pull prices as a logged user but i am assuming without context it is not wroking 

Will try with jwt as i didnt have more time last week 

Thanks 

 
Mateusz Struzik
Reply

Hi 

So the user id shop id etc from the url : /dwapi/ecommerce/products/search?LanguageId=LANG17&RepositoryName=Products&QueryName=ProductsList&ProductSettings.FilledProperties=Id,Name,Number,Price,Discount,Manufacturer,ProductFields,StockUnits&PageSize=7&CurrentPage=1&PriceSettings.FilledProperties=Price&CurrencyCode=NOK&CountryCode=NO&ShopId=SHOP13&UserID=13733&GroupID=1-130

is basically for get details from BC but they are not authenticate it ? 

@Imar i tried to pull prices as a logged user but i am assuming without context it is not wroking 

Will try with jwt as i didnt have more time last week 

Thanks 

 
Mateusz Struzik
Reply

Hi 

When i am using the jwt token the live integration is working, so many thanks  for help with that, right now i only tested it via postman but will adapt code to apply jwt. 

But i aslo hit other problems maybe you have solution for that, becasuse i need to impersonate the selected user by its id, but as a id for BC i have external id, i tried to switch my user id with this external but than i am getting error form  search endpoint. 

What i tried :
1. use external id for authenticate impersonation, with jwt token call the product search endpoint, for user id put ExternalId - not work 

2. Use user id for authenticate impersonation, with jwt token call the product search endpoint, for user id put ExternalId - not work

3. when i am using user id both for authentication and later product search call i am getting products with prices but probably in BC there is some other user with same id but the prices i got are wrong 

Regards 

MAteusz  

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
This post has been marked as an answer

Hi Mateusz,

The request /dwapi/ecommerce/products/search is just an end point that fetches products from DW as JSON. It's not BC specific at all. However, as part of fetching products, the prices need to be calculated. This is done by one or more so-called PriceProviders that can provide prices for products. If you use Live Integration, it has a PriceProvider that connects to an ERP like BC. When it connects, it can send the customer number (and user ID) as part of the request. It pulls this customer number from the current user. If there's no user, no customer number is sent and you get anonymous prices (or Live Integration doesn't run at all if it's not set up to get anonymous prices). When the request is made from a normal, pageview-based request, there's a DW auth cookie (and session state) that is used to get the current user. When you make an API request however, there's no cookie and session, and hence no user. By getting a JWT token from the auth end point, and sending that along with the API call, DW can extract user info from the JWT token and create a user that is then used inside live integration. So, in summary, you must send (as you found out) a JWT token in the API request to get user-specific pricesn or otherwise the end points don't know anything about the user that is making the request.

For impersonation, the same principles apply. In summary, you need to do this:

1. Log in as the main user. This gives you a JWT token. You already have this.
2. Hit /dwapi/users/impersonate?userId=UserId where UserId is the DW ID of the user you want to impersonate (you can get the list of users from /dwapi/users/impersonatees)
3. The impersonate end point gives you another JWT which represents the impersonated user.

When you then hit one of the product end points, you should send that second JWT that represents the impersonated user. That way, the request to the ERP is made on behalf of that user (its customer number) resulting in the correct prices.

More details on the impersonation end points here: https://doc.dynamicweb.dev/documentation/headless/delivery-api/access.html#impersonation

Hope this helps,

Imar

Votes for this answer: 1
 
Mateusz Struzik
Reply

Hi Imar 

Thanks  for this explanation, more or less i was aware about price provider and that it need to be called for LI. Basically i did whole the steps you descibed like with authorization and impersonation but it seems i am still getting wrong prices. But it looks like afte i call the impersonation list and than take the user id i am getting the jwt token for different user i ma not sure why this is happening but i will do some more investigation.
Still it seems the original problem is solved the jwt is neede so i will need to add some aditional step before product endpoint will be called. 

Thanks  again.

Mateusz 

 

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

I can add that the /dwapi endpoints do not have any context - which is why you have to send the JWT to tell who you are.

Also the dwapi will not lookup prices in bc based on a userid in querystring or when anonymous as that is both a security issue (getting access to prices that are not mine) and a potential DOS weakness.

BR Nicolai

 
Mateusz Struzik
Reply

Thanks Nicolai for claryfication it make sense, and also based on my latest test it ofcourse look like you and Imar said the info fro BC is taking from token 

Regards 

Mateusz

 

You must be logged in to post in the forum