I am very close to getting everything to work. I have at this point been able to generate a User Access Token using the .NET SDK. However, when I use this token to call the search API I get an HTTP 200 response, but no results (see below). The file I am searching for is there and when I use the OAuth Authorization on the Search API reference page the file is found. So I am getting an access token that is accepted but it is not returning the file.
{
"total_count": 0,
"entries": [],
"limit": 30,
"offset": 0
}What could be wrong if my access token is accepted but the search results don't return any files?
I am using a single Box.com developer account. The enterprise ID is the same for both my application and the Box.com account that contains the file I am looking for. They are one in the same.
Here is the code I am using to generate the User Access Token.
using Box.V2.Config;
using Box.V2.JWTAuth;
using Box.V2.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JwtCreation
{
public class BoxJwtUtilities
{
public async static void GetAuthorization()
{
var boxConfig = new BoxConfig("", // client id
"", // client secret
"", // enterprise id
"-----BEGIN ENCRYPTED PRIVATE KEY-----\n\n", // Private key
"", // Private key password or passphrase
""); // public key id
var boxJWT = new BoxJWTAuth(boxConfig);
// Authenticate
var adminToken = boxJWT.AdminToken(); //valid for 60 minutes so should be cached and re-used
var adminClient = boxJWT.AdminClient(adminToken);
// Create an App User
var userRequest = new BoxUserRequest() { Name = "test appuser", IsPlatformAccessOnly = true };
var appUser = adminClient.UsersManager.CreateEnterpriseUserAsync(userRequest).Result;
// get a user token
var userToken = boxJWT.UserToken(appUser.Id.ToString());
}
}
}
