إضافة الشركة

في هذا المقال سنتعلم عملياً كيفية التعامل مع الشركات في مركز المساعدة باستخدام واجهة زيتون (API)، بدايةً من عرض بيانات الشركات وصولاً إلى إضافتها وتعديلها وحذفها.

عرض شركة

يُمكنك عرض بيانات شركة معينة باستخدام معرفها التعريفي، على سبيل المثال لعرض بيانات شركة لها المعرف 1002 نرسل الطلب التالي:

curl "https://example.com/api/agent/v1/companies/1002" \
-H "Authorization: Bearer $TOKEN"

تصفية شركات

يُمكن تصفية نتائج عرض الشركات باستخدام معاملات الاستعلام (Query Parameters)، على سبيل المثال لعرض الشركات المحذوفة نُرسل الطلب التالي:

curl "https://example.com/api/agent/v1/companies?trashed=1" \
-H "Authorization: Bearer $TOKEN"

ولعرض الشركات المسجلة والمسندة للوكيل رقم 1008 نرسل الطلب التالي:

curl "https://example.com/api/agent/v1/companies?assign_to[]=1008" \
-H "Authorization: Bearer $TOKEN" \
--globoff

لعرض الشركات ضمن الفئة رقم 700 نرسل الطلب التالي:

curl "https://example.com/api/agent/v1/companies?segment_ids[]=700" \
-H "Authorization: Bearer $TOKEN" \
--globoff

كذلك لعرض الشركات المشتركة بوسم "IT" ووسم "VIP" نرسل الطلب التالي:

curl "https://example.com/api/agent/v1/companies?tags[]=it&tags[]=vip" \
-H "Authorization: Bearer $TOKEN" \
--globoff

إضافة شركة

يُمكنك إضافة بيانات شركة جديدة كإسمها ورقمها وشعارها، على سبيل المثال لإضافة شركة للشركات المحفوظة لمركز المساعدة وإسنادها للوكيل رقم 1008 نرسل الطلب التالي:

curl "https://example.com/api/agent/v1/companies" \
-X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "company_name",
"logo": "company_logo_in_base64",
"status": "active",
"numbers": [
{
"country_code": 999,
"number": 12345
},
{
"country_code": 999,
"number": 12345
}
],
"tags": ["new"],
"emails": ["email@example.com"],
"assign_to": 1008,
"segment_ids": [700]
}'

تعديل شركة

على سبيل المثال لإضافة وسم جديد بإسم "IT" وعنوان بريد إلكتروني ورابط LinkedIn للشركة رقم 1002 نرسل الطلب التالي:

curl "https://example.com/api/agent/v1/companies/1002" \
-X PUT \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "company_name",
"status": "active",
"tags": ["new", "it"],
"fields": [
{
"key": "linkedin",
"value": "https://www.linkedin.com/example/",
"type": "url"
}
],
"emails": ["email1@example.com", "email2@example.com"]

حذف شركة

على سبيل المثال لحذف الشركة رقم 1002 من مركز المساعدة نُرسل الطلب التالي:

curl "https://example.com/api/agent/v1/companies/1002" \
-X DELETE \
-H "Authorization: Bearer $TOKEN"

ولاستعادة الشركة السابقة إلى قائمة الشركات نُرسل الطلب التالي:

curl "https://example.com/api/agent/v1/companies/1002/restore" \
-X POST \
-H "Authorization: Bearer $TOKEN"

إقرأ أيضاً