Routing error with REST API in Clickatell - json

I am trying to send a SMS using REST API in clickatell.
I tested it using POSTMAN.
I sent the Headers as
POST /rest/message HTTP/1.1
Host: api.clickatell.com
Accept: application/json
Content-Type: application/json
X-Version: 1
Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxx
In body
{
"from": ["xxxxxxxxxx"],
"mo": "1",
"text": "Test Message ",
"to": ["xxxxxxxxx"]
}
I get a response as
{
"data": {
"message": [
{
"accepted": true,
"to": "xxxxxxxxxxxxx",
"apiMessageId": "xxxxxxxxxxxxxxxxxxxxxxxxx"
}
]
}
}
But when I check in clickatell account it shows the message is not sent and there is a ROUTING ERROR.
I am getting this error only while using REST API. Using HTTP is works fine.
Can someone help?

You're using MO set to 1, so that means that you are attempting to send from a two-way number. Make sure your two-way number is linked to the REST API integration.

Related

Discord - Webhook using JSON 400 bad request "embeds" "0"

I've trying to learn JSON along with using web hooks. I'm trying to use postman to test my code but I'm getting an error. Anyone have any ideas?
POST /api/webhooks/XXXXXXXXXXXXXXX HTTP/1.1
Host: discord.com
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: dbb93a2b-fced-8bd6-df89-XXXXXXXXXXX
{
"embeds":
[{
"ticker": "{{ticker}}",
"exchange": "{{exchange}}",
"interval": "{{interval}}",
"date": "{{date}}",
"timenow": "{{timenow}}"
}]
}
error message
{
"embeds": [
"0"
]
}
Discord docs for JSON
https://discord.com/developers/docs/resources/channel#create-message

Trying to send access token from loopback to third party api

I have my API in loopback 3.x. First I created an empty project and right after that I ran npm install loopback-connector-rest --save and lb datasource in the console to have a link to an external API called Userlike. It this URL https://www.userlike.com/api/external/message/chat_meta/.
Then I created a model with no parameters called Messages.
I had no problems executing as I used node . and there was no error, and in localhost:3000 I could visualize my API.
But I had a problem when I clicked GET in the page a 401 error because to access the API in Userlike I needed to send my token so I could get the data, so I modified the datasources.json file and I had this:
{
"userlikeRESTdatasource": {
"name": "userlikeRESTdatasource",
"baseURL": "https://www.userlike.com/api/external/message/chat_meta/",
"crud": false,
"connector": "rest",
"operations": [
{
"functions": {
"getMessages": []
},
"template": {
"method": "GET",
"url": "https://www.userlike.com/api/external/message/chat_meta/",
"headers": {
"accepts": "application/json",
"content-type": "application/json",
"authorization": "8c149a3d-4acf-362e-880c-30ec2f5ecaf"
},
"responsePath": "$.results.*"
}
}
]
}
}
The authorization field I put in the header didn't work as I still received
{
"error": {
"statusCode": 401,
"name": "Error",
"message": "Authorization Required",
"stack": "Error: Authorization Required\n
}
}
My idea was to do something like:
headers.append('Authorization', '8c149a3d-4acf-362e-880c-30ec2f5ecaf7');
headers.append('Access-Control-Allow-Origin', '*');
headers.append('Access-Control-Allow-Methods', 'POST, GET, OPTIONS');
headers.append('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Authorization, Accept');
But with loopback. So I could receive the data from the Userlike API and next I could modify or just use the data I wanted.
But I still can't figure out how can I modify my datasources.json or if I need to create something in another file to make it possible to send the token as the authorization to that URL I'm using.
Pass access token with HTTP header by using this
headers.append('X-Access-Token', '8c149a3d-4acf-362e-880c-30ec2f5ecaf7');
or also pass this token as a parameter.
?access_token=8c149a3d-4acf-362e-880c-30ec2f5ecaf7
This will help.

Loopback: Send request with json data using REST connector

I would like to fetch data from 3rd party REST Service in my Loopback Application. In order to fetch data from Service I need to authenticate first with login and password. I can test service using curl:
curl -b cookies -c cookies -X POST -d '{"auth": {"username":"MyUser","password":"Secret"}}' 'http://api.awesome.service.com/'
That works great. Tcpdump shows request like that:
Host: http://api.awesome.service.com/
User-Agent: curl/7.47.0
Accept: */*
Cookie: HBFAPI_SESSID=hbapi%3A197887%3A58a3028d12c36%3Anym2
Content-Length: 58
Content-Type: application/x-www-form-urlencoded
{"auth":{"username":"MyUser","password":"Secret"}}
So, I've created datasource first:
{
"awesome_datasource": {
"name": "awesome_datasource",
"baseURL": "https://api.awesome.service.com/",
"crud": false,
"connector": "rest",
"operations": [{
"template": {
"method": "POST",
"url": "http://api.awesome.service.com/auth",
"form":{
"auth": {
"username": "{username:string}",
"password": "{password:string}"
}
},
"json": true
},
"functions":{
"login": ["username", "password"]
}
}]
}
}
I tested that using explorer. No matter what I do, I can't get data in request body formatted as json. With or without json option result is this same, which in tcpdump is:
host: api.awesome.service.com
content-type: application/x-www-form-urlencoded
accept: application/json
content-length: 66
Connection: close
auth%5Busername%5D=MyUser&auth%5Bpassword%5D=Secret
I've tried pass parameters as 'query', 'form' or 'data' option. Also checked various header content-type options, but no luck so far.
Model is simple without parameters. Base model is 'Model' (no User, because I want to keep it simple as possible)
I was able to find this thread, but it wasn't much help:
https://github.com/strongloop/loopback-connector-rest/pull/12
Any advice will be much appreciated.
Well all you have to do is to use json instead of form there:
{
"awesome_datasource": {
"name": "awesome_datasource",
"baseURL": "https://api.awesome.service.com/",
"crud": false,
"connector": "rest",
"operations": [{
"template": {
"method": "POST",
"url": "http://api.awesome.service.com/auth",
"json": {
"auth": {
"username": "{username:string}",
"password": "{password:string}"
}
}
},
"functions":{
"login": ["username", "password"]
}
}]
}
}
REST connector tries to mimic request module as much as possible. Basically body, json, form and query(qs in request) do the same thing as the request options but they also accept template strings. Here's the documentation from request with a little modification:
query(qs in request) - object containing querystring values to be appended to the uri
body - entity body for PATCH, POST and PUT requests. Must be a Buffer, String or ReadStream. If json is true, then body must be a JSON-serializable object.
form - when passed an object or a querystring, this sets body to a querystring representation of value, and adds Content-type: application/x-www-form-urlencoded header. When passed no options, a FormData instance is returned (and is piped to request). See "Forms" section above.
json - sets body to JSON representation of value and adds Content-type: application/json header. Additionally, parses the response body as JSON.

How to Add Labels to Confluence Page via REST

I've been hunting for the correct way to add labels to a confluence page via REST (tags, categories, or whatever they are calling them today)
the documentation simply says "add json to the body" and then shows this example
[{"prefix":"global","name":"label1"},{"prefix":"global","name":"label2"}]
Has anyone successfully done this
You need to POST the JSON body using this endpoint: POST /rest/api/content/{id}/label where the id is the id for the content (page).
Reference: https://docs.atlassian.com/confluence/REST/latest/#content/{id}/label-addLabels
For example:
POST /rest/api/content/{id}/label HTTP/1.1
Host: yourinstance.atlassian.net
Authorization: Basic YaRtsWdg4VzdAzazhib2FyZA==
Content-Type: application/json
Cache-Control: no-cache
[
{
"prefix": "global",
"name": "label1"
},
{
"prefix": "global",
"name": "label2"
}
]

api access token post request, where to start

I've been struggling learning Auth for several months now, it comes down to I don't know where to start, it seems there are a bunch of different methods.
I am using an API that provides a token called "Personal Access Token".
Does this mean it's a Bearer or Web Token? I'm lost with this terminology.
They allow you to play with their API in their online tools. I am making a POST request.
The api provides this info:
Link to send Post Request: www.hackerrank.com/restoflink
Request Headers:
{
"Content-Type": "application/json",
"Accept": "application/json",
"Content-Length": 190
}
Request Body:
{
"username": "testing",
"subject": "test",
"message": "test",
"send_email": "true",
"force": "false",
"hide_login_credentials": "true",
"access_token": "Access Token Number"
}
Here is my code:
function onFormSubmission(e){
var accessToken ="ACCESS_TOKEN";
var options = {
method: "post",
headers: {
"Accept": "application/json",
"Authorization": "Bearer " + accessToken
},
payload: {
"username": "testing#gmail.com",
"subject": "test",
"message": "test",
"send_email": "true",
"force": "false",
"hide_login_credentials": "true",
"access_token": "ACCESS TOKEN",
"muteHttpExceptions": "false",
"contentType": "application/json"
}
}
var response = UrlFetchApp.fetch("linkhere", options);
Logger.log(response.getResponseCode())
Logger.log(response.getContentText());
}
When I run this code without the bearer token in the header, I get a "404 truncated server error, "Invalid Access Token"".
This is why I include the token in the in header ("I'm guessing it is a Bearer Token)
The response I get from the request is 200 but it doesn't perform the action I expect it to.
I'm confused on what adjustment I have to make, even though I'm getting at 200 response code, something isn't working with my request from Apps Script.
I tried making the request from POSTMAN and the api's test tools and all my attempts worked, which makes me believe I am doing something wrong in my script.
Any help would be greatly appreciated, this post already helped out a lot!
Here was my error:
UrlFetchApp.fetch("www.hackerrank.com/x/api/v2/tests?duration=-1&access_token=123", options)
URL: ""
I had to add 'https://', for a while I used 'http' and that didn't work.
They call it a permanent OAuth token in their documentation (linked from your comments), but the way they use it is very simple and not like the OAuth implementations I've worked with in the past.
You don't need to include the access token in your headers, simply append &access_token=[your token] to the URL ("linkhere") of your request.
Example:
UrlFetchApp.fetch("www.hackerrank.com/x/api/v2/tests?duration=-1&access_token=123", options)