Shopify API: Retrieve Orders with a specific DiscountCode - node.js

I am currently working on a project that creates Discount Codes via API and I need to retrieve which orders have used a specified Discount Code (ex: TESTCODE123). I couldn't find the documentation or API endpoint mentioned in the Shopify API pages. Is it possible to guide me on this?

You will need to use Admin GraphQL for this and rely on the query parameter to filter them out.
Example:
{
orders(first: 10, query:"discount_code:TESTCODE123"){
edges {
node {
id
}
}
}
}
You can refer the docs here: https://shopify.dev/docs/admin-api/graphql/reference/queryroot?api[version]=2020-01

Related

How to integrate Google Pay on web with DIRECT type (TEST Environment)

How to do Google Pay integration with DIRECT type?
I can't get what to do in this case. Is it possible at all to integrate Google Pay Test Environment with this type? Is it possible to work with test keys for tokenization?
Google provides guide for integration where only PAYMENT_GATEWAY type is described. Please help with some tips.
First, you will need to create a Business Profile to act as a merchant. This will give you a Merchant ID that will later be used in the PaymentDataRequest object.
You can sign up here (it's free and quick)
https://pay.google.com/business/console/home/
Next, you will need to generate a new key pair using OpenSSL, and add it to your Google Business profile.
Please see this link for more details on how to that.
https://developers.google.com/pay/api/web/guides/resources/payment-data-cryptography#key-rotation
Set the type in your tokenizationSpecification to "DIRECT". You will also need to add the below two parameters. Note that the publicKey is the public key you generated earlier and added to your business profile.
const tokenizationSpecification = {
"type": "DIRECT",
"parameters": {
"protocolVersion": "ECv2",
"publicKey": "BOdoXP1aiNp.....kh3JUhiSZKHYF2Y="
}
}
For testing, make sure you are using the 'TEST' environment. See here
function getGooglePaymentsClient() {
if ( paymentsClient === null ) {
paymentsClient = new google.payments.api.PaymentsClient({
environment: 'TEST',
paymentDataCallbacks: {
onPaymentAuthorized: onPaymentAuthorized
}
});
}
return paymentsClient;
}

how to insert an image in a specific location using Google Docs API

I am managing to insert text into specific location in a document using batchUpdate, But I couldn't find any resource to how to do the same only with images. Any documentation about the matter will be highly appreciated. My text replacing function looks like that:
async function updateDoc(docs, auth, documentId) {
try {
await docs.documents.batchUpdate({
auth,
documentId: documentId,
requestBody: {
requests
}
});
} catch (error) {
console.log(error)
}
}
Will be great to have something similar for images.
You want to insert an image to Google Document with Google Docs API.
You want to achieve this using googleapis with Node.js.
You have already been able to get and put values for Google Document with Docs API.
If my understanding is correct, how about this answer? Please think of this as just one of several possible answers.
When it inserts an image to Google Document with Docs API, in the current stage, it uses URL of the image. The sample script is as follows.
Sample script:
Please use requests for your script.
const requests = [{
insertInlineImage: {
location: {index: 1},
uri: "https://cdn.sstatic.net/Sites/stackoverflow/company/img/logos/so/so-logo.png"
}
}];
In this request body, the logo of stackoverflow is inserted to the top of body in the Google Document.
Note:
When you want to insert the specific index, at first, please retrieve the index using the method of documents.get in Docs API.
If you want to use the uploaded image in Google Drive, please use the direct link of the URL in the Google Drive. In this case, please share the image and insert it with the above request body.
Reference:
InsertInlineImageRequest
If I misunderstood your question and this was not the direction you want, I apologize.

What is the proper architecture for requesting a document vs. document details in a REST API?

I'm designing a REST API using NodeJS and Express for managing different types of documents (txt, pdf, doc, etc). The document model is something like:
{
id,
category,
name,
path,
tags,
etc..
}
I currently have a route to GET a single document.
/documents/:id
This route serves up the actual document. I would love some guidance on the proper way to serve up the document details (i.e. the name, category, etc). Should I use a different URL? Send details in headers? Use response.format? Make the client specify via query?
Edit: I should clarify that the documents will be stored on the server filesystem and will not be directly accessible by any client.
If the document details are coming from a different source, the most straightforward way is to set up a different endpoint, /document-details/:id.
Otherwise, if a document can be stringified into a JSON, you could nest both in the same response:
{
document: {},
details: {
category,
name,
path,
tags
}
}
I would recommend against sending any detail about document in the HTTP header, those are usually used to send the details about the response itself.

Using customer object information in private app

I'm currently trying to build a private app which will allow me to create a form which customers can use to update info like name, email address, etc.
I know that I can access this information in my template through the customer object:
https://help.shopify.com/themes/liquid/objects/customer
I also believe that I can send http requests through the admin api which would allow me to update a given customer object:
https://help.shopify.com/api/reference/customer#update
This is an example PUT request from that page
PUT /admin/customers/#{id}.json
{
"customer": {
"id": 207119551,
"email": "changed#email.address.com",
"note": "Customer is a great guy"
}
}
I think that in order to use this api (or at least use it securely) I need to use a private app. I found the following npm package which I would use to create the private app:
https://www.npmjs.com/package/shopify-node-api
This is an example of a PUT request from that page (I think this can be modified for customers):
var put_data = {
"product": {
"body_html": "<strong>Updated!</strong>"
}
}
Shopify.put('/admin/products/1234567.json', put_data, function(err, data, headers){
console.log(data);
});
Does anyone have any experience doing this as I'm unsure about a few things.
Will this PUT request be called when the url is loaded? So if I have an
<a> tag with href="/admin/products/1234567.json the request would load?
If so, this seems quite useless with the customer ID hardcoded in. Can I pass in the customer ID of whoever is logged in and clicking the link and use that as the last part of the request url somehow? In addition to this would it be possible to grab the form data that the user enters to use as the value for "email" or "note?
You should check out this answer shopify app proxy: send customer data or only customer ID for some pointers, discussion and links.
tl/dr; Don't rely on only the logged in customer id or you'll be opening yourself up to easy hackery.
So bascially you update the customer with the PUT you outlined in your question.
To get the id securely you:
Create a form with the customer id and make sure you have a server generated hash of that customer id to thwart bots (that's the reference post)
You post the customer data to a an app via a proxy url
You update the customer via a PUT to a constructed url.

Paypal: Transaction History with REST API / Nodejs SDK

I would like to display all the inbound/outbound transactions a user made/received to display it in a simple html list.
I'm using the recommended node.js module https://github.com/paypal/rest-api-sdk-nodejs and I'm trying to use this code to get the transactions:
// Get Transaction History
paypal.payment.list({
'count': 100,
'sort_by':'create_time',
'sort_order': 'asc',
'start_time': '2008-03-06T11:00:00Z'
}, function(error, payment_history){
if(error){
console.error('error', error);
response.data.payment_history = {};
} else {
console.log('history', payment_history);
response.data.payment_history = payment_history;
}
response.finish();
});
but payment_history gives me { count: 0 }. I'm pretty sure that I have transactions since 2008.
I'm not really sure what's the problem. The user is already logged in using the access_token and I can display user informations but I have no idea how to pull transaction informations.
Look into https://developer.paypal.com/docs/faq/#general-developer-questions for the answer to "Can I retrieve the history of transactions created using the Classic APIs using the REST API?".
I also ran into this issue. Strangely, It seems that the PayPal REST API only returns results for payments made through the REST API. See here: https://stackoverflow.com/a/18139747
Classic API will remain the way to do this until the REST API is improved.

Resources