sinch.js 1.2 KB

1234567891011121314151617181920212223242526
  1. import axios from 'axios'
  2. // Find your Service Plan ID and API Token at dashboard.sinch.com/sms/api/rest
  3. // Find your Sinch numbers at dashboard.sinch.com/numbers/your-numbers/numbers
  4. const SERVICE_PLAN_ID = 'a1ac863dc82e4075b816a22d8f75a9c7'
  5. const API_TOKEN = 'eb521456941c4fce861e254fb669f743'
  6. const SINCH_NUMBER = '+12085686210'
  7. const TO_NUMBER = '+16789901017'
  8. const REGION = 'us'
  9. const SINCH_URL = 'https://' + REGION + '.sms.api.sinch.com/xms/v1/' + SERVICE_PLAN_ID + '/batches'
  10. const headers = { 'Content-Type': 'application/json', Authorization: 'Bearer ' + API_TOKEN }
  11. const payload = JSON.stringify({
  12. from: SINCH_NUMBER,
  13. to: [TO_NUMBER],
  14. body: 'Programmers are tools for converting caffeine into code. We just got a new shipment of mugs! Check them out: https://tinyurl.com/4a6fxce7!'
  15. })
  16. // axios
  17. // .post(SINCH_URL, payload, { headers })
  18. // .then((response) => console.log(response.data))
  19. // .catch((error) => console.error('There was an error!', error.response))
  20. axios
  21. .get(`https://${REGION}.sms.api.sinch.com/xms/v1/${SERVICE_PLAN_ID}/inbounds`, { headers })
  22. .then((response) => console.log(response.data))
  23. .catch((error) => console.error('There was an error!', error.response))