Closed amarg26 closed 5 years ago
Yes, use the tests as examples.
But what is input.customer like
input.webhook in that test is
{ topic: 'orders/create', address: 'http://whatever.hostname.com/', format: 'json' }
Thanks. I have a query now that What is the way to pass the form values eg . email and number to the above param? Also I only need Email and Number , If I exclude the rest will it be fine ?
Yes probably, try it, Shopify will answer with a validation error if it doesn't work.
I have following code to create customer
`const createCustomer = function(shopDomain, accessToken, customer) {
const shopName=shopDomain.replace('.myshopify.com','');
const shopify = new ShopifyAPIClient({ shopName: shopName, accessToken: accessToken });
shopify.customer.create(customer).then(
response => console.log(`customer ${customer} created`),
err => console.log(`Error creating customer ${customer} ${JSON.stringify(err.response.body)}`)
);
}`
createCustomer(shop,accessToken,{ "email": "steve.lastnameson@example.com", "phone": "555-1212", "verified_email": true, "metafields": [ { "key": "new", "value": "newvalue", "value_type": "string", "namespace": "global" } ] });
I am getting error in console as Error creating customer [object Object] {"errors":{"phone":["is invalid"]}}
What am I doing wrong here ?
{"errors":{"phone":["is invalid"]}}
I guess the phone format is invalid.
Format is 10 digit ?
I don't know, try it or search on Google, this is not an issue in the library.
I used right format and I got response as customer [object Object] created
at console .When I check my store admin customer panel. I do not found this entry. Is anything additionally need to be done to get every customer entry at admin store ?
If you got a 200 response then the customer was created and should appear in the admin interface.
createCustomer(shop,accessToken,{
"email": req.body.email, // hard values getting saved but what is dynamic variable or param
"phone": req.body.phone,// i needs to pass ??
"verified_email": true,
"metafields": [
{
"key": "new",
"value": "newvalue",
"value_type": "string",
"namespace": "global"
}
]
});
const createCustomer = function(shopDomain, accessToken, customer) {
const shopName=shopDomain.replace('.myshopify.com','');
const shopify = new ShopifyAPIClient({ shopName: shopName, accessToken: accessToken });
shopify.customer.create(customer).then(
response => console.log(`customer ${customer.email} created`),
err => console.log(`Error creating customer ${customer.email} ${JSON.stringify(err.response.body)}`)
);
}
app.post('/signup',cors(), function (req, res,err) {
res.set('dataType', 'json');
res.sendStatus(200);
res.sendStatus(200);
const postBody = req.body;
console.log(postBody);
console.log(req.body.email);
console.log(req.body.number);
console.log(err);
});
I am getting the customer Hard values in this function call.What I want is when user submits form, (jquery ajax form on client) I want to store it every time when user submits form without passing hard values.How to pass dynamic value to the createCustomer function call ?
function signUpCall(){
$.ajax({
method: "POST",
url: "https://dcf92d61.ngrok.io/signup",
dataType: "text",
data: $('#contact_form').serialize()
})
.done(function( data ) {
alert(JSON.stringify(data));
})
.fail(function(err) {
alert( "error" + err );
});
}
</script>
<form method="POST" accept-charset="UTF-8" id="contact_form" class="contact-form" action="/contact#contact_form" onsubmit="signUpCall();return false;">
<input type="email" class="" name="email" required placeholder="Please Enter Email"
style="width: 420px; display: inline-block;" />
<input type="number" class="" name="number" required placeholder="Please Enter Contact Number"
style="width: 420px; display: inline-block;"/>
<input type='submit'/>
</form>
What is Format of params for for customer.create and customer.update i.e input.customer ? As per test ?