Fetching actual data from Netsuite rather than HATEOAS links - rest

While fetching the data from Netsuite using REST web Services. I am getting the following data as response. Is there any way where instead of HATEOAS links, I can get the actual data? I want to dump all the data to a file and in doing so I would have to make multiple calls with each id to get the data. Is there any way I can fetch all of the data with a single API call?
{
"links": [
{
"rel": "next",
"href": "https://demo123.suitetalk.api.netsuite.com/services/rest/record/v1/salesorder?limit=2&offset=2"
},
{
"rel": "last",
"href": "https://demo123.suitetalk.api.netsuite.com/services/rest/record/v1/salesorder?limit=2&offset=8"
},
{
"rel": "self",
"href": "https://demo123.suitetalk.api.netsuite.com/services/rest/record/v1/salesOrder/?limit=2"
}
],
"count": 2,
"hasMore": true,
"items": [
{
"links": [
{
"rel": "self",
"href": "https://demo123.suitetalk.api.netsuite.com/services/rest/record/v1/salesorder/39"
}
],
"id": "39"
},
{
"links": [
{
"rel": "self",
"href": "https://demo123.suitetalk.api.netsuite.com/services/rest/record/v1/salesorder/40"
}
],
"id": "40"
}
],
"offset": 0,
"totalResults": 8
}

Use the expandSubResources parameter as part of your get request. Set it to true to expand subitems and sublists.
hat tip #johnny for the assist!

Related

Paypal API v2-API response missing seller_receivable_breakdown

How could I find the seller_receivable_breakdown field from Paypal v2 API?
When I capture the payment, I don't get a seller_receivable_breakdown back in the API response, which should contain the net_amount.
Is there a reason why?
API Response:
{
"create_time": "2020-05-08T18:06:08Z",
"id": "35W12417YE077383Y",
"intent": "CAPTURE",
"links": [
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/35W12417YE077383Y",
"method": "GET",
"rel": "self",
"title": "GET"
}
],
"payer": {
"address": {
"country_code": "SG"
},
"email_address": "sb-vnmn01690912#personal.example.com",
"name": {
"given_name": "John",
"surname": "Doe"
},
"payer_id": "ZMVMLDB2Q3RNS"
},
"purchase_units": [
{
"amount": {
"currency_code": "USD",
"value": "76.00"
},
"payee": {
"email_address": "sb-dtlz4548886#business.example.com",
"merchant_id": "9D3W7QWY9MULE"
},
"payments": {
"captures": [
{
"amount": {
"currency_code": "USD",
"value": "76.00"
},
"create_time": "2020-05-08T18:06:37Z",
"final_capture": true,
"id": "1DU784512L090023U",
"links": [
{
"href": "https://api.sandbox.paypal.com/v2/payments/captures/1DU784512L090023U",
"method": "GET",
"rel": "self",
"title": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v2/payments/captures/1DU784512L090023U/refund",
"method": "POST",
"rel": "refund",
"title": "POST"
},
{
"href": "https://api.sandbox.paypal.com/v2/checkout/orders/35W12417YE077383Y",
"method": "GET",
"rel": "up",
"title": "GET"
}
],
"seller_protection": {
"dispute_categories": [
"ITEM_NOT_RECEIVED",
"UNAUTHORIZED_TRANSACTION"
],
"status": "ELIGIBLE"
},
"status": "COMPLETED",
"update_time": "2020-05-08T18:06:37Z"
}
]
},
"reference_id": "default",
"shipping": {
"address": {
"address_line_1": "123 Thomson Rd.",
"admin_area_1": "SG_zip = 308123",
"admin_area_2": "Singapore",
"country_code": "SG",
"postal_code": "308123"
},
"name": {
"full_name": "Doe John"
}
}
}
],
"status": "COMPLETED",
"update_time": "2020-05-08T18:06:37Z"
}
Either it may not be there in sandbox mode, or you may need to do a get operation on the capture id.
https://developer.paypal.com/docs/api/payments/v2/#captures_get
I contacted PayPal support about this and this is their response:
Unfortunately, it looks like the capture response will not include the "seller_receivable_breakdown" if the capture is still pending. You can see that mentioned under the "seller_receivable_breakdown" variable in this documentation about the captures object. If the capture is pending or processing still, (this happens often when a customer opts for a card transaction rather than a PayPal account balance transaction), then the capture response won't show the seller_receivable_breakdown but you can call for details on the capture right after it has finished to then see that object.
PayPal may hold a "suspicious" transaction for few days and the transaction is in a "Pending" state during the hold. Some transaction might even require your personal approval. While the transaction is on hold you cannot get the seller_receivable_breakdown via API (though this data is available in the dashboard).
You can setup a WebHook to fire on "Payment capture completed" and retrieve the information there. Be ready that the WebHook might fire in couple of days after the order.

Paypal subscription webhook for recurring payment

I had set up Paypal webhooks to track the recurring payments. I had set up webhook for
BILLING.SUBSCRIPTION.UPDATED
BILLING.SUBSCRIPTION.RE-ACTIVATED
BILLING.SUBSCRIPTION.RENEWED
BILLING.SUBSCRIPTION.CANCELLED
BILLING.SUBSCRIPTION.EXPIRED
BILLING.SUBSCRIPTION.SUSPENDED
BILLING.SUBSCRIPTION.PAYMENT.FAILED
BILLING.SUBSCRIPTION.ACTIVATED
I am not getting any event apart from Activate. can anyone help me to find out the hook that I need to set up to track transactions for the recurring subscription billing?
Thanks
In the webhook simulator PAYMENT.SALE.COMPLETED is not fully shown, but it is correct to use when payment for a subscription is made. It also has a subscription_id (it called billing_agreement_id for some reason).
{
"id": "WH-528005538C798144N-7H391362AP602264K",
"create_time": "2021-04-17T22:45:35.950Z",
"resource_type": "sale",
"event_type": "PAYMENT.SALE.COMPLETED",
"summary": "Payment completed for CAD 14.55 CAD",
"resource": {
"billing_agreement_id": "I-37B4TLL0FAJJ",
"amount": {
"total": "14.55",
"currency": "CAD",
"details": {
"subtotal": "14.55"
}
},
"payment_mode": "INSTANT_TRANSFER",
"update_time": "2021-04-17T22:44:02Z",
"create_time": "2021-04-17T22:44:02Z",
"protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE",
"transaction_fee": {
"currency": "CAD",
"value": "0.72"
},
"protection_eligibility": "ELIGIBLE",
"links": [
{
"method": "GET",
"rel": "self",
"href": "https://api.sandbox.paypal.com/v1/payments/sale/44P499886K055384U"
},
{
"method": "POST",
"rel": "refund",
"href": "https://api.sandbox.paypal.com/v1/payments/sale/44P499886K055384U/refund"
}
],
"id": "44P499886K055384U",
"state": "completed",
"invoice_number": ""
},
"status": "PENDING",
"transmissions": [
{
"webhook_url": "https://webhook.site/7ece4e68-de87-46df-a341-5d3dc580efe6",
"transmission_id": "b02ef980-9fce-11eb-b0ec-5bc241fbaaf3",
"status": "PENDING"
}
],
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-528005538C798144N-7H391362AP602264K",
"rel": "self",
"method": "GET",
"encType": "application/json"
},
{
"href": "https://api.sandbox.paypal.com/v1/notifications/webhooks-events/WH-528005538C798144N-7H391362AP602264K/resend",
"rel": "resend",
"method": "POST",
"encType": "application/json"
}
],
"event_version": "1.0"
}
See https://developer.paypal.com/docs/integration/direct/webhooks/event-names/#subscriptions
It looks like you want PAYMENT.SALE.COMPLETED
There is also one for refunded and reversed.

JSON API: Correct way to show links?

I made a JSON API using Laravel with Laravel 5 JSON API Transformer package which was listed on jsonapi.org
For now, everything works as expected, a sample response from my api is like (btw the validation failed so i took a look at the jsonapi specs):
{
"data": [
{
"type": "inventory",
"id": "INV0001",
"attributes": {
"inv_inventory_id": "INV0001",
"inv_owner_company_id": 1,
"inv_owner_department_id": 1,
"inv_user_department_id": 1,
"inv_user_worker_id": 1,
"title": "Schreibtisch"
},
"links": {
"self": {
"href": "http://127.0.0.1:8000/api/v2/inventory/INV0001"
},
"user": {
"href": "http://127.0.0.1:8000/api/v2/worker/1"
},
"owner_dept": {
"href": "http://127.0.0.1:8000/api/v2/department/1"
},
"owner_comp": {
"href": "http://127.0.0.1:8000/api/v2/company/1"
}
},
"relationships": {
"worker": {
"data": {
"type": "worker",
"id": "1"
}
},
"department": {
"data": {
"type": "department",
"id": "1"
}
},
"company": {
"data": {
"type": "company",
"id": "1"
}
}
}
}
],
"included": [
{
"type": "worker",
"id": "1",
"attributes": {
"wrk_forename": "Moritz",
"wrk_surname": "ASDF",
"wrk_department_id": 2,
"wrk_homeoffice": true,
"wrk_room_id": 1
},
"links": {
"self": {
"href": "http://127.0.0.1:8000/api/v2/worker/1"
},
"hardware": {
"href": "http://127.0.0.1:8000/api/v2/worker/1/hardware"
},
"software": {
"href": "http://127.0.0.1:8000/api/v2/worker/1/software"
},
"inventory": {
"href": "http://127.0.0.1:8000/api/v2/worker/1/inventory"
},
"accessory": {
"href": "http://127.0.0.1:8000/api/v2/worker/1/accessory"
}
}
},
{
"type": "department",
"id": "1",
"attributes": {
"department": "Entwicklung",
"dept_floor_id": 3
},
"links": {
"self": {
"href": "http://127.0.0.1:8000/api/v2/department/1"
},
"floor": {
"href": "http://127.0.0.1:8000/api/v2/floor/3"
},
"hardware": {
"href": "http://127.0.0.1:8000/api/v2/department/1/hardware"
},
"software": {
"href": "http://127.0.0.1:8000/api/v2/department/1/software"
},
"inventory": {
"href": "http://127.0.0.1:8000/api/v2/department/1/inventory"
},
"accessory": {
"href": "http://127.0.0.1:8000/api/v2/department/1/accessory"
}
}
},
{
"type": "company",
"id": "1",
"attributes": {
"company": "GermanPersonnel",
"com_building_id": 1
},
"links": {
"self": {
"href": "http://127.0.0.1:8000/api/v2/company/1"
}
}
}
],
"links": {
"self": {
"url": "http://127.0.0.1:8000/api/v2/inventory?page[number]=1&page[size]=10"
},
"first": {
"url": "http://127.0.0.1:8000/api/v2/inventory?page[number]=1&page[size]=10"
},
"last": {
"url": "http://127.0.0.1:8000/api/v2/inventory?page[number]=1&page[size]=10"
}
},
"meta": {
"page": {
"total": 1,
"last": 1,
"number": 1,
"size": 10
}
},
"jsonapi": {
"version": "1.0"
}
}
But according to the specifications on jsonapi.org a link should look like
"links": {
"self": "http://127.0.0.1:8000/api/v2/inventory/INV0001"
},
My question is:
Is it legit to display a link like in my sample ouput as an object
with "href"? I'm pretty confused, because the package i used was
listed on jsonapi.org, but seems not to meet the specs.
BTW: My English might be a little bit confusing, but i hope i descriped my problem as well as possible
This is actually valid JSON API output base on the specification,
http://jsonapi.org/format/#document-links
Where specified, a links member can be used to represent links. The value of each links member MUST be an object (a “links object”).
A Valid Sample From Specification
"links": {
"related": {
"href": "http://example.com/articles/1/comments",
"meta": {
"count": 10
}
}
}
Each member of a links object is a “link”. A link MUST be represented as either:
a string containing the link’s URL.
an object (“link object”) which can contain the following members:
href: a string containing the link’s URL.
meta: a meta object containing non-standard meta-information about the link.
Therefore, your output is actually valid.

Spring hateoas pagination without using Spring Data

I want to implement pagination for my REST API.
The application uses Spring Hateoas 0.8, Spring MVC 3.2.4 and Spring Integration 2.2.4.
I see that Spring Hateoas has the PagedResources class but this does not split up the results into pages.
It seems that spring-data is required to have properly created pages with previous and next links correctly created.
I have tried this but the links are not correct and all results are displayed:
#RequestMapping(value = "/resources", method = RequestMethod.GET, produces="application/json")
public HttpEntity<Resources<RequestResource>> showAllAsResources() {
Iterable<? extends Request> people = requestAccess.getRequests();
RequestAssembler assembler = new RequestAssembler();
List<RequestResource> resources = assembler.toResources(people);
Resources<RequestResource> wrapped = new Resources<RequestResource>(resources, linkTo(RequestsController.class)
.withSelfRel());
return new HttpEntity<Resources<RequestResource>>(wrapped);
}
All google searches seem to point to spring-data.
I can't use spring-data as I get my data from spring-integration which calls a soap web service and it returns all results for a search.
I did try adding spring-data classes:
#RequestMapping(value = "/resources2", method = RequestMethod.GET, produces="application/json")
public HttpEntity<PagedResources<Resource<RequestResource>>> viewResources()
{
List<Request> requests = requestAccess.getRequests2();
Page page = new PageImpl<Request>(requests, new PageRequest(0, 5), requests.size());
RequestAssembler requestAssembler = new RequestAssembler();
return new ResponseEntity<PagedResources<Resource<RequestResource>>>(pagedResourcesAssembler.toResource(page, requestAssembler), HttpStatus.OK);
}
This presents the response below which seems to have correct links but all data is presented and not just the page data:
{
"links": [
{
"rel": "next",
"href": "http://lwss:9084/lerest/v1/resources2?page=2&size=5"
},
{
"rel": "prev",
"href": "http://lwss:9084/lerest/v1/resources2?page=0&size=5"
}
],
"content": [
{
"givenName": "Joe",
"familyName": "Bloggs101",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/101"
}
]
},
...
{
"givenName": "Joe",
"familyName": "Bloggs200",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/101"
}
]
},
]
}
],
"page": {
"size": 5,
"totalElements": 100,
"totalPages": 20,
"number": 1
}
}
Is there any Spring classes that can help me achieve this or do I need to implement my own paging?
Many thanks,
Martin
UPDATE
Using the solution from Custom pagination by array list the following code produces the response below, though I think this is a bit of overkill. Are there any Spring helper classes that could achieve the same thing?
#RequestMapping(value = "/resources1", method = RequestMethod.GET, produces="application/json")
public HttpEntity<PagedResources<Resource<RequestResource>>> viewResources1(Pageable pageable)
{
int page = pageable.getPageNumber();
int count = pageable.getPageSize();
RequestAssembler requestAssembler = new RequestAssembler();
List<Request> requests = requestAccess.getRequests2();
int max = (count*(page+1)>requests.size())? requests.size(): count*(page+1);
Page<Request> pageRequests = new PageImpl<Request>(requests.subList(page*count, max), pageable, requests.size());
return new ResponseEntity<PagedResources<Resource<RequestResource>>>(pagedResourcesAssembler.toResource(pageRequests, requestAssembler), HttpStatus.OK);
}
{
"links": [
{
"rel": "next",
"href": "http://lwss:9084/lerest/v1/resources1?page=4&size=20"
},
{
"rel": "prev",
"href": "http://lwss:9084/lerest/v1/resources1?page=2&size=20"
}
],
"content": [
{
"givenName": "Joe",
"familyName": "Bloggs161",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/161"
}
]
},
{
"givenName": "Joe",
"familyName": "Bloggs162",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/162"
}
]
},
{
"givenName": "Joe",
"familyName": "Bloggs163",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/163"
}
]
},
{
"givenName": "Joe",
"familyName": "Bloggs164",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/164"
}
]
},
{
"givenName": "Joe",
"familyName": "Bloggs165",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/165"
}
]
},
{
"givenName": "Joe",
"familyName": "Bloggs166",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/166"
}
]
},
{
"givenName": "Joe",
"familyName": "Bloggs167",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/167"
}
]
},
{
"givenName": "Joe",
"familyName": "Bloggs168",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/168"
}
]
},
{
"givenName": "Joe",
"familyName": "Bloggs169",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/169"
}
]
},
{
"givenName": "Joe",
"familyName": "Bloggs170",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/170"
}
]
},
{
"givenName": "Joe",
"familyName": "Bloggs171",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/171"
}
]
},
{
"givenName": "Joe",
"familyName": "Bloggs172",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/172"
}
]
},
{
"givenName": "Joe",
"familyName": "Bloggs173",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/173"
}
]
},
{
"givenName": "Joe",
"familyName": "Bloggs174",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/174"
}
]
},
{
"givenName": "Joe",
"familyName": "Bloggs175",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/175"
}
]
},
{
"givenName": "Joe",
"familyName": "Bloggs176",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/176"
}
]
},
{
"givenName": "Joe",
"familyName": "Bloggs177",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/177"
}
]
},
{
"givenName": "Joe",
"familyName": "Bloggs178",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/178"
}
]
},
{
"givenName": "Joe",
"familyName": "Bloggs179",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/179"
}
]
},
{
"givenName": "Joe",
"familyName": "Bloggs180",
"links": [
{
"rel": "self",
"href": "http://lwss:9084/lerest/v1/180"
}
]
}
],
"page": {
"size": 20,
"totalElements": 100,
"totalPages": 5,
"number": 3
}
}

PayPal REST API - List of Refund Transactions

A few months ago I asked the following for a List of Sale Transactions:
PayPal Restful API - Pull List of Sale Transactions
In that question I got an answer referencing the List of Payment Resources call, which is great, but now I need to do something similar for refunds. However it's unclear to me from the documentation whether this includes Refunds.
Does the List of Payment Resources include Refund transactions (which would be a reverse payment of sorts), or is there some other way of accessing a list of Refund transactions?
Thanks in advance.
You currently cannot specifically get a list of refunded transactions. However, as you mention, you can get a list of payments and within that you will see the state of the sale object as refunded and a refund object with the state of completed:
Example:
{
"id": "PAY-ABCDEFGHIJKLMNO1234567890",
"create_time": "2013-09-20T15:44:04Z",
"update_time": "2013-09-20T16:10:05Z",
"state": "approved",
"intent": "sale",
"payer": {
"payment_method": "paypal",
"payer_info": {
"email": "bob-facilitator#example.com",
"first_name": "Bob",
"last_name": "Example",
"payer_id": "ABCDEFG123456"
}
},
"transactions": [
{
"amount": {
"total": "1.00",
"currency": "USD",
"details": {
"subtotal": "1.00"
}
},
"description": "example description",
"related_resources": [
{
"sale": {
"id": "ABCDEFGH123456789",
"create_time": "2013-09-20T15:44:04Z",
"update_time": "2013-09-20T16:10:05Z",
"state": "refunded",
"amount": {
"total": "1.00",
"currency": "USD"
},
"parent_payment": "PAY-ABCDEFGHIJKLMNO1234567890",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/12345678ABCDEFGIJ",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/12345678ABCDEFGIJ/refund",
"rel": "refund",
"method": "POST"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-ABCDEFGHIJKLMNO1234567890",
"rel": "parent_payment",
"method": "GET"
}
]
}
},
{
"refund": {
"id": "ABCDEFGH123456789",
"create_time": "2013-09-20T16:10:05Z",
"update_time": "2013-09-20T16:10:05Z",
"state": "completed",
"amount": {
"total": "1.00",
"currency": "USD"
},
"sale_id": "12345678ABCDEFGIJ",
"parent_payment": "PAY-57E15446PJ712294VKI6G2RA",
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/refund/ABCDEFGH123456789",
"rel": "self",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-ABCDEFGHIJKLMNO1234567890",
"rel": "parent_payment",
"method": "GET"
},
{
"href": "https://api.sandbox.paypal.com/v1/payments/sale/12345678ABCDEFGIJ",
"rel": "sale",
"method": "GET"
}
]
}
}
]
}
],
"links": [
{
"href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-ABCDEFGHIJKLMNO1234567890",
"rel": "self",
"method": "GET"
}
]
}