Can anyone guide me to an example using the webapi to query contacts based on a custom field? ie. find contact where myCustomId = 1234
Alle Svar (9)
Hi Snorre,
Assuming you know that in the APIs companies are contacts and contacts are persons...
The Custom Objects page, specifically the searching custom objects section, in docs details how to translate a custom field (user-defined field (udef) or extra field) into a search criteria field.
With that, here is a raw HTTP GET request to select a company ID and name, where the custom field x_hassupportagreement == 0.
GET https://{{env}}.superoffice.com/{{tenant}}/api/v1/contact?$select=contactId,name&$filter=contactExtra/x_hassupportagreement eq 0 HTTP/1.1
Authorization: Bearer {{token}}
Content-Type: application/json
Accept: application/json
GET https://{{env}}.superoffice.com/{{tenant}}/api/v1/contact?$select=contactId,name&$filter=contactUdef/SuperOffice:3 eq 0 HTTP/1.1
Authorization: Bearer {{token}}
Content-Type: application/json
Accept: application/json
using raw http request, when requesting this GET:
https://sod2.superoffice.com/Cust42245/api/v1/person?$select=personId,name&$filter=personExtra/x_personid%20eq%201234
I receive 200 and this, which I assume means "no hits"
{
"odata.metadata": "https://sod2.superoffice.com:443/Cust42245/api/v1/Archive//$metadata",
"odata.nextLink": null,
"value": []
}
PersonID is a short text field, can that be the problem?
I was hoping this would work, but it throws the exception "Forbidden Forbidden".
ArchiveListItem[] results = await archiveAgent.GetArchiveListByColumnsAsync(
"ContactPersonDynamicSelectionV2",
new []{"personId","firstName"},
new[]
{
new ArchiveOrderByInfo()
{
Name = "personId",
Direction = OrderBySortType.ASC
}
},
new[]
{
new ArchiveRestrictionInfo()
{
Name = "personExtra/x_personid",
Operator = "=",
Values = new [] { "1234" }
}
},
new[] { "person" },
0,
int.MaxValue);
Hi Snorre,
Only use the selection providers if you have a comprehensive understanding of the SuperOffice Find API.
You can simplify by using the Person archive provider instead.
EDIT: When using the SuperOffice.WebApi nuget package, make sure to se IsActive to true.
Example:
var archiveAgent = new ArchiveAgent(config);
var provider = "Person";
var entities = new[] { "person" };
var personId = new[] { "12345" };
var columns = new string[] { "personId", "firstName" };
var restrictions = new ArchiveRestrictionInfo[]
{
new ArchiveRestrictionInfo()
{
Name = "personExtra/x_personid",
Operator = "=",
Values = personId,
IsActive = true
}
};
var sortOrders = new ArchiveOrderByInfo[]
{
new ArchiveOrderByInfo()
{
Name = "personId",
Direction = OrderBySortType.ASC
}
};
results = await archiveAgent.GetArchiveListByColumnsAsync(
provider,
columns,
sortOrders,
restrictions,
entities,
0,
int.MaxValue);
Hope this helps.