How to replace session with stateless rest apis? - api

So, I am trying to make a shopping cart web architecture on rest framework where I am struggling to use browser storages to use as an alternative to maintaining the state.
I tried the window.localStorage and window.sessionStorage() APIs but it failed in the case of the private browsing mode in Safari and Opera.
So can anyone help out in the figuring other methods by which I can maintain states in rest based architecture?

You don't need sessions to store application state. User resources.
On approach would be to model every shopping cart as a resource with a unique ID:
/shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80
The client application in the browser would read this resource:
GET /shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80
It would add an item to the cart:
POST /shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80/items
{
"itemId": "1234",
"quantity": 1
}
It would list the contents of the shopping cart:
GET /shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80/items
[
{
"itemId": "1234",
"title": "Some nice item",
"quantity": 1,
"price", 12.34,
"priceTotal": 12.34
},
{
"itemId": "9876",
"title": "Some other nice item",
"quantity": 2,
"price", 0.99,
"priceTotal": 1.98
}
]
The web application would remove an item from the cart:
DELETE /shop/shoppingcarts/E73AC56C-BDF7-11E5-81F1-8E2EDB915C80/items/9876
I think you get the idea.

Related

How to know the Shopify username who triggered a webhook?

I have a product/update Shopify webhook. When the webhook event comes, I see the JSON payload but I don't get any clue about who updated the product. I need the username or email or whatever to identify the user who triggered the webhook. Is that even possible ? If yes, how ?
As per Shopify Documentation, product/update hook does not contain any information regarding the user who triggered the action. However, if it is extremely important for you to find out the user, a workaround is to use the Shopify Events API. As you already have the Product ID in the recieved webhook, you may issue another call to
GET /admin/products/#{product_id}/events.json
and in the response
{
"events": [
{
"id": 677313116,
"subject_id": 921728736,
"created_at": "2008-01-10T08:00:00-05:00",
"subject_type": "Product",
"verb": "create",
"arguments": [
"IPod Touch 8GB"
],
"body": null,
"message": "Product was created: IPod Touch 8GB.",
"author": "Shopify",
"description": "Product was created: IPod Touch 8GB.",
"path": "/admin/products/921728736"
}
]
}
you will have the author field. You may further filter the result using verb and created_at fields.
The supported events are
But I am also only able to get the created, published and unpublished events.

Social Tables API: Event field values for Industry and Type are lost in browser UI

I create an event using the POST /4.0/legacyvm3/teams/{team}/events function with the following data:
{
"name": "My Event",
"category": "event",
"type": "Conference",
"industry": "Corporate",
"start_time": "2017-05-10T10:00:00.000Z",
"end_time" : "2017-05-10T11:00:00.000Z",
"spaces": [
{
"name": "My Room"
}
]
}
and get the following response:
{"id":2474582,"user_id":138947,"team_id":"49992","name":"My Event","category":"event","venue_mapper_version":2,"start_time":"2017-05-10T10:00:00.000Z","end_time":"2017-05-10T11:00:00.000Z","uses_metric":false,"public":false,"attendee_management":true,"spaces":[{"id":4696516,"name":"My Room","event_id":2474582,"space_order":0}]}
All good. But when editing the event in my browser using the URL:
https://app.socialtables.com/?event=2474582
I am prompted to select a value for Industry and Type. Also, the start and end times are both appear as 11:00. Why is this?
Start and end times look correct given that our API assumes you're using UTC (I see 6 and 7am EDT) when I open your event. It also was 10 and 11 in the response you posted.
Probably more importantly, you're using our legacy API and are therefore being pushed to our legacy product. There is a 4.0/events endpoint available to use. If you're writing your integration now I strongly recommend using these endpoints: https://developer.socialtables.com/api-console#!/Events/post_4_0_events

Yodlee AddSiteAccount1 issues

I am trying to verify various MFA based accounts Yodlee API by performing following steps:
Successful call to addSiteAccount1
In response, it does return siteAccountId
In response, it also provides site refresh status that REFRESH_TRIGGERED
if resp['siteRefreshInfo']['siteRefreshMode']['refreshMode'] == 'MFA' and
resp['siteRefreshInfo']['isMFAInputRequired'] == True and
resp['siteRefreshInfo']['siteRefreshStatus']['siteRefreshStatus'] ==
'REFRESH_TRIGGERED'
Now, calling getMFAResponseForSite repeatedly together with getSiteRefreshInfo results into initially code 801 and than 508 eventually timeout.
Eventually, I come out of the loop with result isMessageAvailable: True
{u'itemId': 0,
u'retry': False, u'timeOutTime': 99880, u'memSiteAccId': 10144098,
u'errorCode': 0, u'isMessageAvailable': True, u'fieldInfo':
{u'questionAndAnswerValues': [], u'numOfMandatoryQuestions': -1,
u'mfaFieldInfoType': u'SECURITY_QUESTION'}}
The only concern I have is that it provides mfaFieldInfoType, but it doesn't provide the actual question.
Couple questions:
a. How do I retrieve proper MFA question(s) for the site?
b. If user is initially coming into system and would like to link account more than couple second wait for user will kill the experience - so what's the recommended time period to be allowed to get MFA question?
c. Is this due to development vs. production environment difference?
d. I can retrieve account and holdings details for account, however than the account results in NON_REFRESHABLE state.
After calling addSiteAccount1 API, you get siteAccountId for an account.
Pass the siteAccountId to getMFAResponseForSite API and keep polling until you get the MFA form. then pass the MFA form with valid values to putMFARequestForSite API.
Please refer to our API flow- https://developer.yodlee.com/Aggregation_API/Aggregation_Services_Guide/API_Flow/Add_Site_Account
Blockquote
Sample response-
{ "isMessageAvailable": true, "fieldInfo": {
"questionAndAnswerValues": [
{
"question": "What is the name of your state?",
"questionFieldType": "label",
"responseFieldType": "text",
"isRequired": "true",
"sequence": 1,
"metaData": "QUESTION_1"
},
{
"question": "What is the name of your first school",
"questionFieldType": "label",
"responseFieldType": "text",
"isRequired": "true",
"sequence": 2,
"metaData": "QUESTION_2"
}
],
"numOfMandatoryQuestions": 2,
"mfaFieldInfoType": "SECURITY_QUESTION" }, "timeOutTime": 97340, "itemId": 0, "memSiteAccId": 10003775, "retry": false }

Storing branch attributes offline from Branch.io to track user attribution in my own database

I am trying to store our a campaign attribution identifier offline so that we can do some very custom analytics on the response. Our business team has very specific criteria for determining repeat user activities in our system that can't be tracked with normal analytics, at least not in a very simple way. They need to know how individual users were referred to our system via campaigns, links, etc.
I believe this is as simple as using branch.io to generate a link with specific data in that link. Then, assuming that user ever clicked that link, we should be able to, from our app, use the branch.io SDK to call out to branch.io, retrieve the attribution information, and then pass it to our own servers.
Is this use case possible with branch.io, and am I thinking of it correctly?
Create a branch.io link with a unique referral source
User clicks on that link which may or may not take them to an install
Eventually the user installs our app
On registration within our app we query branch.io using the SDK and ask it for existing attribution information associated to that user.
We make an API call to our own services and pass down whatever we got from branch.io and the user's ID to persist in our own analytics database.
Please let me know if this is possible and if we're thinking of it correctly. I believe this is fundamentally the same use case as custom on-boarding but need to verify for our management team before we bother to implement.
The client-to-server technique that you have described in your response will absolutely work with Branch! If you are interested in a server-to-server approach, your best bet would be to create a webhook from your Dashboard account for the Install event. When installs are referred you'll notice that the json data included in the response will have:
{
"metadata": {
"ip": "<purposely stripped out>",
"referred": true
},
"os": "iOS",
"session_referring_click_timestamp": "2016-02-09T15:57:23.411Z",
"session_referring_click_query": {},
"os_version": "9.2.1",
"first_referring_click_timestamp": "2016-02-09T15:57:23.411Z",
"first_referring_link_data": {
"date_ms": 1455033416690,
"date_sec": 1455033416,
"date": "2016-02-09T15:56:56.690Z",
"data": {
"$og_title": "Jingles Bingleheimer",
"$publicly_indexable": 1,
"face_index": "2",
"~creation_source": 3,
"$identity_id": "225633246304569572",
"monster": "true",
"+url": "https://bnc.lt/ALMc/pkZbNmazPq",
"$one_time_use": false,
"~id": "225633381004658863",
"~channel": "sms",
"body_index": "1",
"monster_name": "Matts Monster",
"$exp_date": 0,
"color_index": "4"
},
"branch_id": "225633381004658863",
"app_short_identifier": "625048",
"domain": "bnc.lt",
"channel": "sms",
"state": 1,
"href": "/ALMc/pkZbNmazPq"
},
"first_referring_click_query": {},
"event": "install",
"event_timestamp": "2016-02-09T15:57:51.019Z",
"session_referring_link_data": {
"date_ms": 1455033416690,
"date_sec": 1455033416,
"date": "2016-02-09T15:56:56.690Z",
"data": {
"$og_title": "Jingles Bingleheimer",
"$publicly_indexable": 1,
"face_index": "2",
"~creation_source": 3,
"$identity_id": "225633246304569572",
"monster": "true",
"+url": "https://bnc.lt/ALMc/pkZbNmazPq",
"$one_time_use": false,
"~id": "225633381004658863",
"~channel": "sms",
"body_index": "1",
"monster_name": "Matts Monster",
"$exp_date": 0,
"color_index": "4"
},
"branch_id": "225633381004658863",
"app_short_identifier": "625048",
"domain": "bnc.lt",
"channel": "sms",
"state": 1,
"href": "/ALMc/pkZbNmazPq"
},
"hardware_id": "<purposely stripped out>"
}
As you can see, it will include the referring link information in the response.
In general, installs will be referred if:
The user clicks on a Branch link and there is an identity associated to the link.
The user installing the app has not installed the app in the past.
Also, webhook documentation can be found here and the SDK will need to be integrated with your app so that Branch can understand that an Install event has occurred.
Note: You can also create webhooks on custom events such as "sign_up_complete" as well.

Setting product published date via Shopify API doesn't work properly

When I set the published_at to a furture date by using the following JSON via Shopify product update API (https://ashop.myshopify.com/admin/products/product_id.json PUT).
{
"product": {
"id": 632910392,
"published": false,
"published_at": "2015-01-01T00:00:00+11:00"
}
}
It returned 200 and the following JSON
{
"product": {
"body_html": "something",
"created_at": "2014-01-07T14:49:00+11:00",
"handle": "test-product",
"id": 206281997,
"product_type": "MERCHANDISE",
"published_at": "2015-01-01T00:00:00+11:00",
"published_scope": "",
},
/* some other JavaScript properties*/
}
Shopify accepted the published date but the product was still visible. Below is the screenshot of the product Visibility
But if I removed "published_at": "2015-01-01T00:00:00+11:00" from the request JSON, the product changed to hidden.
How can I set the published date via Shopify API? Is it possible a Shopify API's bug?
Thanks for you help.
I have found a solution by using private API. And I tested it. Use publish_on instead of published_at. please refer to Shopify forums http://ecommerce.shopify.com/c/shopify-apis-and-technology/t/setting-product-published-date-via-shopify-api-doesn-t-work-properly-173469