Skip to content

Instantly share code, notes, and snippets.

@rob-richards
Forked from westdavidr/yl-api-reference.md
Last active June 30, 2023 10:16
Show Gist options
  • Save rob-richards/927c852a0920eeff52aebd66c4586e81 to your computer and use it in GitHub Desktop.
Save rob-richards/927c852a0920eeff52aebd66c4586e81 to your computer and use it in GitHub Desktop.
Young Living API reference

##API URLS


##Authentication

To obtain a token, issue a request to POST https://www.youngliving.com/api/accounts/token

  • The request must be a HTTP POST request.
  • The request must include a Content-Type header with the value of application/json.
  • The body of the request must in JSON format. Note: userName and password are required in order to obtain a token.

Request body

{
    "userName":"",
    "email":"",
    "memberId":"",
    "password":""
}

Example request

POST /api/accounts/token HTTP/1.1
Host: youngliving.com
Content-Type: application/json

{
    "userName":"janedoe",
    "email":"janedoe",
    "memberId":"123456789",
    "password":"password"
}

##Organization Base URL: https://www.youngliving.com/vo.dlv.api/downline ###Endpoints

  • GET /children/user/{periodid}
  • GET /children/member_id/{periodid}
  • GET /detail/user/{periodid}
  • GET /detail/{memberid}/{periodid}

###Examples

  • (0 can be used in place of {periodid} for current period)

####Get downline for authorized user. Example Request:

GET
https://www.youngliving.com/vo.dlv.api/downline/children/user/405

Example Response:

{
	"customerid": "1449977",
	"currentperiodid": 406,
	"periodid": 405,
	"chartstartperiod": 398,
	"chartendperiod": 405,
	"totalchildren": 74,
	"legs": [ ]
}

####Get downline for specific user Example Request:

GET
https://www.youngliving.com/vo.dlv.api/downline/children/1223344/405

Example Response:

{
	"customerid": 1223344,
	"currentperiodid": 406,
	"periodid": 405,
	"chartstartperiod": 398,
	"chartendperiod": 405,
	"totalchildren": 15,
	"legs": [ ]
}

####Get details for authorized user. Example Request:

GET 
https://youngliving.com/vo.dlv.api/downline/detail/user/405

Example Response:

{
	"customerid": 123456,
	"name": "BLOW, JOE",
	"customertype": 2,
	"email": "test@example.com",
	"mainphone": "1234567891",
	"datesignedup": "5/1/2013 12:27:52 PM",
	"dateactivated": "5/1/2013 12:27:52 PM",
	"onhold": false,
	"activitystatusid": 1,
	"holdreason": "",
	"avatarimage": "",
	"volume": { },
	"rank": { },
	"address": { },
	"autoship": { },
	"sponsor": { },
	"enroller": { }
}

####Get details for a specific user. Example Request:

GET 
https://youngliving.com/vo.dlv.api/downline/detail/user/405

Example Response:

{
	"customerid": 1223344,
	"name": "MEMBER, COOL",
	"customertype": 2,
	"email": "test@example.net",
	"mainphone": "1234567891",
	"datesignedup": "11/16/2013 12:19:32 PM",
	"dateactivated": "11/16/2013 12:19:32 PM",
	"onhold": false,
	"activitystatusid": 1,
	"holdreason": "",
	"avatarimage": "",
	"volume": { },
	"rank": { },
	"address": { },
	"autoship": { },
	"sponsor": { },
	"enroller": { },
	"sponsorpath": [ ]
}

##Commission Base URL: https://youngliving.com/vo.dlv.api/commission ###Endpoints

  • GET: /check/summary/{periodid}
  • GET: /check/unilevel/{periodid}/{levelnum}
  • GET: /history/{periodid}

###Examples

  • (0 can be used in place of {periodid} for current period)

####Get commission check summary for a specific commission period. Example Request:

GET
https://youngliving.com/vo.dlv.api/commission/check/summary/405

Example Result:

{
  "customerid":"123456",
  "checkid":"12345678",
  "checkdate":"11/17/2014",
  "periodid":"405",
  "checktotal":"314.39",
  "totalcommission":"317.39",
  "currencyunit":"USD",
  "dgyf":"0",
  "paidasrankid":2,
  "maxrankid":2,
  "volume":{
    "ogv":4635.5,
    "pv":290.25,
    "pgv":4635.5
  },
  "retail":{
    "commission":"11.84"
  },
  "unilevel":{
    "commission":"229.71",
    "levels":[
      {
        "levelnum":1,
        "commission":"$142.83"
      },
      {
        "levelnum":2,
        "commission":"$63.49"
      },
      {
        "levelnum":3,
        "commission":"$23.39"
      }
    ]
  },
  "faststart":{
    "commission":"75.84",
    "levels":[
      {
        "levelnum":1,
        "commission":"$8.44"
      },
      {
        "levelnum":2,
        "commission":"$67.40"
      }
    ]
  },
  "personalgen":{
    "commission":"0"
  },
  "generations":{
    "commission":"0"
  },
  "risingstar":{
    "commission":"0"
  },
  "leadership":{
    "commission":"0"
  },
  "diamondexpress":{
    "commission":"0"
  },
  "starterkit":{
    "commission":"0"
  },
  "adjustments":{
    "total":"-3",
    "items":[
      {
        "description":"Maintenance Fee",
        "amount":"-3",
        "commledgertypeid":2
      }
    ]
  }
}

#####Get commission check details for a specific level in a commission period. Example Request:

GET
https://youngliving.com/vo.dlv.api/commission/check/unilevel/405/1

Example Result:

{
  "customerid":123456,
  "periodid":406,
  "commissionvolume":1785,
  "percentage":8,
  "commissionearned":"$142.83",
  "unilevel":{
    "levels":[
      {
        "membernum":123445,
        "membername":"MEMBER, COOL",
        "commissionvolume":75.25,
        "percentage":8.0,
        "commissionsearned":6.02
      },
      ...
    ]
  }
}

#####Get commission check details for a specific level in a commission period. Example Request:

GET
https://youngliving.com/vo.dlv.api/commission/history/405

Example Result:

{
  "customerid":1449977,
  "checks":[
    {
      "periodid":405,
      "checknumber":"12345678",
      "checkdate":"11/17/2014",
      "amount":317.39,
      "amountformatted":"$317.39",
      "currency":"USD"
    },
    ...
  ]
}

##Qualification Endpoints


##Essential Rewards Base URL: https://youngliving.com/api/shopping/essential-rewards ###Endpoints

  • GET: /info

###Examples

####Get essential rewards information Example Request:

GET
https://youngliving.com/api/shopping/essential-rewards/info

Example Result:

{
	"totalPoints": 96,
	"totalExpiringPoints30Days": 0,
	"consecutiveMonthsOfErOrders": 12,
	"earningPercentage": 15,
	"availableMonthlyPoints": 96,
	"monthsBeforePercentageIncrease": 0,
	"nextEarningRate": 0,
	"isEnrolled": true,
	"payments": [ ],
	"legacyOtgProcessingDayOfMonth": 1,
	"legacyNfrProcessingDayOfMonth": 1,
	"isErTemplateConfirmed": true,
	"areErDeliveriesValid": true,
	"doesTemplateMeetMinPv": true,
	"otg": {
		"processingDate": {
			"year": 2014,
			"month": 12,
			"day": 1
		}
	},
	"nfr": {
		"processingDate": {
			"year": 2014,
			"month": 11,
			"day": 1
		}
	}
}

##Helpers

function getPeriodId(date) { // Defaults to Current Period if you leave 'date' empty
    date = date instanceof Date ? date : new Date();
    return (date.getFullYear() * 12 + date.getMonth() + 1) - (2014 * 12 + 5) + 400;
}
@raithedavion
Copy link

Can you post a full request example? ie: I do the token request, get some stuff back, but nothing that screams "i'm the auth token". Mostly need to know what i'm supposed to pass in with each request to make it authorized.

@amafigu
Copy link

amafigu commented Jun 30, 2023

Hi guys, I would like to get the available products with prices and so on, my question is how the shopping api works

if I hit this URL

https://www.youngliving.com/api/shopping

I get that

{
    "version": "1.1",
    "content": {
        "headers": [
        ]
    },
    "statusCode": "OK",
    "reasonPhrase": "OK",
    "headers": [
    ],
    "trailingHeaders": [
    ],
    "requestMessage": null,
    "isSuccessStatusCode": true
}

Well, there seems to be nothing there that is related to shopping/buying products.

Does someone know how this api retrieve products?

Should this api do that? It looks like that is for manage user info, but not products.

For the people that are asking how to do that.

I would recommed to work in a agnostic way without really coding first, use a api tester.

Well to get the token, which you have to add in the header as - authtoken : value - you send the post request and then hier is a example with javascript backend (express)

const express = require('express');
const router = express.Router();
const axios = require('axios');
require('dotenv').config();

router.post('/authenticate', async (req, res) => {
  try {
    const tokenResponse = await axios.post(
      'https://www.youngliving.com/api/accounts/token',
      {
        memberId: process.env.YL_ID,
        password: process.env.YL_PASSWORD,
      },
      {
        headers: {
          'Content-Type': 'application/json',
        },
      }
    );

    const plainToken = Buffer.from(JSON.stringify(tokenResponse.data)).toString(
      'base64'
    );

    console.log('productsResponse ', res.json);
  } catch (error) {
    res.status(500).json({ message: error.message });
  }
});

module.exports = router;

you can call it from the frontend with some fake page just for test what will hit the /authenticate

in React something like

useEffect(() => {
    const serverBaseURL = "http://localhost:3001"

    const fetchData = async () => {
      try {
        // HTTP POST to your server to get the token
        const response = await axios.post(
          `${serverBaseURL}/api/youngliving/authenticate`,
        )
        console.log("response MyComponent ", response)

        if (response.status === 200) {
          const authToken = response.data.authToken
          // You can now use the authToken for further API calls
        }
      } catch (error) {
        console.error("Error fetching data:", error)
      }
    }

    // Call the fetchData function
    fetchData()
  }, [])

I would recommed that after you get the plainToken from the logs use it as authtoken value in the header and take the " " away from the value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment