# Unable to register a custom request template

**URL:** <https://community.cumulocity.com/t/unable-to-register-a-custom-request-template/3117>\
**Category:** Forum\
**Tags:** cumulocity\
**Created:** [February 4, 2022, 6:47am UTC](https://community.cumulocity.com/t/unable-to-register-a-custom-request-template/3117 "2022-02-04T06:47:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasad.patil](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@prasad.patil](https://community.cumulocity.com/u/prasad.patil)\
**Post date:** [February 4, 2022, 6:47am UTC](https://community.cumulocity.com/t/unable-to-register-a-custom-request-template/3117/1 "2022-02-04T06:47:40Z")

</div>

#### What product/components do you use and which version/fix level?

Backend: **1011.0.12**  
UI: **1011.0.12**

#### Are you using a free trial or a product with a customer license?

#### What are trying to achieve? Please describe in detail.

- I need to register a custom template for sending some custom numerical values.

- For this I have referred the C++sdk. There’s an example by the name ‘ex-03-measurement’ which I referred. This example tells us about how we can send dummy CPU workload to a device on Cumulocity IoT. I have tried this example and its works fine.

- I referred the above mentioned example and a document named ‘Reference Guide’ topic SmartREST \> Registration Process. Using these 2 sources as reference I created a template as follows,

- I am trying to register the above custom template via Postman. But I get a response as follows,  
43,1,Template already existing

- What I know is there is no such template registered by me before and custom templates can be registered by using message-id starting from 100.

- Can anyone point out what I am missing ?

#### Do you get any error messages? Please provide a **full error** message screenshot and log file.

Please find the attached screenshot for the above scenario,

 ![Register_Template_1](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/a/c/acbdeeaf704bfe7414b555388b2a4a56baeea1c6.png)

---

<div class="post-metadata">

**Author:** ![Christian\_Guether1](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/christian_guether1/32/14848_2.png) [@Christian\_Guether1](https://community.cumulocity.com/u/Christian_Guether1)\
**Post date:** [February 4, 2022, 11:46am UTC](https://community.cumulocity.com/t/unable-to-register-a-custom-request-template/3117/2 "2022-02-04T11:46:26Z")

</div>

Hi Prasad,

can you also share the headers of your request. Each template, which you create, will be added to a SmartRest template collection. This collection is identified by the custom header X-Id. Might be that a template already exists for the current template collection, which has the same id you also provided for your request to create a new template.

You could also try to change the value for the X-Id header.

Best regards  
Christian

---

<div class="post-metadata">

**Author:** ![prasad.patil](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@prasad.patil](https://community.cumulocity.com/u/prasad.patil)\
**Post date:** [February 4, 2022, 12:47pm UTC](https://community.cumulocity.com/t/unable-to-register-a-custom-request-template/3117/3 "2022-02-04T12:47:17Z")

</div>

Hi Christian,

As you suggested I changed the X-Id to a random number ‘1234’ in the header and the registration worked. In response I received the following message: 20,765539.

Now I need to use this template to send the ‘My\_Cov’ numerical values from the example ‘ex-03-measurement’ which I referred from the C++ sdk.

There’s this function in the sdk where we assign the template id to the agent.send function,

```
virtual void operator()(SrTimer &timer, SrAgent &agent)
{
    const int cpu = rand() % 100;
  
   if(cpu%2 == 0)
    agent.send("103," + agent.ID() + "," + to_string(cpu));
   
}

```

In the above function tried sending 120 (my custom template’s id) instead of the 103 as seen in the example. But it is not working. I might be missing something here.

My requirement is very small.

- I want to use the ‘ex-03-measurement’ example from the C++ sdk.

- This example sends a CPU workload using a template Id 103.

- Instead of template Id103 I want to use my custom registered template Id 120 and see the custom measurement on a device registered on Cumuloicty IoT.

Can you please help me with this ?

---

<div class="post-metadata">

**Author:** ![prasad.patil](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@prasad.patil](https://community.cumulocity.com/u/prasad.patil)\
**Post date:** [February 7, 2022, 11:03am UTC](https://community.cumulocity.com/t/unable-to-register-a-custom-request-template/3117/4 "2022-02-07T11:03:40Z")

</div>

Hi Christian,

I am still not able to send a custom measurement by registering a custom template.  
I have provided a detailed explanation of what I am doing in the above comment  
Please suggest where I am going wrong.

---

<div class="post-metadata">

**Author:** ![Christian\_Guether1](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/christian_guether1/32/14848_2.png) [@Christian\_Guether1](https://community.cumulocity.com/u/Christian_Guether1)\
**Post date:** [February 7, 2022, 7:54pm UTC](https://community.cumulocity.com/t/unable-to-register-a-custom-request-template/3117/5 "2022-02-07T19:54:02Z")

</div>

Hi Prasad,

I’m not familiar with the C++ SDK. Did you follow the steps as described in the [guide](https://cumulocity.com/guides/device-sdk/cpp/#integrating-to-the-platform)? In particular, the section which describes how to manage to the X-Id header?

> It is important to mention that you must store the correct SmartREST _X-ID_ and device’s _Cumulocity IoT ID_ in the inherited member variables `xid` and `id` respectively. They will be used by `SrAgent` after the integrate process for initializing the corresponding internal variables.

Did you set the xid variable at some point in your code?

Best regards  
Christian

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/system/32/31990_2.png) [@system](https://community.cumulocity.com/u/system)\
**Post date:** [May 8, 2022, 7:54pm UTC](https://community.cumulocity.com/t/unable-to-register-a-custom-request-template/3117/6 "2022-05-08T19:54:09Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
