Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const access_token = "{{access_token}}"
- // assumes a variable called "input" with a property called "siteName"
- const siteName = input.siteName
- // return the first item in an array
- const head = ([x]) => x
- fetch(`https://api.vromo.io/v2/graph/role/sites?access_token=${access_token}`, {
- method: "GET"
- })
- .then(res => res.json())
- .then(sites => {
- // filters the list of all sites down to the site with the given name
- const site = head(sites.items.filter(site => site.contact.name === siteName))
- // site.id in the url ensures the job is created on the fetched site
- return fetch(`https://api.vromo.io/v2/graph/role/sites/${site.id}/jobs?access_token=${access_token}`, {
- method: "POST",
- headers: {
- "Content-Type": "application/json"
- },
- body: JSON.stringify(
- [{
- "name": "Order Number #483920",
- "contact": {
- "name": "Mike",
- "phone": "+353832224444",
- "email": "mike@gmail.com"
- },
- "attr": [{
- "key": "Chef Instructions",
- "value": "No onions on burger please"
- },
- {
- "key": "Driver Instructions",
- "value": "Please do not ring the doorbell"
- }
- ],
- "tasks": [{
- "timeframe": {
- "by": 1578585415881
- }
- },
- {
- "timeframe": {
- "by": 1578589038037
- },
- "zone": {
- "name": "Customer",
- "address": "VROMO, Phibsborough Tower, Dublin 7, Ireland",
- "coords": {
- "lat": 53.355473,
- "lon": -6.270598
- }
- }
- }
- ]
- }]
- )
- })
- })
- .then(res => res.json())
- .then(data => console.log(data))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement