Код: Выделить всё
json
Copy
Edit
{
"manifest_version": 3,
"name": "GoHighLevel Messenger Extension",
"version": "1.0",
"permissions": [
"storage",
"activeTab",
"scripting"
],
"host_permissions": [
"https://app.gohighlevel.com/*"
],
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"matches": [""],
"js": ["content_script.js"]
}
],
"action": {
"default_popup": "popup.html"
}
}
Copy
Edit
chrome.storage.local.get("ghl_api_key", async (res) => {
if (!res.ghl_api_key) {
alert("No GHL API key found. Please save one first.");
return;
}
const apiKey = res.ghl_api_key;
const url = "https://app.gohighlevel.com/v2/location ... 7/contacts";
// Note: 54HQKNLdRdp1puWWYfv7 is my location ID
try {
const resp = await fetch(url, {
method: "POST",
headers: {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
firstName: "Test",
email: "[email protected]",
phone: "+15555555555"
})
});
console.log("Fetch status:", resp.status); // Logs 401
if (!resp.ok) {
// e.g. "Error creating contact: 401"
alert(`Error creating contact: ${resp.status}`);
} else {
const data = await resp.json();
console.log("Success:", data);
}
} catch (err) {
console.error("Fetch error:", err);
}
});
< /code>
Тестирование в почте: < /p>
http
Copy
Edit
POST https://app.gohighlevel.com/v2/location ... 7/contacts
Authorization: Bearer
Content-Type: application/json
{
"firstName": "Test",
"email": "[email protected]",
"phone": "+15555555555"
}
< /code>
Это возвращает 200 OK и успешно создает контакт. /> Добавлен "host_permissions": ["https://app.gohighlevel.com/*"] в manifest.json. Сообщение. Токен работает в почтальоне? Я упускаю какие -либо дополнительные заголовки или шаги в контексте расширения хрома?>
Подробнее здесь: https://stackoverflow.com/questions/795 ... pite-corre