主页 > marketing >
使用 nodejs 对 Marketing Cloud 的 contact 主数据进行修改操作(nodejs setimmediate)
25-04-22
3
本文将带您了解关于使用nodejs对MarketingCloud的contact主数据进行修改操作的新内容,同时我们还将为您解释nodejssetimmediate的相关知识,另外,我们还将为您提供关
本文将带您了解关于使用 nodejs 对 Marketing Cloud 的 contact 主数据进行修改操作 的新内容,同时我们还将为您解释nodejs setimmediate 的相关知识,另外,我们还将为您提供关于Cloud for Customer 的 contact 主数据 function 字段下拉菜单的绘制原理、Contact Form 7 添加检查验证表单步骤插件 – Contact Form 7 add confirm、Django/Python“django.core.exceptions.ImproperlyConfigured:无法导入‘contact’检查‘...apps.contact.apps.ContactConfig.name’是否正确”、Marketing Cloud API消费entity unsupported format错误消息的处理 的实用信息。
本文目录一览:
假设在 Marketing Cloud 有这样一个 contact 主数据:
现在需求是使用编程语言比如 nodejs 修改这个 contact 实例的高亮属性。
代码如下:
var config = require ("./mcConfig" );
var request = require (''request'' );
var url = config.tokenURL;
console .log("user: " + config.user + " password: " + config.password);
var getTokenOptions = {
url : url,
method : "GET" ,
json :true ,
headers : {
''Authorization'' : ''Basic '' + new Buffer(config.user + ":" + config.password).toString(''base64'' ),
"content-type" : "application/json" ,
"x-csrf-token" :"fetch"
}
};
function getToken ( ) {
return new Promise (function (resolve,reject ) {
var requestC = request.defaults({jar : true });
console .log("Step1: get csrf token via url: " + url );
requestC(getTokenOptions,function (error,response,body ) {
var csrfToken = response.headers[''x-csrf-token'' ];
if (!csrfToken){
reject({message :"token fetch error: " + error});
return ;
}
console .log("Step1: csrf token got: " + csrfToken);
resolve(csrfToken);
});
});
}
function updateContact (token ) {
return new Promise (function (resolve, reject ) {
var sPostData = "--batch_1f7d-bd35-caed" + "\n" +
"Content-Type: multipart/mixed; boundary=changeset_8f9e-9a44-9f9e" + "\n" +
"\n" +
"--changeset_8f9e-9a44-9f9e" + "\n" +
"Content-Type: application/http" + "\n" +
"Content-Transfer-Encoding: binary" + "\n" +
"\n" +
"MERGE Consumers(''02000A21209F1EE99CDF1A1FC9AA8065'')?sap-client=100 HTTP/1.1" + "\n" +
"Cache-Control: max-age=360" + "\n" +
"sap-contextid-accept: header" + "\n" +
"Accept: application/json" + "\n" +
"Accept-Language: en" + "\n" +
"DataServiceVersion: 2.0" + "\n" +
"MaxDataServiceVersion: 2.0" + "\n" +
"x-csrf-token: fQ2Pwfmf0K_LVYoKV9QYUw==" + "\n" +
"Content-Type: application/json" + "\n" +
//"Content-Length: 215" + "\n" +
"\n" +
"{\"YY1_CustomerType_ENH\":\"Jerry测试1\"}" + "\n" +
"--changeset_8f9e-9a44-9f9e--" + "\n" +
"\n" +
"--batch_1f7d-bd35-caed--" ;
var requestC = request.defaults({jar : true });
var createOptions = {
url : config.updateContactURL,
method : "POST" ,
json :false ,
headers : {
"content-type" : "multipart/mixed;boundary=batch_1f7d-bd35-caed" ,
''x-csrf-token'' : token
},
body :sPostData
};
requestC(createOptions,function (error,response,data ) {
if (error){
reject(error.message);
}else {
debugger ;
console .log("Contact updated successfully" );
resolve(data);
}
});
});
}
getToken().then(updateContact).catch((error ) => {
console .log("error: " + error.message);
});
我在 nodejs 代码里把需要更改的字段值赋为 "Jerry 测试 1”:
执行之后这个属性被成功更新了:
要获取更多 Jerry 的原创文章,请关注公众号 "汪子熙":
[外链图片转存失败 (img-kY00ou5p-1566695062000)(https://upload-images.jianshu.io/upload_images/2085791-dcc88e58a67cac8c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)] 要获取更多 Jerry 的原创文章,请关注公众号 "汪子熙":
本文同步分享在 博客 “汪子熙”(CSDN)。 如有侵权,请联系 support@oschina.cn 删除。 本文参与 “OSC 源创计划”,欢迎正在阅读的你也加入,一起分享。
站长朋友们在使用以后,为了访客能够轻松联系到自己,提高网站的转化率,通常会在网站中加入联系我们的表单,让客户可以方便的在线发邮件给自己预设的邮箱。我们都熟悉,这种表单使用 来做非常方便,但是Contact Form 7插件默认的工作流程是:客户填写咨询信息,点击发送,直接发到站长的邮箱,并没有检查确认的步骤。今天我们就来介绍一款插件 – Contact Form 7 add confirm,这款wordpress插件可以给 Contact Form 7 添加检查验证表单的步骤。
插件安装方法:
1. 在后台的插件里搜索 Contact Form 7 add confirm,在线安装或者,上传到服务器空间。 2. 激活插件。
插件使用方法: 通常提交按钮的代码是:
如何解决Django/Python“django.core.exceptions.ImproperlyConfigured:无法导入‘contact’检查‘...apps.contact.apps.ContactConfig.name’是否正确” 希望大家能帮我解决这个问题...
我的工作流程:
|. vscode :
| capstone_project_website :
| - _pycache_ :
| - apps :
| - _pycache_
| - accounts :
| - contact : # app that is throwing errors
| - _pycache_ :
| - migrations :
| - _init_ . py
| - admin . py
| - apps . py
| - forms . py
| - models . py
| - test . py
| - urls . py
| - views . py
| - public :
| - _init_ . py
| - templates : # all my .html
| - _init_ . py
| - a sgi . py
| - settings . py
| - urls . py
| - views . py
| - w sgi . py
| requirements :
| scripts :
| static :
|. gitig nor e
|. python - version
| db - sqlite3
| docker - compose . yml
| Dockerfile
| Makefile #command I am running
| manage . py
| setup . cfg
我在 capstone_project_website/settings.py
中安装的应用程序:
INSTALLED_APPS = [
"django.contrib.admin" , "django.contrib.auth" , "django.contrib.contenttypes" , "django.contrib.sessions" , "django.contrib.messages" , "django.contrib.staticfiles" , "capstone_project_website.apps.accounts" , "capstone_project_website.apps.contact" ,]
我的capstone_project_website/apps/contact/apps.py
:
from django . apps import AppCon fig
class ContactCon fig ( AppCon fig ):
name = "contact"
我正在运行的命令在我的 Makefile
中:
compose - start :
docker - compose up -- remove - orphans $ ( options )
当我运行 make compose-start
时,我从我的终端收到此消息:
make compose - start
docker - compose up -- remove - orphans
Docker Compose is Now in the Docker CLI , try `docker compose up`
Starting django - website_postgres_1 ... done
Starting django - website_db_migrate_1 ... done
Starting django - website_website_1 ... done
Attaching to django - website_postgres_1 , django - website_db_migrate_1 , django - website_website_1
db_migrate_1 | Traceback ( most recent call last ):
db_migrate_1 | File "/usr/local/lib/ python3.7 /site-packages/django/apps/con fig .py" , line 244 , in create
db_migrate_1 | app_module = import_module ( app_name )
db_migrate_1 | File "/usr/local/lib/ python3.7 /importlib/ __init__ .py" , line 127 , in import_module
db_migrate_1 | return _bootstrap . _gcd_import ( name [ level :], package , level )
db_migrate_1 | File "<frozen importlib._bootstrap>" , line 1006 , in _gcd_import
db_migrate_1 | File "<frozen importlib._bootstrap>" , line 983 , in _find_and_load
db_migrate_1 | File "<frozen importlib._bootstrap>" , line 965 , in _find_and_load_unlocked
db_migrate_1 | ModuleNotFoundError : No module named ''contact''
db_migrate_1 |
db_migrate_1 | During handling of the above exception , another exception occurred :
db_migrate_1 |
db_migrate_1 | Traceback ( most recent call last ):
db_migrate_1 | File "manage.py" , line 22 , in <module>
db_migrate_1 | main ()
db_migrate_1 | File "manage.py" , line 18 , in main
db_migrate_1 | execute_from_command_line ( sys . argv )
db_migrate_1 | File "/usr/local/lib/ python3.7 /site-packages/django/core/management/ __init__ .py" , line 419 , in execute_from_command_line
db_migrate_1 | utility . execute ()
db_migrate_1 | File "/usr/local/lib/ python3.7 /site-packages/django/core/management/ __init__ .py" , line 395 , in execute
db_migrate_1 | django . setup ()
db_migrate_1 | File "/usr/local/lib/ python3.7 /site-packages/django/ __init__ .py" , line 24 , in setup
db_migrate_1 | apps . populate ( settings . INSTALLED_APPS )
db_migrate_1 | File "/usr/local/lib/ python3.7 /site-packages/django/apps/registry.py" , line 91 , in populate
db_migrate_1 | app_con fig = AppCon fig . create ( entry )
db_migrate_1 | File "/usr/local/lib/ python3.7 /site-packages/django/apps/con fig .py" , line 250 , in create
db_migrate_1 | app_con fig _class . __qualname__ , db_migrate_1 | django . core . exceptions . ImproperlyCon fig ured : Cannot import ''contact'' . Check that ''capstone_project_website.apps.contact.apps.ContactCon fig .name'' is correct .
postgres_1 |
postgres_1 | Postgre sql Database directory appears to contain a database ; Skipping initialization
postgres_1 |
postgres_1 | 2021 - 05 - 02 14 : 17 : 44.105 UTC [ 1 ] LOG : starting Postgre sql 13.2 ( Debian 13.2 - 1.pgdg100 + 1 ) on x86_64 - pc - linux - gnu , compiled by gcc ( Debian 8.3 . 0 - 6 ) 8.3 . 0 , 64 - bit
postgres_1 | 2021 - 05 - 02 14 : 17 : 44.106 UTC [ 1 ] LOG : listening on IPv4 address "0.0.0.0" , port 5432
postgres_1 | 2021 - 05 - 02 14 : 17 : 44.106 UTC [ 1 ] LOG : listening on IPv6 address "::" , port 5432
postgres_1 | 2021 - 05 - 02 14 : 17 : 44.113 UTC [ 1 ] LOG : listening on Unix socket "/var/run/postgre sql /.s.PG sql .5432"
postgres_1 | 2021 - 05 - 02 14 : 17 : 44.121 UTC [ 28 ] LOG : database sy stem was shut down at 2021 - 05 - 02 14 : 17 : 17 UTC
django - website_db_migrate_1 exited with code 1
postgres_1 | 2021 - 05 - 02 14 : 17 : 44.129 UTC [ 1 ] LOG : database sy stem is ready to accept connections
website_1 | Watching for file changes with StatReloader
^ CGracefully stopping ... ( press Ctrl + C again to force )
Stopping django - website_website_1 ... done
Stopping django - website_postgres_1 ... done
我知道我投入了很多工作流程,但我想知道我是否设置错误。我之前在我的帐户应用程序上尝试 makemigrations
时遇到过这个问题。那个答案似乎奏效了。
答案是将 name
中的 capstone_project_website/apps/accounts/apps.py
更改为
class AccountsCon fig ( AppCon fig ):
name = "capstone_project_website.apps.accounts"
在已安装的应用程序中,您可以看到路径是:
"capstone_project_website.apps.accounts" ,
我已尝试更改...的名称capstone_project_website/apps/contact/apps.py
class ContactCon fig ( AppCon fig ):
name = "contact"
...到name=''capstone_project_website.apps.contact''
...和我安装的应用名称:
INSTALLED_APPS = [
...
"capstone_project_website.apps.ContactCon fig " ,]
重点是我不确定发生了什么,是目录问题、名称问题还是在make compose-start
之前遗漏了某些步骤。如果您能帮我解决这个问题,并解释我做错了什么,我将不胜感激!
谢谢
解决方法
检查您的 Django 版本。如果您将 django 版本更新到 3.2 ,请尝试切换到最早的版本。
django==3.1.8
,
尝试改变这个:
类 ContactConfig(AppConfig):
姓名 = "联系人"
为此:
类 ContactConfig(AppConfig):
name = "apps.contact"
在消费SAP Marketing Cloud API时,遇到如下错误:
解决方案是在发起http请求的头部添加content-type字段,类型为multipart/mixed:
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
本文同步分享在 博客“汪子熙”(CSDN)。 如有侵权,请联系 support@oschina.cn 删除。 本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。
关于使用 nodejs 对 Marketing Cloud 的 contact 主数据进行修改操作 和nodejs setimmediate 的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于Cloud for Customer 的 contact 主数据 function 字段下拉菜单的绘制原理、Contact Form 7 添加检查验证表单步骤插件 – Contact Form 7 add confirm、Django/Python“django.core.exceptions.ImproperlyConfigured:无法导入‘contact’检查‘...apps.contact.apps.ContactConfig.name’是否正确”、Marketing Cloud API消费entity unsupported format错误消息的处理 的相关信息,请在本站寻找。