api v2 - POSTMAN examples

I am sorry for not posting these POSTMAN examples sooner. You can download the attached file and import them into your Postman. 

There are over 30 examples of different ways to hit the API. and this is for those users who are not using cURL. 

 

These range from Exports, Imports, uploading data, and reviewing dump files.  

I hope these are beneficial.

 

NOTE: you may have to update the file extension from .txt to .json. Anaplan community does not all .josn

Answers

  • Thanks Jason for both V1 and V2 examples.

    Very, very helpful.

     

     

  • I'm curious about this one:

     

    "https://api.anaplan.com/2/0/workspaces"

     

    I tried it recently and confirm it with R&D: this endpoint doesn't exist in 2.0

    Did you manage to make it work or is it a mistake ? 

  • I actually had a conversation with my rep today. the endpoint Workspace does return a result, however what I was told is that the result may not reliable. 

    Also the endpoint of models that works in version 1/3 does not work at all in version 2. 

     

    it was nice to be able to see all those values without have to open up the model.  Not sure why it is not current available. 

  • Hello Jason,

     

    I'm just starting with certificates, and am a bit struggling there.

    I already collected my certificate from my CA and imported it in Anaplan Administration.

     

    So I have the following files:

    - userAnaplan.cnf: the config file that helped me generate my private Key file and my CSR

    - userAnaplan.csr: the CSR generated from the CNF file

    - userAnaplan.key: the private key file generated from the CNF file

    - userAnaplan.p7b: the certificate issued by my CA based on the CSR

    - userAnaplan.pem: the certificate extracted from the P7B file

     

    And now I want to do a first login to Anaplan API, using the auth.anaplan.com/token/authenticate URI.

    I already managed to get a token using a username and password, but struggle with the certificate.

     

    I downloaded your Postman sample, but could you detail a little more please how do you generate the data for the different fields:

    {{ca cert value}}

    encodedData

    encodedSignedData

    Which command lines or tools do you use to generate the base64 versions of the data using the files above?

     

    Thanks a lot,

    FX

  • Hi FX,

    Check my comment here for how to get the encoded data and signed data headers
    https://community.anaplan.com/t5/Anaplan-Platform/Using-CA-Certificate-to-execute-Anaplan-REST-API-2-0-from-VB-Net/m-p/82314/highlight/true#M17928
    Francis has posted the solution in C# in the same post

    You can also achieve the same result in Python by following this
    https://community.anaplan.com/t5/Best-Practices/Anaplan-API-2-0-Python-Library/ta-p/38139
    Although this does not work on Windows...

    Let me know if you need more help

    Regards,
    Anirudh
  •  I also have a Java solution as well. 

  • Hello,

     

    Based on your code samples, I tried to create a Postman pre-request script that allows me to generate the authentication header.

    However, Anaplan keeps sending me back a 401 (FAILURE_BAD_CREDENTIAL).

     

    Here is my request:

     

    POST /token/authenticate HTTP/1.1
    Host: auth.anaplan.com
    Authorization: CACertificate {{anaplan_certificate}}
    Content-Type: application/json
    
    {
        "encodedData": {{anaplan_encodedString}},
        "encodedSignedData": {{anaplan_signedString}}
    }

     

    And here is my pre-request script:

     

    function randomString(length, chars) {
        var result = '';
        for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
        return result;
    }
    
    var randomString = randomString(150, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
    var signedString = CryptoJS.HmacSHA512(randomString, pm.environment.get("anaplan_secretkey"));
    
    pm.environment.set("anaplan_encodedString", btoa(randomString));
    pm.environment.set("anaplan_signedString", btoa(signedString));

     

     

    The Postman environment variable "anaplan_certificate" contains the content of my certificate file, without "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----" and where I removed all CR and LF characters. It's basically just a very long string looking like "MIIFHzCCBAegAwIBA.............EWmQjqsbcj2zY09pew==".

    The Postman environment variable "anaplan_secretkey" contains the content of my certificate file, without "-----BEGIN PRIVATE KEY-----" and "-----END PRIVATE KEY-----" and where I removed all CR and LF characters. It's basically just a very long string looking like "MIIEvQIBADANBgk.............RtgkrHJ+SKp/EFH2PhBx1xjE=".

     

    The certificate is correctly imported on my Anaplan administration console too.

    2020-09-22 11_32_24 - Base.png

     

     

     

    Any idea on what I am doing wrong?

     

    Thanks for your help,

    FX

  • Hello @Jason_C  and @anirudh 

    By any chance do you have any clue on what I should do so the Postman script to login with certificate that I posted just before would work?

    I suspect CryptoJS.HmacSHA512 to give me a wrong value, but I'm really not sure.

    Thanks a lot,

    FX

  • Hello FX,

     

    Can you confirm that the value you have for "anaplan_certificate"

    Authorization: CACertificate {{anaplan_certificate}}

    is something like :

    "MIIFHzCCBAegAwIBA.............EWmQjqsbcj2zY09pew=="

    ?

    If so, then you need to correct that by getting the string value of the base64 version of that string.

    Usually you should have a string value starting with "LS0..."

     

  • Hello @christophe_keom 

     

    Thanks for the hint. I juste tested your suggestion..

     

    1. Changed my authorization header to be the following:

     

    Authorization:CACertificate {{anaplan_certificate_base64}}

     

     2. Added a line to the Pre-Req script:

     

    pm.environment.set("anaplan_certificate_base64", btoa(pm.environment.get("anaplan_certificate")));

     

     

    This transforms correctly my certificate value "MIIFHzCCBAegAwIBA.............EWmQjqsbcj2zY09pew==" to "TUlJRkh6Q0NCQWVnQ........21RanFzYmNqMnpZMDlwZXc9PQ==" which corresponds to the Base64 text value of the certificate.

     

    But still, the test gives me 401 reply, with a "FAILURE_BAD_CREDENTIAL" message. 😞

    Any other idea?

     

    Thanks,

    FX

  • FX,

     

    Seeing the outcome of what you get makes me think that it might be a simple issue.

    Can you ensure that you keep those titles:

    "-----BEGIN CERTIFICATE-----"

    "-----END CERTIFICATE-----"

    when you try to generate that

    anaplan_certificate_base64

    value

    ?

    After reading your previous post, I guess this is what happened.

    You should have a value starting with "LS0.."

     

    Rgds,

     

    Christophe K.

  • When I test via Postman I absolutely use the certificate. That is the only way, if you are looking at data loaded into a file on Anaplan can truly confirm you are looking at the right data.

    You can use a tool called openssl (https://www.openssl.org) to help convert your certificates.  

    Example: enc -base64 -in "C:\OpenSSL-Win64\bin\anaplan_api_v2_1.0.0\random_strg_100.txt" -out "C:\OpenSSL- Win64\bin\anaplan_api_v2_1.0.0\random_strg_100.txt.base64"

     

    OR 

     

    Per instructions from the Anaplan support team:

    1. Use a Base-64 encoder (e.g. https://www.base64encode.org/ ) to encrypt the CN and PEM string, separated by a colon. For example, paste this in:
      [email protected]:-----BEGIN CERTIFICATE-----
      CERTCONTENTS
      -----END CERTIFICATE-----
  • Hello,

     

    I am trying to do the same with postman but not working (i have Error 400 Bad Request Result)

    I am using java to sign and encode data like i found in the following link (https://anaplanauthentication.docs.apiary.io/#reference/authentication-token)

     

    In postman Header, i have added : 

     

    Content-Type : application / json
    
    Autorization : CACertificate LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS[..................]kQgQ0VSVElGSUNBVEUtLS0tLQ

     

    In Body part :

     

     

    { 
    'encodedData': 'VOOBp3PvmX+DQL[..........................]Dn6zKU+x1MJQ==',
    'encodedSignedData': 'p1pnJ4/O8YcizY++b2OmZNfF70PWjvm0vPR6y+PoqrKhfPVi8f6YcTi66QTdV9dR+X7S69ooWqgG894PLny[............................]xPCtmNV7gIdfvk4W4rL04KKvNvqfV+pvLTtC7gBWE0Rg=='
    }

     

     

    (EncodedData is random string from 100char encoded to base64 => 136char

    EncodedSignedData is random string signed with the private key and encoded to base64 => 344char)

     

    Do i need to put simple quote in the Json ? In the Header for the CACertificate ?

    I think this is just a little thing but i am not able to found it.

     

    Thank you and best regards,

  • Hi @Jason_C and/or @christophe_keom 

    I'm sorry I don't get it. I really think I am not very far, but it still continues to fail. 😟

    I now have a header looking like this: "Authorization: CACertificate LS0.....", so it seems OK.
    But still a 401 FAILURE_BAD_CREDENTIAL.

    The full code I have in the pre-req script is the following:

     

    function randomString(length, chars) {
        var result = '';
        for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
        return result;
    }
    
    var anaplan_privatekey = "-----BEGIN PRIVATE KEY-----\
    MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDg/EygC4681MTB\
    MToJXByMoFHhyPZNSTLtl7xRLjVNJ7N31JQLtf8Anv5e1hRcjDy4mQcPgxvhWvVa\
    .....
    Vcfg8G3Jbel2sz6HGjR9SohMFx038K5C2F43L5hRW0MF4dxwGYeWs3Ic0Z7CC9IR\
    tgkrHJ+SKp/EFH2PhBx1xjE=\
    -----END PRIVATE KEY-----"
    
    var anaplan_certificate = "-----BEGIN CERTIFICATE-----\
    MIIFHzCCBAegAwIBAgIQBghdO0SjwpaGWIjw5OftnTANBgkqhkiG9w0BAQ0FADBl\
    MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\
    ...
    TxAKO5P+pU1Hc8vVW2jtMY4ajNn4C2L6vUfQ0rfMW3jSrBWXlG3GJWYiYJ1BkNxJ\
    tDCDJO1yEWmQjqsbcj2zY09pew==\
    -----END CERTIFICATE-----"
    
    var privatekey = anaplan_privatekey.replace(/(?:\r\n|\r|\n)/g, "").replace("-----BEGIN PRIVATE KEY-----", "").replace("-----END PRIVATE KEY-----", "")
    
    var randomString = randomString(150, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
    var signedString = CryptoJS.HmacSHA512(randomString, privatekey);
    
    // var certificate = anaplan_certificate.replace(/(?:\r\n|\r|\n)/g, "").replace("-----BEGIN CERTIFICATE-----", "").replace("-----END CERTIFICATE-----", "")
    var certificate = anaplan_certificate;
    
    var randomStringBase64 =  btoa(randomString);
    var signedStringBase64 = btoa(signedString);
    var certificateBase64 = btoa(certificate);
    
    console.log("privatekey: " + privatekey);
    console.log("randomString: " + randomString);
    console.log("randomStringBase64: " + randomString);
    console.log("signedString: " + signedString);
    console.log("signedStringBase64: " + signedStringBase64);
    console.log("certificate: " + certificate);
    console.log("certificateBase64: " + certificateBase64);
    
    pm.environment.set("anaplan_encodedString", randomStringBase64);
    pm.environment.set("anaplan_signedString", signedStringBase64);
    pm.environment.set("anaplan_certificate_base64", certificateBase64);

     

    I feel like the CryptoJS.HmacSHA512() function is not behaving like Anaplan expects.

    For reference, the body of the request does not change:

    {
        "encodedData": {{anaplan_encodedString}},
        "encodedSignedData": {{anaplan_signedString}}
    }

    Any other ideas?

    Thanks a lot,
    FX

  • Hi @fxlepoutre did you manage to solve this issue? I seem to have the same problem.

  • Hi @matKa 

    Unfortunately not.

    From my understanding, Postman's javascript function "CryptoJS.HmacSHA512()" is not generating a signature as required by Anaplan of the random string.

    Our developers managed to do the integration in Java on their environment without the Postman example finally, but based on the Python and C# examples posted previously on the thread.

    If you manage to do the signature within the pre-req scripts of Postman, I'd be glad if you can share your code.

    Have a good day,