How to get purchase order documents from tradeShift API? - rest

I am trying to get the trade shift purchase order using their API.
FYI, While I am making an API request,
I am using OAuth1.
I am using endpoint
https://api-sandbox.tradeshift.com/tradeshift/rest/external/documents?limit=5
In the header, When I set Accept as application/JSON, I am getting a response like
{
"itemsPerPage": 5,
"itemCount": 2,
"indexing": false,
"numPages": 1,
"pageId": 0,
"Document": []
}
But If I add nothing in the Header, I am getting an XML response.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ts:DocumentList xmlns:cec="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:ts="http://tradeshift.com/api/public/1.0" xmlns:ns6="http://tradeshift.com/api/1.0" xmlns:ns7="http://tradeshift.com/api/2.0" xmlns:ns8="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:ns9="urn:oasis:names:specification:ubl:schema:xsd:Quotation-2" xmlns:ns10="urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2" xmlns:ns11="urn:oasis:names:specification:ubl:schema:xsd:Order-2" xmlns:ns12="urn:oasis:names:specification:ubl:schema:xsd:OrderChange-2" xmlns:ns13="urn:oasis:names:specification:ubl:schema:xsd:ApplicationResponse-2" xmlns:ns14="urn:oasis:names:specification:ubl:schema:xsd:Reminder-2" xmlns:ns15="urn:oasis:names:specification:ubl:schema:xsd:RemittanceAdvice-2" xmlns:ns16="urn:oasis:names:specification:ubl:schema:xsd:ReceiptAdvice-2" xmlns:ns17="urn:oasis:names:specification:ubl:schema:xsd:Catalogue-2" xmlns:ns18="https://tradeshift.com/documents/ubl/xsd/Requisition-2" xmlns:ns19="urn:oasis:names:specification:ubl:schema:xsd:OrderResponse-2" xmlns:ns20="urn:oasis:names:specification:ubl:schema:xsd:RequestForQuotation-2" xmlns:ns21="urn:oasis:names:specification:ubl:schema:xsd:OrderResponseSimple-2" xmlns:ns22="urn:oasis:names:specification:ubl:schema:xsd:OrderCancellation-2" xmlns:ns23="urn:oasis:names:specification:ubl:schema:xsd:DespatchAdvice-2" indexing="false" numPages="1" pageId="0" itemsPerPage="5" itemCount="2"/>
I am not quite sure if the document is already there as UBL format.
Can you please ensure, if the document is already there as UBL.
If document is there, then How can I parse the document?
And if the document is not there, how can I get the documents?

The document is not there, that both responses are the same just the format is different.
In order to get the Documents that you receive in your Tradeshift account you should follow the below steps:
get the list with all the documents available in your account using the below API:
GET https://api-sandbox.tradeshift.com/tradeshift/rest/external/documents?type=order Content-Type=application/json Accept=application/json Authorisation=oauth1
As response, you will have a JSON with all the orders in your account and the details you will need to retrieve the UBL file of the order.
From the JSON resulted in point 1 using the DocumentId of the order you want to get make the below call
GET https://api-sandbox.tradeshift.com/tradeshift/rest/external/documents/{DocumentUUID} Content-Type=application/json Accept=application/xml Authorisation=oauth1
Once you get a file in order to get it marked as processed you can also tag the document using the below API call:
PUT https://api.tradeshift.com/tradeshift/rest/external/documents/{DocumentId}/tags/{your-tag}
At the first call, you can then add more parameters like withouttag in order to filter out the documents you have tagged already, like in the below call:
`GET https://api-sandbox.tradeshift.com/tradeshift/rest/external/documents?type=order&withouttag={your-tag}`

Related

IBM Maximo REST service POST not setting attributes on MBO

I have tried to create a record of my customized object through REST service in IBM Maximo.
The problem is that I created the record but I can't assign values to the attributes.
Next I will show what I did and what happened:
I have an Object Structure called oxidato that represents my customized object.
I did a POST using POSTMAN to this URL:
http://hostname:port/maximo/oslc/os/oxidato?lean=1
In the body section this is the JSON I was trying to send:
{
"attribute1":"205",
"attribute2":"206"
}
The record was created but none of the attributes was filled.
In my opinion, the REST service received the POST but can´t read the body.
What am I missing? I add an image of the POSTMAN as example:
EDIT1: I update the POST in order to use the newest API RES (Thanks Dex!)
EDIT2: I add an image of the header
I have found that Maximo will often ignore incoming attributes that aren't in the Maximo namespace (http://www.ibm.com/maximo). You could go through the trouble of setting up your VALOR1 and VALOR2 attributes to be in that namespace, but it's easier to just tell OSLC to ignore namespaces. You do that by setting the "lean" parameter to "1".
In your case, go to the "Params" tab and add an entry with a name of "lean". Give it a value of "1" and then send your POST again. You should see "?lean=1" appear at the end of the POST URL along the top there, but your body content should remain unchanged.
EDIT:
On the other hand, it looks like (based on your URL) that you aren't actually using the newer JSON/OSLC REST API; It looks like you are using the older REST services. This IBM page gives you a lot of information on the newer JSON REST API, including the correct URLs for it: https://developer.ibm.com/static/site-id/155/maximodev/restguide/Maximo_Nextgen_REST_API.html.
You should change your URL to /maximo/oslc/os/oxidato to use the newer API that naturally supports JSON and the lean parameter described above. This does required Maximo 7.6 to use though.
EDIT 2:
The attributes are often oddly case sensitive, requiring lowercase. Your example in your question of "attribute1" and "attribute2" are properly lowercase, but your screenshot shows uppercase attribute names. Try changing them to "valor1" and "valor2". Also, these are persistent attributes, right?
The response code received back (e.g. 200 - OK) and the response body will detail the record that was created.
I think you are correct in that the body of the post request is being ignored. Provided there are no required fields on the custom MBO your POST is probably creating an empty record with the next value in the sequence for the key field but you should see that in the response.
The following POST should create a record with values provided for attribute1 and attribute2 and provide a response with the record's identifier so that you can look it up in Maximo and show the values that were stored for attribute1 and attribute2:
http://hostname:port/maximo/rest/os/oxidato/?_format=json&_compact=1&attribute1=205&attribute2=206
Response: 200 OK
Reponse Body:
{ "CreateOXIDATOResponse": {
"rsStart": 0,
"rsCount": 1,
"rsTotal": 1,
"OXIDATOSet": {
"OXIDATO": {
"rowstamp": "[0 0 0 0 0 -43 127 13]",
"ATTRIBUTE1": "205",
"ATTRIBUTE2": "206",
"OXIDATOID": 13
}
} } }
You may also want to turn on debug logging for the REST interface in System Configuration -> Platform Configuration -> Logging for additional detail on what's happening in the log file.

How to get Sharepoint user by Title using REST?

I'm trying to search for a given user on a Sharepoint site using "lastname, firstname". I was able to use the following url to get the total list of site users as a large XML document:
https://thissite.com/sites/thatsite/_api/web/siteusers/
However, I haven’t been able to figure out how to search by Title. When I use the following url:
https://thissite.com/sites/thatsite/_api/web/siteusers/getbytitle(“lastname,%20firstname”)
I get this error:
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code>
-1, Microsoft.SharePoint.Client.InvalidClientQueryException
</m:code>
<m:message xml:lang="en-US">
The expression "web/siteusers/getbytitle("lastname, firstname")" is not valid.
</m:message>
</m:error>
When I use the following url to get the same user's data:
https://thissite.com/sites/thatsite/_api/web/siteusers/getbyid(41)
Then I successfully get XML returned with that user's data.
I guess I could just parse the list obtained from /siteusers and load it into a searchable data object, but I was hoping for something more direct.
UserCollection resource does not expose getbytitle method, that's the reason why you get this exception.
In order filter user by title you could utilize $filter query option as demonstrated below:
https://contoso.sharepoint.com/_api/web/siteusers?$filter=Title eq '<Title>'

RESTful URLs for collection of objects

I have an entity Temperature.
My URLs are designed as follows:
GET /api/temperatures/new
GET /api/temperatures/{id}/edit
GET /api/temperatures
POST /api/temperatures
PUT /api/temperatures/{id}
DELETE /api/monitoring/temperatures/{id}
I would like to create multiple temperatures (a collection of temperatures) at once - are there any conventions in terms of the urls to use?
So far, I came up with the following:
POST /api/monitoring/temperatures/collection
GET /api/monitoring/temperatures/cnew
I thought there must be a convention for this already so would like to check with you.
GET /api/temperatures # Getting all resources
POST /api/temperatures # Create new resource
GET /api/temperatures/<id> # Get a single resource
PUT /api/temperatures/<id> # Edit all fields
PATCH /api/temperatures/<id> # Edit some fields
DELETE /api/temperatures/<id> # Delete a resource
These are the kinds of URL's Fielding describes in his thesis on REST. You shouldn't be describing what an end point does in the URL especially when used properly the HTTP verbs provide plenty of information. Be aware the REST architectural style has more to it than JSON over HTTP. Generic connectors, decoupling of components and a stateless server are key components of a RESTful application.
Note: Most people probably wouldn't implement both PUT and PATCH. PUT will be fine but I included it for completeness.
In response to your comment, if you are referring to creating multiple resources with one POST request you don't need a new URL. Your application should be able to handle {temp: 45, date: ...} and [{temp: 45, date: ...}, {temp: 50, date: ...}] at the same endpoint.
The HTTP method GET is not suitable for creating or editing resources - /api/temperatures/new and /api/temperatures/{id}/edit. HTTP GET is used for getting information without changing state in a server. You should use POST or PUT.
If you want to create multiple temperatures, you should use
POST /api/monitoring/temperatures
and consume JSON or XML list of objects.
Java example:
#POST
#Path("/temperatures")
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public Response postTemperatures(Temperatures temperatures){
// process and save
}
#XmlRootElement
public class Temperatures {
public List<Temperature> temperatures;
Temperatures(){}
}
You can update multiple entries with a single post by sending in an array of temperatures instead of a single entry,
POST /api/temperatures { [{...},{...}] }
but your api endpoint structure could be streamlined a little.
Ideally you want a simple consistent interface for all API resources.
I would personally simplify:
GET /api/temperatures/new
GET /api/temperatures/{id}/edit
GET /api/temperatures
POST /api/temperatures
PUT /api/temperatures/{id}
DELETE /api/monitoring/temperatures/{id}
to
GET /api/temperatures // Get all temperatures
POST /api/temperatures // Send in array of new entries to update
GET /api/temperatures/{id} // Read a specific temperature
PUT /api/temperatures/{id} // Update a specific temperature
DELETE /api/temperatures/{id} // Delete a specific temperature
This gives a consistent interface to the api for all temperature related calls that maps onto a CRUD interface.
Without context its hard to work out exactly what /api/temperatures/new is used for, but I would consider using a parameter on the call for finegraining the response.
e.g.
/api/temperatures?age=new // Get new temps
Which will allow you to use the common structure to add different types of criteria later on.

Facebook Graph API event-id/comments?since=2014-02-01&until=2014-02-10 , Date filter has no effect

I am trying to bring comments made on a particular event by targeting this URL: https://graph.facebook.com/1466384840257158/comments
I am passing the user_access_token
I have two comments at present on this event made on the same
day(2014-03-29)
Now I try to pass a date which should bring an empty data result/object
like this: https://graph.facebook.com/1466384840257158/comments?since=2011-01-01&until=2014-01-10
This request has no effect, it still shows me the two comment made
on the 29th
I have tried the same kind of date range on my user-id/feed and it
gave me an empty data object.
Finally i tried event-id/feed (before trying date filter) and it
gave me the following error
.
{
"error": {
"message": "An unexpected error has occurred. Please retry your request later.",
"type": "OAuthException",
"code": 2
}
}
Could you please guide me about date filter on that particular query (point4) or if you have any other idea to use date filter on comments made for an event.
Comments use Cursor-based Pagination, so you cannot use since or until on the comments endpoint (these parameters would work f.ex. for the feed endpoint).
To get the comments in a time range you have to fetch all comments from NOW to the start of the time range, f.ex. with https://graph.facebook.com/1466384840257158/comments?filter=stream&limit=1000+paging (the filter=stream will order the result with the timestamp).
USING SINCE UNTIL FOR COMMENTS on GROUP
If you want to use since and until for comments, it is not possible directly for a group. So, First you can apply it for status(feed) and then get the comments for that feed.
This works for me:
{group_id}/?fields=feed.since(08/25/2016).until(08/31/2016){from,comments{from,message}}
Why don't you try first to filter by notifications?... notifications allows you to add parameters like since. For example (using Facebook pages):
https://graph.facebook.com/PAGEID?fields=notifications.since(2015-3-31 00:00:00).limit(250).include_read(true)&{id,created_time,updated_time,unread,object,link}&access_token=ACCESSTOKEN
Once you got the json data, loop through data, get the ID and send a second request but this time using the PAGEID_POSTID edge. Something like this:
https://graph.facebook.com/PAGEID_POSTID/comments?fields=id,from{name,id},message,can_remove,created_time&limit=1000
Voahla!... there's no need to read every comment!...
Note 1: A Page access token is required, along with the manage_pages permission
Note 2: Use the parameter/field include_read to get all the notifications, even the already readed
Note 3: In the second request, use the parameter/field "filter=stream" to order the posts and get the comments made in the name of your page
Note 4: Don't forget to control the asynchronicity once you loop!
Note 5: Notifications duplicate posts, use an array to avoid to read more than one time the postUse the parameter/field include_read to get all the notifications, even the already readed
I do not know if it's too late. But, Yeah it works in the graph api version 3.3.
for example: if you wanna get comments on a post of a Facebook page you can do it like this:
You have to use page Access-token
The get Graph Request : post_id/comments?since=some_date

v3 IPP FindAll is not returing the correct paged data when Customers are sub-customers

I'm using the below line:
commonService.FindAll(new Intuit.Ipp.Data.Customer(), currentPage, itemListPageSize).ToList();
When returning multiple pages the paging isn't returning the right rows on page if there are sub-customers. To reproduce, just create several customers and retrieve the second page like:
commonService.FindAll(new Intuit.Ipp.Data.Customer(), 2, itemListPageSize).ToList();
When it retrieves page 2, the first page's data is returned.
Am I doing something wrong?
FindAll with paging actually uses query endpoint.
Please mention if you are trying this call against QBD/QBO.
Can you please capture the raw request and response of the above call and share in this post.
(for that you can enable logger as mentioned in the following docs, or you can configure your app with any http snooper like Fiddler.)
https://developer.intuit.com/docs/0025_quickbooksapi/0055_devkits/0150_ipp_.net_devkit_3.0/logging
You can try this call directly using ApiExplorer. Please verify if you are getting the same result.
https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/020_key_concepts/00300_query_operations/0100_key_topics#Pagination
Thanks