Adding item to list using the Foursquare API - list

By using Foursquare's API I'm trying to add a new venue to a list that I made. Currently I use the this call:
https://api.foursquare.com/v2/lists/MY_USER_ID/tips/?venueid=4b3bb64ff964a520627925e3&oauth_token=XXXXXXXXX
Although the venueID is correct the output I do get is:
{
meta: {
code: 400
errorType: "param_error"
errorDetail: "Value 4b3bb64ff964a520627925e3 is invalid for item id"
}
response: { }
}
What might cause this error?

In order to add a venue to an existing list, you need to make a request to:
POST https://api.foursquare.com/v2/lists/LIST_ID/additem?venueId=4b3...&oauth_token=XXXX
Let me know if that request doesn't work for you

I was getting a similar issue on a different API call. The fix for my issue was to include the HTTP header content type like this: Content-Type: application/x-www-form-urlencoded

Related

Updating Sales Order line items in Dynamics business central

I have a sales order created using API for business central. Sales order has a single line item. I want to update the quantity of line item. Following is what I have tried so far.
Endpoint: https://api.businesscentral.dynamics.com/v1.0/domain.com/api/v1.0/companies(company_id)/salesOrders(sales_order_ide)/salesOrderLines(sales_order_line_id)
where sales order line id is of the form e86d3aa1-f2f8-ea11-aa61-0022481e3b8c-10000
as described in this document When a PATCH request is made, I get the following exception:
')' or ',' expected at position 9 in
'(sale-order-line-item-id)'.
The exception stated above was also occuring when i was simply trying to get the line item but that was fixed when I changed the URL and it took the form:
Endpoint:
https://api.businesscentral.dynamics.com/v1.0/domain.com/api/v1.0/companies(b4a4beb2-2d42-40dc-9229-5b5c371be4e3)/salesOrders(e86d3aa1-f2f8-ea11-aa61-0022481e3b8c)/salesOrderLines?filter=sequence eq 10000
This endpoint is returning correct response when i try to get the line item by issuing
GET request. However, when I issue a PATCH request using the same endpoint, with a simple request body e.g.
{"quantity" : 2.0}
it throws the exception:
'PATCH' requests for 'salesOrderLines' of EdmType 'Collection' are not
allowed within Dynamics 365 Business Central OData web services.
I am also specifying the if-Match header along with the request that contains etag value for the line item but of no avail and same exception is occurring. Am I missing something? Any help will be appreciated.
For those who may visit this question later, after much hit and trial through Postman, I finally figured out the problem. In my case if-Match header that's basically is Etag for the line item is all fine. The Problem was with API URL, specifically the way we specify the line item id. We have to specify this in single quotes so the URL for API call becomes:
https://api.businesscentral.dynamics.com/v1.0/domain.com/api/v1.0/companies(company_id)/salesOrders(sales_order_ide)/salesOrderLines('sales_order_line_id')
You would note that we are not specifying company_id and sales_order_id in single quotes, reason being, both of these parameters a of type GUID whereas sales_order_line_id is of type string as per metadata document.
I am getting below error
{
"error": {
"code": "BadRequest_NotFound",
"message": "Bad Request - Error in query syntax."
}
}

D365FO patch method to update Records

I am trying to update a value for data in D365FO with Patch method as below.
https://<URL>/data/DXCGeneralJournalAccountEntries(GeneralJournalAccountEntryRecId = 5637144584)
Body: {
"DXCAdeptiaProcessed": "2019-01-01T00:00:00Z"
}
error code that i am getting is
{
"Message": "No HTTP resource was found that matches the request URI
'/data/DXCGeneralJournalAccountEntries(GeneralJournalAccountEntryRecId = 5637144584)'. No route data was found for this request." }
Can you suggest why this error may be coming.
have you tried with putting ' around the identifier that you are using?
(GeneralJournalAccountEntryRecId = '5637144584')
It looks like the entity that you're trying to update is a custom entity and it may not have been exposed in the REST OData API.
If you submit a GET request to /Metadata/Entities you should be able to find the entity in the results. Here you can check the properties for that entity, it should look something like this:
{
"Name": "DXCGeneralJournalAccountEntries",
"PublicEntityName": "DXCGeneralJournalAccountEntries",
"PublicCollectionName": "DXCGeneralJournalAccountEntries",
"LabelId": "#SYS999999",
"DataServiceEnabled": true,
"DataManagementEnabled": true,
"EntityCategory": "Master",
"IsReadOnly": false
},
Otherwise the documentation might be able to help with exposing the entity: https://learn.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/data-entities/odata#exposing-odata-entities

Using postman to test POST request, how do I access the form-data inside the request?

I've been googling for a few hours, and I need help. I dont think I'm using the correct words. Anyhow, I'm using Claudia.JS to set up a POST request to my AWS Lambda function. Here's the basics of the function:
api.post('/leads', function (request) {
console.log(request);
return request;
});
When I use postman to test the post request, I'm returned the request object. Awesome. Then I try to pass form-data through. I set the key to 'username' and the value to 'this is the username'. This is what request.body is:
"body": "---------------------------
-019178618034620042564575\r\nContent-Disposition: form-data;
name=\"username\"\r\n\r\nthis is the username\r\n----------------------
------019178618034620042564575--\r\n",`
I thought I could return request.body.username... to key the value of username...but I'm missing something.
How do I access the form data in the request?
update: okay. The website is taking the form data, making a post request...this function is receiving the post request? still-- in postman...if I were to put my own JSON in...why can I not access request.body like... request.body.username?
You should try console.log(request.data) to see your request object, ie. in my own case I can see the content of my request's body.
Have a look at https://www.getpostman.com/docs/postman/scripts/postman_sandbox to see all the relevant information about your request.
I solved this by looking at the header set in postman. It was set to form-data instead of application/JSON. All gravy now.

How to send a parameter which is dictionary in Postman

I have just started using Postman for testing my API.
I am able to send list of request parameters, but could not figure out how will I send a parameter which is a dictionary,
say my request has two different parameters, first is property, and the structure of property is something like "ptype":"residential","mtype":"requirement","dtype":"sale","category":"multistoryapt","city":"Gurgaon,Mumbai"
How can I send these parameters together ?
I have explored on internet and there are ways of sending an array but not a dictionary.
Am I missing something ?
You could send data as raw body with the Content-Type application/json, this way it's up to you how the data is structured.
If you want to send it in the application/json format then the body should look like this:
{
"key1":"value1",
"key2":"value2"
}
For a comprehensive resource on how to serialise JSON go to http://www.newtonsoft.com/json/help/html/SerializingCollections.htm
If for some reason you cannot send it with json, here is how we send dictionaries in the form:
object[ptype], object[mtype], object[dtype], object[category], object[city]
You can do it with this:
POST Request in Postman:
Content-Type: Json/Application
{
"IsManual":true,
"platform":"IOS",
"barcodeList":{"1":"DSSDsdsdsas","2":"DSSDsdsdsas"},
"Client":"Cliente1",
"ScanDate":"2018-10-16T17:03:02.2347052-03:00"
}
I cam across this topic as I have a parameter
public Dictionary<string, string> Customer { get; set; }
for my REST API and I wanted to test it with Postman. Unfortunately I didn't find any quick help for how to send a Dictionary using Postman. After trying around some combinations this is what worked for me
Customer[0].Key:name
Customer[0].Value:Testname
Match the name of your dictionary and Request body dictionary name.
Suppose ,
Dictionary<string,string> randomName = new Dictionary<string,string(){{"key1","value1"} ,{"key2","value2"}};
so , your request for PostMan should be:
{
"randomName " : { "key1":"value1", "key2":"value2"}
}

Adding headers to HTTP request using cfhttp's addParam method

I'm new to Coldfusion and can't understand why I'm having so much trouble adding a couple of headers to an http request that I'm making with cfhttp. I'm trying to write the request using cfscript, and from everything I've read I should be able to simply do:
httpService.addParam(type="header", name="Content-Type", value="application/json");
or
httpService.addParam(type="header", name="Authorization", value=local.authPasscode);
But the outgoing request doesn't seem to contain these headers. I can tell it's not working because:
I'm getting errors back in my response
I'm doing a writeDump(GetHttpRequestData()), which shows all the details of the request (and this output does not show the Authorization header at all and shows the Content-Type header as:
multipart/form-data; boundary=----WebKitFormBoundaryZs9TyOQV02N3fQop
I also seem to have difficulty adding the body of the message in a similar way so I'm thinking I'm doing something wrong with addParam(). I'm attempting that like so:
httpService.addParam(type="body", value="hello");
Again, the response I get back has a bunch of missing field errors and the output of writeDump(GetHttpRequestData()) shows a missing body.
Am I supposed to be able to use addParam() in this way?
Full code:
httpService = new http();
httpService.setMethod("POST");
httpService.setUrl(application.config.beanstream.postURL);
local.authPasscode = "Passcode " & ToBase64(application.config.beanstream.merchantid & ":" & application.config.beanstream.APIPasscode, "utf-8");
// Set headers.
httpService.addParam(type="header", name="Authorization", value=local.authPasscode);
httpService.addParam(type="header", name="Content-Type", value="application/json");
// Construct the message body.
local.body = {
"test": "hello"
};
httpService.addParam(type="body", value=SerializeJSON(local.body));
writeDump(GetHttpRequestData());
local.result = httpService.send().getPrefix();
Update:
Okay, so I changed my postURL to that of another local page and on that page I'm using GetHttpRequestData() to log the method, protocol, headers and content all out to a file. Here's what I get:
POST
HTTP/1.1
{host={www.mysite.com},user-agent={ColdFusion},connection={close},content-length={16},authorization={Passcode Mjc1ODMwMDAwOjIwMTI5NGUwMjI2MzQxMzlBZjBFMDE2RmViRjg0RDAz},content-type={application/json}}
{"test":"hello"}
So it looks to me like I am indeed correctly sending a POST to the correct URL and the headers are getting set correctly as well. My content even seems like it's there so this is starting to feel like I'm sending invalid body data to the API. Unless anybody can think of anything else to check I'm going to investigate that further.
instead of
local.body = {
"test": "hello"
};
try
local.body = {};
local.body["test"] = "hello";
then you can
SerializeJSON(local.body)