0

I have this string in a Google Apps Script

const response = UrlFetchApp.fetch(url, { 'method': 'POST', 'headers': {'Authorization': 'Basic QWRtaW5pc3RyYXRv','Content-Type': 'application/json'}}); I can't find a working way to have the string "QWRtaW5pc3RyYXRv" read from a variable.

Something like var key = "QWRtaW5pc3RyYXRv"; const response = UrlFetchApp.fetch(url, { 'method': 'POST', 'headers': {'Authorization': 'Basic + key +','Content-Type': 'application/json'}});

Does not work!!

1

1 Answer 1

1

Use a template literal, like this:

  const key = 'QWRtaW5pc3RyYXRv';
  const auth = `Basic ${key}`;
  const headers = { 'Authorization': auth, 'Content-Type': 'application/json' };
  const response = UrlFetchApp.fetch(url, { 'method': 'POST', 'headers': headers });
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.