Passing token in header to Prophet 21 API

1.2k views Asked by At

This is the first time I am working with Prophet 21 by Epicor. I am having a hard time figuring out how to pass the token in the HTTP request header after I authenticate with a user account.

https://localhost:4443/api/security/token/?username={USERNAME}&password={PASSWORD}

Returns the token but I'm not sure what the request header should be set as. I have tried Token, AccessToken, and a bunch of other combination but I always receive this message:

<TokenError xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <Description>Token Validation Exception Occured</Description>
    <Error>invalid_request</Error>
    <Uri/>
</TokenError>

Here is an example of what I'm trying:

https://localhost:4443/api/inventory/v2/parts/

Header

Token = token eoWffZR0PlReRLwHopOTNSoBccwj96VSkjGYX2QnGdLjqY10mREmjwh4GDXqpf7HBBHrFImN3T4RtHEPjBK+VQ5EniquqnBbOAvlzf+5amV3rKDB67w5XbyoOzD2YSiFOULoRRY2Iaxe7pAy5JaWQ==

Token = eoWffZR0PlReRLwHopOTNSoBccwj96VSkjGYX2QnGdLjqY10mREmjwh4GDXqpf7HBBHrFImN3T4RtHEPjBK+VQ5EniquqnBbOAvlzf+5amV3rKDB67w5XbyoOzD2YSiFOULoRRY2Iaxe7pAy5JaWQ==

I won't include more examples but I have tried all kinds of combinations. I have also reviewed the SDK documentation which is pretty useless. For example here is the JavaScript code example but it is including functions that aren't in the documentation so I can't see how it is structuring the request.

<script type="text/javascript">
     var gToken;

     function getTokenUI(){
         var userName = $('#name').val();
         var passWord = $('#password').val();
         var jsonToken = getToken(userName, passWord)
         gToken = jsonToken.AccessToken
         $('#return ul').append('<li>' + gToken + '</li>');
     }   

     function getOppUI() {
         var oppID = $('#oppid').val();
         var xhr = ajaxRequest("GET", OppResourceURL(oppID), null, "json", gToken);
         $('#restreturn ul').append('<li>' + xhr.responseText + '</li>');

         var jsonObj = $.parseJSON(xhr.responseText);

         $.each(jsonObj, function(key, val) {
             $('body').append('<div>' + key + ": " + val + '</div>');
         });
     }
 </script>

I'm basically looking for some help with structuring the header so I can send over the token. I want to use the Laravel PHP framework to do this.

Thank you in advance for you time and assistance with this.

1

There are 1 answers

1
thestepafter On

So it turns out that this authentication is pretty standard, I was just thrown off by the Token reference in the documentation.

Setting Authorization = Bearer {token} works.