html Yotpo API POST

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html Yotpo API POST相关的知识,希望对你有一定的参考价值。

<mvt:comment> Yotpo </mvt:comment>
<!-- Yotpo -->
http://blog.merchant.local/?p=2995
<!– Yotpo –>
<script>
$(document).ready(function () {
        var credUrl = 'https://api.yotpo.com/oauth/token',
            creds = {
            "client_id": "ej5GZPZcQfXvXaI3fHCxHl3k9NnIz0Lqh2Idf19k",
            "client_secret": "M5ltFLv9j6FXiYsZqDXZV0qD5T9GZlcnDRfbrPYp",
            "grant_type": "client_credentials"
            },
            accessToken = '';
            console.log(accessToken);
        $.ajax({
            url: credUrl,
            type: 'POST',
            contentType:'application/json',
            data: JSON.stringify(creds),
            dataType:'json',
            success: function(data){
            }
        }).done(function (data) {
            accessToken = data.access_token;
            console.log(accessToken);
            d = new Date();
            var data = {
                "validate_data": false,
                "platform": "general",
                "utoken": accessToken,
                "email": "&mvt:order:bill_email;",
                "customer_name": "&mvt:order:bill_fname;",
                "order_id": "&mvt:item:order_id;",
                "currency_iso": "USD",
                "user_reference": "&mvt:order:cust_id;",
                "order_date": d.getDate() + "-" + (d.getMonth()+1) + "-" + d.getFullYear(),
                "products": {
                    <mvt:assign name="pcounter" value="0" />
                    <mvt:foreach iterator="item" array="order:items">
                        <mvt:assign name="pcounter" value="g.pcounter + 1 "/>
                        <mvt:if expr="g.pcounter GT 1">
                        ,
                        </mvt:if>
                        "&mvt:item:code;": {
                        "url": "&mvt:seo_settings:urlprefix;p/&mvta:item:name;/&mvta:item:code;",
                        "name": "&mvt:item:name;",
                        "image": "&mvt:global:domain:base_url;&mvt:item:customfield_values:productimagecustomfields:default;",
                        "price": '&mvt:item:price;'
                        }
                    </mvt:foreach>
                }
        };
        $.ajax({
            url: 'https://api.yotpo.com/apps/ej5GZPZcQfXvXaI3fHCxHl3k9NnIz0Lqh2Idf19k/purchases',
            type: 'POST',
            contentType:'application/json',
            data: JSON.stringify(data),
            dataType:'json',
            success: function(data){
            }
        });
        });
});
</script>

以上是关于html Yotpo API POST的主要内容,如果未能解决你的问题,请参考以下文章

xml 将Yotpo Stars(每个产品和网站评论)保存到自定义字段

Web Api如何传递POST请求

Axios加密的POST参数

POST 请求 Fetch API 防止重定向

如何使用python请求将经过身份验证的POST请求编码到API?

vue--axios使用post方法与后台进行异步传值是报错POST http://localhost:8080/api/AddEmployeeApi 405 (METHOD NOT ALLOWED)