REST URL convention [closed] - api

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I have an application table that has columns like quoteId, accountNumber, and few others. I have created a REST endpoint to update the account number on the basis of quoteId i.e Update account no. in the application that has quoteId = {quoteId}. Here is the endpoint:
PUT /applications/quotes/{quoteId}/accountNumber
Is it the correct REST convention?

Is it the correct REST convention?
Maybe.
If your PUT/PATCH/POST request uses the same URI as your GET request, then you are probably on safe ground. If PUT/PATCH/POST are using different URI, then something has Gone Wrong somewhere.
In other words, if /applications/quotes/{quoteId}/accountNumber is a resource that you link to, then it is the right idea that you send unsafe requests to that URI.
But if accountNumber is information normally retrieved via /applications/quotes/{quoteId}, then /applications/quotes/{quoteId} should be the target resource for edits (instead of creating a new resource used for editing only).
The reason for this is cache-invalidation, as explained in RFC 7234.
If this isn't immediately clear to you, then I suggest reviewing Jim Webber's 2011 talk on REST.

You should use PATCH instead of PUT for partial object updates.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH
https://www.infoworld.com/article/3206264/how-to-perform-partial-updates-to-rest-web-api-resources.html

In my opinion, your url must be:
PUT /applications/quotes/{quoteId}
payload: {
accountNumber: <number>,
... any other field...
}
Because you only want to update a part of an object of the list of quotes that you identify uniquely with quoteId.
About the use of PUT or PATCH, it's true that PUT means that you want to keep the object as the updated copy that you are sending (you must send in this case the entire object to make the update) but the fact is (I think) that many of us use PUT like you, to do partial updates of object.

Related

Pass data from Shopify URL to saved order [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
What is a method of passing custom data through a Shopify URL and having that data stored with the order (for later extraction through reports, admin access, API pull, etc.)?
For example, I would like to produce URLs like
examplestore.com/products/soccerball?aff=123456
(for an external affiliate tracking system), and have that 123456 be saved with the order. Then I could pull the orders from Shopify and know which orders were associated with which affiliates.
I realize there are affiliate apps for use within Shopify, but they seem to want to own the affiliate definition and data. This isn't what I need, as the IDs I pass in are entirely owned and managed by an external system.
Shopify allows to add some properties to the line items associated with an order. So, You can add properties to the products before adding to cart.
for that you can Refer the URL: https://cartjs.org/pages/reference#core-api-add-item
Now from all your orders you can filter them through the properties in their line items.
I found the answer here: Shopify Permalink Cart Preloading
Using a permalink to create a cart with one or more items in it, extra parameters can be added to the URL that provide additional information (including shipping address, but especially including data such as an affiliate id).
For example,
example-store.myshopify.com/cart/variant_id:quantity?ref=external_referral_id
will result in a cart that, when checked out and completed, will store the referral ID with the order.

To prevent multiple login with same user Id [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I had implement session to store the user id, but after that i realized that only work for single browser not for different browser. I think the session is store in the browser. Do you guys got any idea implement this?
The way I do this is that I log the date/time the user logs in and out of the program/website, for example:
---------------------------------------------------
| username | lastLoggedIn | lastLoggedOut
---------------------------------------------------
| Joe | 06/05/2015, 17:12 | 06/06/2015, 17:16
---------------------------------------------------
| Bob | 04/05/2015, 19:16 | 04/05/2015, 20:21
My code then compares the lastLoggedIn entry with the lastLoggedOut entry; if the lastLoggedOut entry is earlier than the lastLoggedIn entry, then the user is still logged in and we can prevent them logging in again.
To verify this, we need to compare the two entries, firstly splitting them into separate Date and Time variables and then working on the values given.
As the author of the question has pointed out:
what if the user simply closes their browser without logging out
first?
This situation is slightly trickier to handle, but nonetheless doable. I'm unsure for VB.NET, but for C# you are able to catch a browser closing event by using onbeforeunload.
If you're using HTTP Keep Alive (it can be enabled in IIS, see here), simply scan the concurrent server connections for the IP; if it is not found then update the user's lastLoggedOut field.
what if the web server crashes when users are logged in?
Though hopefully you've programmed your web application so that won't happen, a crash or power outage could happen at any time. This does mean that users will still be listed as logged in in the database.
To fix this, simply add a check when the web-app starts up to check for users still listed as logged in; you can then 'log them out' by replacing the entry with a valid one.
For completion, you might also want to dump the members who were 'repaired' by the system into a file so that if any of them have further issues you have an audit trail.

How can i delete a contact from a list with the mailjet api and php? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I use mailjet api to send newsletter, but i don't know how delete a contact from a list.
Please help me.
I'm a developer evangelist here at Mailjet.
The relation between a contactlist and a contact is represented through the listrecipient entity. You can learn more about this in our guide, here:
To remove a contact from a list, you have two options: either DELETE this entity or unsubscribe the contact from the list. The second solution has the advantage to keep the contact's status in the list. It prevents to send unwanted emails to a contact, if for some reason you add it in the list again later.
First, do a GET request to retrieve the ID of the listrecipient entity.
As described in our reference documentation, here, use the Contact and ContactsList filter.
Once you have the ID, you can either run a DELETE request on it to permanently delete the contact in the list or set the IsUnsubscribed property to true to unsubscribe it.

From the SQL to the Mongo way of designing a DB [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to understand how to solve certain issues on Mongo, I had been working with SQL for a while and I know the basics of DB design, many of those are useless in Mongo, since is completely different.
Here's an example. I have user credentials (username, password), user information (name, lastname, ...), and user facebook information (friend list, likes, ecc). In MySQL a good way to organize that is in 3 tables, one for credentials, one for general user information, and one for fb user information, all 3 related by the user ID. In that way if I need to login the user I need to query just the credentials table that have very light rows (3 columns; id, username, password).
Well, how this argument can be translated to the non relational realm? Do I extend my users object by adding the general info and the facebook info as arrays?:
user =>array(
'username' => 'user1',
'password' => 'pass1',
'gInfo' => array('name' => '','lastname' => ''),
'fbInfo' => array('likes' => '','friends' => '')
)
Or like in SQL, its better if I created two new objects related by the Mongo _ID of the user.
So here is your real case.
"Do my so called 'relations' exceed a reasonable amount of 'records' per user, and does it make sense to maintain that information in a separate 'relational' store?"
So if your answer to that is no then you are a good candidate for using the MongoDB "embedded document" form. Part of that answer may derive from, 'I always did it that way because they told me so".
Half the point of why MongoDB exists is to provide an alternative to modeling in, "Second normal form", "Third normal form" semantics, in the case where this makes sense to the usage patterns and storage requirements. And generally to say that the concept of document embedding exists to avoid the need to fetch "related" results from another collection as the results are already embedded in the response document.
Is it better to have different Id's? You mean in different collections. Where MongoDB does
not do Joins. Then the case would be probably not, but if you need it then consider the consequences.
As the wise Jedi said, "Unlearn, what you have learned". And apply a different way of thinking to your schema design, the MongoDB will suit you well.
Good luck Padawan.

Is there an API to get a list of gmail filters and update them? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
Google Apps has an "Google Apps Email Settings API" which allows to create a new mail filter via an API call.
Is there any (perhaps undocumented) way to get the list of current filters and update them?
A Filter object was added to the API that allows for filter processing, including retrieval, creation and deletion.
https://developers.google.com/gmail/api/guides/filter_settings
Specifically:
Listing Filters
GET https://www.googleapis.com/gmail/v1/users/userId/settings/filters
Returns a JSON list of Filter objects
Retrieving a specific Filter
GET https://www.googleapis.com/gmail/v1/users/userId/settings/filters/id
Returns a single JSON Filter object
Deleting a specific Filter
DELETE https://www.googleapis.com/gmail/v1/users/userId/settings/filters/id
Creating a Filter
POST https://www.googleapis.com/gmail/v1/users/userId/settings/filters
With a JSON encoded Filter in the request body.
While the REST URLs have v1 in the address, they are linked from the current documentation. Also note, GMail API migration is currently in progress, and the deprecated API will cease to function as of July 2016. Keep this in mind, as the API may change.
No. There is no API to retrieve filters, only create new ones (as you found).
However, users can export all of their filters from the UI and re-import them into another account manually:
Using Filters
I haven't tried it, but according to the Google Admin SDK docs, it looks like you can:
https://developers.google.com/admin-sdk/email-settings/#retrieving_labels