cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

How to pass application key in headers for Thingworx 8 version

PGayathri
6-Contributor

How to pass application key in headers for Thingworx 8 version

Hi,

can anyone please tell me how to pass application key in headers as parameters, can you post the sample headers.

I tried application key string in headers in many formats, but still I am facing the same issue(cors).

I tried below cases:

headers:{

appKey: <application key>,

ApplicationKey: <application key>,

Application Key: <application key>,

Application-Key: <application key>,

application-key: <application key>,

KEY:<application key>,

}

Thanks in advance .

8 REPLIES 8
posipova
20-Turquoise
(To:PGayathri)

Have you tried, for example:

"headers": {
    "accept": "application/json",
    "content-type": "application/json",
    "appkey": "your-app-key-here",
    "cache-control": "no-cache",
    "postman-token": "postman-token-here"
  },

PGayathri
6-Contributor
(To:posipova)

Hi Polina,

Actually I am consuming thingworx apis from react app.

I am passing the below headers while api calling. correct me if I am doing wrong.

const HEADERS = {

  'Content-Type': 'application/json',

  'Accept': 'application/json',

  'appkey': '73cd42e2-fa9b-4896-b7c4-39780aa0c6d7',

  'cache-control': 'no-cache'

};

do I need to pass postman token also, if yes can you please tell me how to get the postmantoken.

Thanks.

cbuse
13-Aquamarine
(To:PGayathri)

appkey needs to be spelled like this - appKey

const HEADERS = {

  'Content-Type': 'application/json',

  'Accept': 'application/json',

  'appKey': '73cd42e2-fa9b-4896-b7c4-39780aa0c6d7',

  'cache-control': 'no-cache'

};

PGayathri
6-Contributor
(To:cbuse)

Hi Cristina,

I have supplied the appKey same as mentioned in above code, but still getting 404 unauthorized.

I am sending headers as follows:

let default_headers = {

      'Content-Type': 'application/json',

      Accept: 'application/json',

      appKey: <<Thingworx_ApplicationKey>>,

      'cache-control': 'no-cache'

    };

Please help me.

The formats provided by others works for me. You do not need the Postman-Token.

Are you sure the appKey you are using has access to the entity you are targeting?

PGayathri
6-Contributor
(To:wreading)

yes Wes Reading, appKey has access to thingworx.  I am able to access thingworx apis when sending application key as url parameter.

application key has user reference Administrator. I assigned project and model tag to application key. Is it okay to assign project and model tag to application key.

That's strange. I had the opposite problem where I couldn't make it work in the header... Maybe try to do it from a command line if you have access to Linux or if you install the windows curl command. This may help in eliminating some questions. The Windows command will be something like this:

GET https://<host><:port>/Thingworx/Resources/EntityServices/ServiceDefinitions -H "Cache-Control: no-cache" -H "appKey: 73cd42e2-fa9b-4896-b7c4-39780aa0c6d7"

Note that depending on your environment you may need one or both of the following options:

-k  : Accept self signed certs

-N --noproxy <host> : Do not go through the proxy if one is configured

From Linux, like this:

curl -X GET \

  https://<host><:port>/Thingworx/Resources/EntityServices/ServiceDefinitions \

  -H 'Cache-Control: no-cache' \

  -H 'appKey: 73cd42e2-fa9b-4896-b7c4-39780aa0c6d7'

Hope that helps gives some clues.

Wes

Announcements


Top Tags