hey there good morning good evening good,whatever time you're watching this at,welcome to yet another pipe dream,speedrun uh this week is very special,because this week is gonna be our first,iot episode so this is a counter that,will actually flip these numbers to,whatever number you define in a web hook,which is perfect for pipedream,it's called a smurl and this is the,shopify counter edition and we're going,to be using it to track live,transactions from a shopify app and on,top of that we're going to be debuting a,brand new feature here at pipedream,called a data store which you can use in,your workflows so let's get started here,is a brand new workflow on pipedream and,we're going to create a web hook trigger,that smirl can communicate with,let's go ahead and click continue and,here's a brand new url we can copy,we'll go back to our smurl dashboard and,we will enter it right here within our,settings for the counter now the counter,knows to go back to pipe dream and look,for a json object with an attribute,number in it now that we have smirl,communicating with our workflow we can,go ahead and create a new node.js step,that will return an http response that,contains the json that sumrall can,understand so we're going to go ahead,and make the,a call to the respond helper and the,body needs to contain the attribute,called number that's how smurl knows,where the number is and let's just set,it to zero just to start and just make,sure that we leave a status of 200.,we'll test this very quickly,and then we'll click deploy,i can't forget to await this,await the respond because it's a,asynchronous method here,we'll deploy this,and then we'll go over to smurl,it already started working actually,you can hear the,ticker moving so what happened was smirl,asked this url that we created for a,number,and when they opened up the url,it gave a number of zero which updated,our ticker or counter to zero,all right now smirl is updating in real,time to whatever number we provide here,in our web hook but going in here and,updating it manually is not very fun nor,cool let's just change that so we'll,bring in a brand new data store,like i mentioned in the beginning this,video,this is a new feature,and we're going to call it,data,and we'll say the type of this,attribute is a data store,now a data store is like a simple key,value storage utility where we can go,ahead and retrieve data within this web,hook so we'll say the,number,is equal to,data dot get get it get is to get data,from the data store and we'll call it,just number,and if it if number doesn't exist we,should probably default to zero it's,probably a good idea and then we can,remove this,now number is retrieving its value from,our data store to,include a data store we have to actually,click test,this will,open up a new prop,called,data,and we can create a brand new store,let's just name it a smurl,number,and now it created a brand new store for,us to,use for this workflow and other,workflows one minor problem with my step,here uh you'll see this error message,down here data is not defined,that's because well data's not defined,we are we're introducing the steps,variable and the dollar sign variable,which contains utilities for the step,but props,like up here are injected under the this,this,is,the instance of the step and we're,injecting a data prop which is available,at this dot data,all props are available under this dot,now we'll run it again,voila,the body says number zero so we're,defaulting to zero because number,doesn't exist yet let's fix that,so i'm actually going to create a,separate workflow that's only,responsible for updating the real time,value in our data store,so we're going to name this one,smirl,web hook,just so remember that this is,responsible for being the web hook i'm,going to deploy the changes we have,right now too while we're at it,this next workflow we're going to create,is responsible for actually retrieving,the data that we want to,put into the data store,so,like i said this is going to be a,shopify partner integration,we're going to listen to transactions on,our shopify apps whenever a new app,charge is,created by one of your apps let's update,our counter so i'm just going to pick my,test shopify account here we're going to,update it every 15 minutes we'll create,this source so unlike the web hook,trigger which is triggered by http,requests this is a polling source that's,asking shopify every 15 minutes to see,if there's any new transactions on the,given shopify partner account and let's,try it now let's get some test events in,here,cool we got lots of events to play with,we're going to pick one of these,and we're going to create another step a,node.js step,and we're going to inject our s our new,store,we'll call it data again we'll say type,is a data store,and make sure to add that comma there,click test this will run the props and,inject them into this step,and voila look at that we can pick our,smurl number store that we used in the,previous workflow get rid of this over,here,so,we're going to,take the latest event we should first,grab the current number right so that,way we can add it add the next number to,it so we'll get use the set method this,time and we'll say,get the number or sorry,we'll get the number not set the number,and if it doesn't exist make it zero,then we can say within the steps,there's the trigger event,the trigger step get the event under the,trigger,and then from in there i know that the,net amount dot amount contains the,actual dollar amount right here i can,just copy path that makes it a little,bit quicker so instead of typing it all,out like i just did you just copy path,and paste it's the same result,now,if you notice these are decimals which,smirl doesn't have decimals i'm just,going to round this number,this should round it to the nearest,whole number,so we'll say,amount,equals this make a brand new variable,and now we could,say the new number,equal to the addition of,number,plus,the amount,now the one thing that i want i'm just,concerned about is the possibility that,these are interpreted as strings and not,as numbers,so the best way to fix that is to say,parse,int,on this side,well let's just wrap this whole thing,with parse int and here,since this should be a float before it,becomes a before it's rounded we should,say parse float,this,i'm just being extra cautious here it's,probably not necessary but i'm just,gonna say parseint as well around this,so now we have this new number that,should for sure be a integer,because i'm crazy like that and then we,will,set the data so instead of using the get,method like i showed you before we can,use the set method on the data store,we'll say set,number,equal to,the new number,voila so that's that's it now this code,will run at 15 minute interval it'll,emit every time a new transaction is,found and then it will add the numbers,to the data store under the the keyword,number so hopefully when i click test,here we don't get any bugs but we can,fix those no problem,property get of undefined,so i i just have a hard time accessing,uh data stores i guess the correct name,was,data not db test it again,and it looks like the counter is already
Congratulation! You bave finally finished reading how to convert sales in shopify counter and believe you bave enougb understending how to convert sales in shopify counter
Come on and read the rest of the article!