How to Add Labels to Confluence Page via REST - json

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"
}
]

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

Routing error with REST API in Clickatell

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.

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.

Adding product via google shopping json API 400 must specify product

I'm having trouble getting a product insertion request working with google shopping API (https://developers.google.com/shopping-content/v2/reference/v2/products/insert). I'm sending an authenticated post request to https://www.googleapis.com/content/v2/shop_id/products?dryRun=true but only getting status: 400 with error message:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "[product] INSERT request must specify product"
}
],
"code": 400,
"message": "[product] INSERT request must specify product"
}
}
My request looks like this (shortened for brevity and ssl encrypted)
POST /content/v2/<removed>/products?dryRun=true HTTP/1.1
Host: www.googleapis.com
Content-Length: 2102
accept-encoding: gzip, deflate
authorization: Bearer <removed>
user-agent: Python-httplib2/0.9.1 (gzip)
{
"offerId": 4572,
"gtin": "4048669296057",
"googleProductCategory": "Apparel & Accessories > Clothing",
"targetCountry": "se",
"title": "Puma Sweat Pants",
"onlineOnly": true,
"price": {
"currency": "SEK",
"value": "1337"
},
"channel": "online",
"contentLanguage": "sv",
"brand": "Puma",
"link": "http://example.com/produkt/puma-sweat-pants"
}
I know the request is correctly authenticated as I can remove the authentication and get a different message.
Googles Common errors page (https://developers.google.com/shopping-content/v2/how-tos/common-errors) suggests that this is a batch job, but that would be the url https://www.googleapis.com/content/v2/products/batch
I found the reason for my troubles: I was not sending the Content-Type: application/json header.

Docusign rest api composite template error

I've made composite templates and had them working before, but I'm suddenly getting an error and have no idea why this is causing an issue. Here's my request:
POST https://demo.docusign.net/restapi/v2/accounts/356019/envelopes HTTP/1.1
Host: demo.docusign.net
X-DocuSign-Authentication: <DocuSignCredentials><Username>test#gmail.com</Username><Password>*****</Password><IntegratorKey>****</IntegratorKey></DocuSignCredentials>
Content-Type: multipart/form-data; boundary=MY_BOUNDARY
Accept: application/json
Content-Length: 807319
Expect: 100-continue
Connection: Keep-Alive
--MY_BOUNDARY
Content-Type: application/json
Content-Disposition: form-data
{
"emailSubject": "Please Docusign this",
"emailBlurb": "This is a test... Also sign this form",
"enableWetSign": "true",
"status": "sent",
"compositeTemplates": [
{
"inlineTemplates": [
{
"sequence": "1",
"recipients": {
"signers": [
{
"email": "test#gmail.com",
"name": "test",
"recipientId": "1"
}
]
}
}],
"document":
{
"documentId": "1",
"name": "test0",
"fileExtension": "pdf"
}
}
]
}
--MY_BOUNDARY
Content-Type: application/pdf
Content-Disposition: file; filename="test0.pdf"; documentid="1"
<pdf bytes here>
--MY_BOUNDARY--
I have this working with server templates, but it seems like anything that requires the document object gives me a bad request. The request I'm getting is:
Request Error: BadRequestDocuSign Error: {
"errorCode": "UNSPECIFIED_ERROR",
"message": "the document is corrupt, rebuilding failed"
}
I've read the pdf bytes in another program and have successfully created a pdf from it, so I'm not sure what could be causing this issue. Does anybody know what the problem may be? Thank you for your time.