oitathi
oitathi

Reputation: 175

Listing Envelope Status Changes using Java PARTNER_AUTHENTICATION_FAILED

I'm trying to get all status of the envelopes that was sended. I'm following this example: https://developers.docusign.com/esign-rest-api/code-examples/code-example-list-envelope-status-changes#run-the-examples.

@Component
@EnableScheduling
public class VerificadorDeAssinaturas {

@Autowired
private DocuSignProperties docuSignProperties;

private ApiClient apiClient;

@Scheduled(cron = "0 0/1 * * * *")
public EnvelopesInformation verificaNovasAssinaturas() throws IllegalArgumentException, IOException, ApiException {
    this.apiClient = new ApiClient(this.docuSignProperties.getBaseUrl());
    apiClient.addDefaultHeader("Authorization", "Bearer " + getTokenAcesso());
    EnvelopesApi envelopesApi = new EnvelopesApi(apiClient);

    ListStatusChangesOptions options = envelopesApi.new ListStatusChangesOptions();
    LocalDate date = LocalDate.now().minusDays(30);
    options.setFromDate(date.toString("yyyy/MM/dd"));

    EnvelopesInformation results = envelopesApi.listStatusChanges(this.docuSignProperties.getUserId(), options);
    return results;
}

private byte[] getByteFile() {
    byte[] privateKeyBytes = null;
    try {
        privateKeyBytes = FileCopyUtils.copyToByteArray(
                new ClassPathResource(this.docuSignProperties.getPrivateKeyFilename()).getInputStream());
    } catch (IOException | IllegalArgumentException ex) {
        ex.printStackTrace();
    }
    return privateKeyBytes;
}

private String getTokenAcesso() throws IllegalArgumentException, IOException, ApiException {
    OAuth.OAuthToken oAuthToken = apiClient.requestJWTUserToken(this.docuSignProperties.getIntegratorKey(), this.docuSignProperties.getUserId(), getScopes(), getByteFile(), 3600);
    return oAuthToken.getAccessToken();
}

private List<String> getScopes(){
    List<String> scopes = new ArrayList<>();
    scopes.add(OAuth.Scope_SIGNATURE);
    return scopes;
}

}

in this line:

EnvelopesInformation results = envelopesApi.listStatusChanges(this.docuSignProperties.getUserId(), options);

I'm receiving this error: "errorCode": "PARTNER_AUTHENTICATION_FAILED", "message": "The specified Integrator Key was not found or is disabled. Invalid account specified for user."

Someone knows what is the problem?

Upvotes: 0

Views: 241

Answers (2)

oitathi
oitathi

Reputation: 175

I forgot to use these lines:

    com.docusign.esign.client.auth.OAuth.UserInfo userInfo = apiClient.getUserInfo(oAuthToken.getAccessToken());
    apiClient.setBasePath(userInfo.getAccounts().get(0).getBaseUri() + this.docuSignProperties.getBasePath());
    Configuration.setDefaultApiClient(apiClient);
    String accountId = userInfo.getAccounts().get(0).getAccountId();

Upvotes: 1

theincrediblethor
theincrediblethor

Reputation: 448

As per https://developers.docusign.com/esign-rest-api/code-examples/config-and-auth, have you created an integration key (step 4)?

Upvotes: 0

Related Questions