Autodesk Forge Bim 360 API-可以补丁用户
我正在尝试使用node.js'forge-api'软件包更新BIM 360用户(活动/非活动)及其公司的状态。
当前API中尚不可用此特定端点: htttps://forge.autodesk。 com/en/doc/bim360/v1/reference/http/user-:user_id-patch/
基于实现的端点(PatchItem),我对其进行了复制并修改如下:
const { ApiClient } = require('forge-apis');
function patchUser(accountId, oauthClient, credentials, res, userId, companyId, status) {
const body = {
status: status,
company_id: companyId
}
patchAPI(accountId, {}, oauthClient, credentials, body, userId)
.then(data => {
const { name, id, status, company_name } = data.body
res.json({name: name, id: id, status: status, company: company_name})
})
.catch(error => {
res.json(error)
})
}
async function patchAPI(hubId, opts, oauth2client, credentials, body, userId) {
opts = opts || {};
var postBody = body;
// verify the required parameter 'hubId' is set
if (hubId == undefined || hubId == null) {
return Promise.reject("Missing the required parameter 'hubId' when calling patchAPI with users");
}
// verify the required parameter 'userId' is set
if (userId == undefined || userId == null) {
return Promise.reject("Missing the required parameter 'userId' when calling patchAPI with users");
}
// verify the required parameter 'body' is set
if (body == undefined || body == null) {
return Promise.reject("Missing the required parameter 'body' when calling patchAPI with users");
}
var pathParams = {
'hub_id': hubId,
'user_id': userId
};
var queryParams = {};
var headerParams = {
'x-user-id': opts.xuserid
};
var formParams = {};
var contentTypes = ['application/vnd.api+json'];
var accepts = ['application/vnd.api+json', 'application/json'];
var returnType = null;
return ApiClient.instance.callApi(
'/hq/v1/accounts/{hub_id}/users/{user_id}', 'PATCH',
pathParams, queryParams, headerParams, formParams, postBody,
contentTypes, accepts, returnType, oauth2client, credentials
);
}
不幸的是,它没有修改用户。用户完全像以前一样返回,就像完全忽略了身体部位一样。
我知道我所有的ID都是正确的,因为我会收到状态200,并且用户返回(不变),并且可以成功用Postman修补用户。
不知道我缺少什么,但是任何帮助将不胜感激
I am trying to update the status of a BIM 360 user (active/inactive) and its Company using the Node.js 'forge-api' package.
This particular endpoint is not available yet in the current api:
https://forge.autodesk.com/en/docs/bim360/v1/reference/http/users-:user_id-PATCH/
Based on implemented endpoints (patchItem) I duplicated it and modified as follows:
const { ApiClient } = require('forge-apis');
function patchUser(accountId, oauthClient, credentials, res, userId, companyId, status) {
const body = {
status: status,
company_id: companyId
}
patchAPI(accountId, {}, oauthClient, credentials, body, userId)
.then(data => {
const { name, id, status, company_name } = data.body
res.json({name: name, id: id, status: status, company: company_name})
})
.catch(error => {
res.json(error)
})
}
async function patchAPI(hubId, opts, oauth2client, credentials, body, userId) {
opts = opts || {};
var postBody = body;
// verify the required parameter 'hubId' is set
if (hubId == undefined || hubId == null) {
return Promise.reject("Missing the required parameter 'hubId' when calling patchAPI with users");
}
// verify the required parameter 'userId' is set
if (userId == undefined || userId == null) {
return Promise.reject("Missing the required parameter 'userId' when calling patchAPI with users");
}
// verify the required parameter 'body' is set
if (body == undefined || body == null) {
return Promise.reject("Missing the required parameter 'body' when calling patchAPI with users");
}
var pathParams = {
'hub_id': hubId,
'user_id': userId
};
var queryParams = {};
var headerParams = {
'x-user-id': opts.xuserid
};
var formParams = {};
var contentTypes = ['application/vnd.api+json'];
var accepts = ['application/vnd.api+json', 'application/json'];
var returnType = null;
return ApiClient.instance.callApi(
'/hq/v1/accounts/{hub_id}/users/{user_id}', 'PATCH',
pathParams, queryParams, headerParams, formParams, postBody,
contentTypes, accepts, returnType, oauth2client, credentials
);
}
Unfortunately it is not modifying the user. The user is returned exactly as before, as if the Body part is completely ignored.
I know that all my Ids are correct because I receive a status 200 and user is returned (unchanged) and I can successfully PATCH the user with Postman.
Not sure what I am missing but any help would be much appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“ Forge-apis”软件包中提供的补丁端点是针对数据管理API的,其身体的内容类型必须为“应用程序/vnd.api+json”,
但是对于BIM 360 API,内容类型必须为是“应用/json”。
更改下面的线后,一切正常。
var contentTypes = ['application/json'];
The PATCH endpoints that are provided in the 'forge-apis' package are for the Data Management API and their Content-Type for the body must be 'application/vnd.api+json'
However for the BIM 360 API the Content-Type must be 'application/json'.
After changing the line below everything is working fine.
var contentTypes = ['application/json'];